Skip to content

feat: Keep the DevTools component tree and selection up to date - #4222

Merged
spydon merged 5 commits into
flame-engine:mainfrom
BilalWalker:devtools-live-updates
Nov 23, 2026
Merged

spydon merged 5 commits into
flame-engine:mainfrom
BilalWalker:devtools-live-updates

Conversation

@BilalWalker

@BilalWalker BilalWalker commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Description

Keeps the component tree and the selected component in the flame_devtools extension up to date while the game runs, as described in #4173. Before, they only updated through the manual refresh button.

  • The selected component is polled every 100 ms and the tree every second, while the extension is connected. A new Poller never starts a poll while the previous one is still running.
  • A "Live" switch in the header of the component tree turns the updates off. The refresh button still refreshes the tree once.
  • The tree is updated in place instead of being rebuilt: nodes of components that are still in the game are kept, with their expansion state, and only their data is replaced. Before, any change in the structure of the tree collapsed every node. The selected component section listens to the data of its node, so its toString updates too, and the selection is cleared when its component is removed.
  • IncrementalNumberFormField no longer overwrites a value that is being edited. A focused field keeps its text and shows the latest value when it loses focus. Submitting or tapping outside of the field removes the focus.
  • doc/flame/other/debug.md describes the live updates.

Cost of polling, measured on a debug web build of a game with 1000 rotating boxes (about 2000 components):

Call Median
getPaused (trivial call, for the round-trip overhead) 97 ms
getPositionComponentAttributes 98 ms
getComponentTree (659 KB) 216 ms

So building the tree costs about 120 ms on that scene, and polling a single component costs about the same as the round trip. Open question: with a 1 s interval, that is roughly 12% of the game's time on a big scene in debug mode. Happy to change the interval, or make it slower on big trees, if you prefer.

Testing:

  • Unit tests for Poller (one poll per interval, no overlapping polls, inactive, failed polls, stopping) and for the in-place tree sync (kept nodes and their expansion, updated data, removed and added components).
  • Widget tests for the focus behavior of IncrementalNumberFormField. The angle field tests now remove the focus before reading a value back from the game.
  • Tried by hand in the simulated DevTools environment against a running game: values changed in the game showed up in the form without a refresh, expanded nodes, the selection and the scroll position survived the refreshes, and the Live switch stopped and restarted the updates.
  • Not tried by hand: removing the selected component while the game runs.

Screenshot and recording:

devtools-live-updates
flame-devtools-live-updates.webm

Checklist

  • I have followed the Contributor Guide when preparing my PR.
  • I have updated/added tests for ALL new/updated/fixed functionality.
  • I have updated/added relevant documentation in docs and added dartdoc comments with ///.
  • [-] I have updated/added relevant examples in examples or docs.

Breaking Change?

  • Yes, this PR is a breaking change.
  • No, this PR is not a breaking change.

Related Issues

Closes #4173

IncrementalNumberFormField replaced its text whenever a new value came
in. That is fine while values only arrive on a manual refresh, but once
the selected component is polled, a poll would overwrite what the user
is typing.

A focused field now keeps its text when a new value arrives, and shows
the latest value when it loses focus. If no new value arrived while it
was focused, the typed value is kept. Submitting the field or tapping
outside of it removes the focus.

The angle field tests now remove the focus before the value is read
back from the game, since a focused field ignores it.

Tested with new widget tests for IncrementalNumberFormField; all
flame_devtools tests pass.
The component tree and the selected component in the DevTools extension
only updated through the manual refresh button, so their values went
stale as soon as the game moved on (flame-engine#4173).

The extension now polls the game while it is connected: the selected
component every 100 ms, and the tree every second, since the game
builds the whole tree with the toString and attributes of every
component on each call. A Poller never starts a poll while the previous
one is still running. A "Live" switch in the tree header turns polling
off; the refresh button still works.

The tree used to be rebuilt from scratch when its structure changed,
which collapsed every node. It is now updated in place: nodes of
components that are still in the game are kept with their expansion
state, and only their data is replaced. The selected component section
listens to the data of its node, so its toString updates too. The
selection is cleared when its component is removed.

Measured with a debug web build of a game with 1000 rotating boxes
(about 2000 components): getComponentTree took 216 ms (659 KB), while a
trivial service call took 97 ms, so building the tree costs about
120 ms, and a single component's attributes cost about the same as the
trivial call.

Tested with unit tests for Poller and the in-place tree sync, and by
hand against a running game: values change in the form without a
refresh, expanded nodes, selection and scroll position survive, and
the Live switch stops and restarts the updates.
Resolves the conflicts with flame-engine#4227, which moved flame_devtools from
package:flutter/material.dart to the package:flame_devtools/material.dart
re-export. The new files and tests of this branch use the re-export
too, and the tree sync test uses the new named isPositionComponent
parameter of ComponentTreeNode.

All flame_devtools tests pass and analyze is clean.
@BilalWalker

Copy link
Copy Markdown
Contributor Author

Merged the latest main after #4227 (conflicts resolved, tests green). @erickzanardo whenever you have a moment, happy to adjust the poll interval or anything else.

@spydon

spydon commented Nov 18, 2026

Copy link
Copy Markdown
Member

Can you add a screenshot/video of the result?

@BilalWalker

Copy link
Copy Markdown
Contributor Author

Can you add a screenshot/video of the result?

Here’s a recording: the game on the left, DevTools on the right. It shows the values following the game, collapsed nodes staying collapsed, and the Live switch stopping and resuming the updates.

flame-devtools-live-updates.webm

refreshComponentTree was a static method that took the previous model,
updated its tree in place and then returned a copy of it with the new
component count. Since the model is mutated anyway, pretending that it
is immutable only made it harder to follow, as pointed out in review.

ComponentTreeModel is now a plain mutable class with a refresh method
that updates the tree and the component count. The provider holds that
single model, and the loader returns the component count, which the
tree header shows.

All flame_devtools tests pass and analyze is clean.

@spydon spydon left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's quite a dirty solution, but I guess it buys some performance to not have the state immutable.

@spydon
spydon enabled auto-merge (squash) November 23, 2026 14:56
@spydon
spydon merged commit 73245d7 into flame-engine:main Nov 23, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add live updates for the component tree and selected component in DevTools

3 participants