refactor!: Make descendants return an eagerly collected snapshot list - #4009
Open
spydon wants to merge 1 commit into
Open
refactor!: Make descendants return an eagerly collected snapshot list#4009spydon wants to merge 1 commit into
spydon wants to merge 1 commit into
Conversation
luanpotter
reviewed
Aug 16, 2026
| void _remove(Component parent) { | ||
| parent._internalChildren.remove(this); | ||
| for (final component in _collectDescendants()) { | ||
| for (final component in _collectDescendants(reversed: true)) { |
Member
There was a problem hiding this comment.
why not use the public descendants here?
luanpotter
reviewed
Aug 16, 2026
| ); | ||
|
|
||
| testWithFlameGame('descendants() iterator is lazy', (game) async { | ||
| testWithFlameGame('descendants() supports early stopping', (game) async { |
Member
There was a problem hiding this comment.
this is no longer a feature of descendants but rather just how dart streams work, this test is misleading as the list is now eagerly collected (arguably it was wrong to begin with bc even before it was not testing what it was intending to)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
descendants()was a lazysync*generator, which allocates an iterator per tree level and pays a delegation chain walk per element. After #3981 it was the last generator-shaped traversal of the component tree; this PR makes it delegate to the same_collectDescendantscollection pass, so there is only one traversal shape left to care about.The method now returns a
List<Component>that is an eagerly collected snapshot of the tree at the moment of the call. This means the whole subtree is always traversed (early stopping no longer saves traversal work), and iterating while adding or removing components is safe instead of surfacing aConcurrentModificationError.Checklist
docsand added dartdoc comments with///.examplesordocs.Breaking Change?
Migration instructions
Most call sites need no changes, since
ListimplementsIterable. Overrides ofdescendantsmust update their return type fromIterable<Component>toList<Component>. Code that relied on the lazy iteration semantics (early stopping to avoid traversing large trees, or catchingConcurrentModificationErroron mutation during iteration) now gets a full-tree snapshot instead; query methods such asfirstWherestill stop early, they just iterate an already collected list.Related Issues
Relates to #3957