Repository navigation
Do not send traversal child semantics nodes to engine when traversal parent is missing - #193372
Conversation
There was a problem hiding this comment.
Code Review
This pull request updates SemanticsNode and SemanticsOwner to skip orphan traversal children during hit testing and semantics updates when their traversal parent is detached or hidden. It also adds tests to verify that these nodes are not serialized during route transitions or opacity changes. The review feedback suggests a performance optimization in _shouldSkipInHitTest to use the private field _traversalChildIdentifier directly instead of calling the expensive getSemanticsData() method.
| final SemanticsNode? traversalParent = | ||
| owner!._traversalParentNodes[getSemanticsData().traversalChildIdentifier]; |
There was a problem hiding this comment.
Calling getSemanticsData() is expensive because it allocates and compiles a new SemanticsData object on every call. Since _traversalChildIdentifier is already stored as a private field on SemanticsNode and kept up-to-date, we can directly use it here to avoid unnecessary allocations and improve performance during semantics updates.
final SemanticsNode? traversalParent =
owner!._traversalParentNodes[_traversalChildIdentifier];4013f50 to
c0c4d54
Compare
QuncCccccc
left a comment
There was a problem hiding this comment.
LGTM. Thank you! Sorry for the late response.
| if (!visitedNodes.contains(childNode)) { | ||
| childNode._markDirty(); | ||
| } | ||
| if (!hadSameTraversalParent) { |
There was a problem hiding this comment.
One case that still doesn't work is nested portals (but we can fix it in a separate PR): an OverlayPortal inside another portal's overlay child (like cascading menus), when the outer anchor is hidden and shown again. With the outer anchor under Opacity 1 → 0 → 1:
- Frame 2 (hidden): only the root is sent, so both overlay children and their descendants drop out of the engine's tree.
- Frame 3 (shown again): the inner overlay child is re-sent and still lists its child in childrenInTraversalOrder, but that child is never re-sent.
If I read the code right, the inner anchor isn't dirty in the frame where it gets skipped, so it stays in _traversalParentNodes (L5216-5218 only removes skipped traversal parents that are dirty). When it's shown again, hadSameTraversalParent is true, so only the inner overlay child itself is marked dirty, not its descendants.
There was a problem hiding this comment.
Thanks! I will send out a separate PR for this case
|
autosubmit label was removed for flutter/flutter/193372, because The base commit of the PR is older than 7 days and can not be merged. Please merge the latest changes from the main into this branch and resubmit the PR. |
…parent is missing (flutter#193372) fix flutter#190357 When an `OverlayPortal` (such as the one inside a Material `Slider`) is inside a pushed route, the route's entrance transition (e.g., `FadeTransition`) starts at opacity `0.0` on the initial frame. `RenderAnimatedOpacityMixin.visitChildrenForSemantics` skips visiting the `OverlayPortal` anchor (`traversalParentIdentifier`), while `_RenderTheater.visitChildrenForSemantics` still visits the `OverlayPortal`'s `_RenderDeferredLayoutBox` (`traversalChildIdentifier`) directly on the `OverlayEntry`. Although the traversal child is excluded from its hit-test parent's `childrenInTraversalOrder` and `childrenInHitTestOrder` when its traversal parent is not in `_traversalParentNodes`, `SemanticsOwner.sendSemanticsUpdate` still serialized the traversal child via `_addToUpdate`. This sent an orphan `SemanticsNode` (not referenced by any parent in the update) to the engine, causing issues. This PR: - Skips calling `_addToUpdate` in `SemanticsOwner.sendSemanticsUpdate` for nodes in a traversal child subtree whose traversal parent is missing (`_isSkippedInHitTestTree`). - Marks affected traversal children, their unmerged descendants, and their hit-test `parent`s dirty when a traversal parent is newly registered, detaches, or changes its identifier so the nodes and hit-test child lists are updated in sync when the traversal parent enters or leaves the semantics tree. ## Pre-launch Checklist - [ ] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [ ] I read the [AI contribution guidelines] and understand my responsibilities, or I am not using AI tools. - [ ] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [ ] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [ ] I signed the [CLA]. - [ ] I listed at least one issue that this PR fixes in the description above. - [ ] I updated/added relevant in-code documentation (doc comments with `///`). - [ ] If this PR introduces a new feature or capability, I created and linked a website documentation issue or PR in [flutter/website] (or verified none is needed). - [ ] I added new tests to check the change I am making, or this PR is [test-exempt]. - [ ] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [ ] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. If this change needs to override an active code freeze, provide a comment explaining why. The code freeze workflow can be overridden by code reviewers. See pinned issues for any active code freezes with guidance. **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [AI contribution guidelines]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#ai-contribution-guidelines [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [flutter/website]: https://github.com/flutter/website [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
…279) Material's Slider always wraps its value indicator in an OverlayPortal. In a pushed route Flutter 3.47 then sends the engine a semantics node that no parent lists as a child (flutter/flutter#190357). The macOS and Windows accessibility bridges reject it, stay failed, and freeze their native tree on stale nodes; a later pointer move can then read a freed node and crash (flutter/flutter#193588). Part of #267. NavisSlider wraps Slider in its own Overlay.wrap(alwaysSizeToContent, Clip.none), which keeps the portal's semantics inside the slider. All 17 Slider sites use it and an architecture test forbids a bare Slider in lib. The wrap goes away once a stable Flutter ships flutter/flutter#193372. Co-authored-by: khalifa <[email protected]> Co-authored-by: Claude Sonnet <[email protected]>
fix #190357
When an
OverlayPortal(such as the one inside a MaterialSlider) is inside a pushed route, the route's entrance transition (e.g.,FadeTransition) starts at opacity0.0on the initial frame.RenderAnimatedOpacityMixin.visitChildrenForSemanticsskips visiting theOverlayPortalanchor (traversalParentIdentifier), while_RenderTheater.visitChildrenForSemanticsstill visits theOverlayPortal's_RenderDeferredLayoutBox(traversalChildIdentifier) directly on theOverlayEntry.Although the traversal child is excluded from its hit-test parent's
childrenInTraversalOrderandchildrenInHitTestOrderwhen its traversal parent is not in_traversalParentNodes,SemanticsOwner.sendSemanticsUpdatestill serialized the traversal child via_addToUpdate. This sent an orphanSemanticsNode(not referenced by any parent in the update) to the engine, causing issues.This PR:
_addToUpdateinSemanticsOwner.sendSemanticsUpdatefor nodes in a traversal child subtree whose traversal parent is missing (_isSkippedInHitTestTree).parents dirty when a traversal parent is newly registered, detaches, or changes its identifier so the nodes and hit-test child lists are updated in sync when the traversal parent enters or leaves the semantics tree.Pre-launch Checklist
///).If you need help, consider asking for advice on the #hackers-new channel on Discord.
If this change needs to override an active code freeze, provide a comment explaining why. The code freeze workflow can be overridden by code reviewers. See pinned issues for any active code freezes with guidance.
Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the
gemini-code-assistbot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.