Repository navigation
Commit 15ddda0
Rebuild a semantics fragment when its sibling conflict changes (flutter#190431)
`shouldFormSemanticsNode` ends in `return parentData!.explicitChildNodes
|| _hasSiblingConflict;`. When the parent data half changes,
`_didUpdateParentData` calls `markNeedsBuild`, because whether a
fragment forms a node may have changed. When the sibling conflict half
changes, nothing does. `markSiblingConfigurationConflict` just assigns
the flag and returns.
That gap is enough to corrupt the semantics tree. A fragment that stops
forming its own node keeps `built == true` and keeps its
`cachedSemanticsNode`. While it is out of the tree an ancestor can take
its children back, and its child list is never refreshed because
`_buildSemantics` short circuits on `built`. When the fragment forms a
node again it is handed straight back into the tree still holding
children that now belong to somebody else, and attaching it attaches
them too. The result is a `SemanticsNode` that is attached but has no
parent, which is what trips `assert(!child.attached)` in
`_replaceChildren`.
There are three earlier branches in `shouldFormSemanticsNode`
(`isSemanticBoundary`, `isRoot`, `contributesToSemanticsTree`). I went
looking for the same gap in those and could not find one, because
everything that feeds them goes through `markNeedsUpdate`, which nulls
parent data on its way up and so ends at `markNeedsBuild` anyway. I
would not swear to that the way I would to the paragraph above, so if
you know of a path I am not seeing, I would rather hear it now.
Outside debug builds this looks worse than an assertion. The orphan
still passes the `node.attached` check used when building
`childrenInTraversalOrder`, so its id goes to the engine as a child that
is not reachable, which is the shape of the `Failed to update
ui::AXTree, error: N will not be in the tree and is not the new root`
that @davidhicks980 reported in flutter#187198. I should be clear that this
part is me reading the code and not something I measured. I could not
find a way to drive VoiceOver from a test, so I have not confirmed that
the release mode failure is this and only this.
OverlayPortal runs into this reliably because showing an overlay child
creates and removes a sibling conflict for the anchors around it, so
node formation flips back and forth while the traversal graft moves
nodes between subtrees.
The change marks the fragment as needing a build when its sibling
conflict flag actually changes across a pass. It has to be a before and
after comparison rather than a check inside
`markSiblingConfigurationConflict`, because
`_marksConflictsInMergeGroup` deliberately resets every fragment to
false first and that reset is load bearing: `configToMergeUp` reads
`shouldFormSemanticsNode`, so leaving the previous pass's flag in place
while recomputing changes the result. The snapshot is taken in the
existing loop just before the reset, and the comparison rides along with
the loop that marks the conflicts, so there is no extra pass over
`mergeGroup`. Both directions are marked, because losing a conflict
changes node formation just as much as gaining one.
This runs during the parent data phase of `flushSemantics`, before the
build loop, so the fragment is rebuilt in the same flush.
### Why not repair the child list instead
The first version of this PR fixed the stale child list at the point of
the theft, and guarded `attach` the way `detach` already is. Both work,
and the test passes with either. @chunhtai pointed out that the fragment
should have known its children were taken and marked itself, which
turned out to be right, so this version drops both in favour of fixing
the invalidation. Happy to add the `attach` guard back as hardening if
you want it, since `detach` is still the only one of the ten methods in
`semantics.dart` that walk `_children` that checks whether the child is
still its own, but it is a separate concern from this bug.
While I was checking that number I found I had got it wrong earlier. I
said eight places here and on flutter#187198. It is ten, and the two I missed,
`_redepthChildren` and `_updateChildrenMergeFlags`, both assert on
`child.owner`, so a stale entry can trip there as well.
I did earlier report that invalidating was not possible because
`markNeedsBuild`, `RenderObject.markNeedsSemanticsUpdate` and the
`flushSemantics` exit assert all reject being dirtied during the flush.
That was true of invalidating at the moment of the theft, which is in
the middle of the build phase. Invalidating at the moment the decision
changes is a different place and does not have that problem.
### Test
The regression test goes in the existing `Semantics` group in
`overlay_portal_test.dart`. It needs two portal anchors before it will
fail, because the fragment whose conflict changes belongs to the sibling
anchor rather than the one being toggled. Taking the sibling out makes
it pass on unpatched master. It fails on master with `'!child.attached':
is not true` and passes with this change.
One thing worth flagging: the test has no semantics expectations of its
own, so its only failure mode is that framework assertion. Happy to add
some if you would rather it pinned the resulting tree down.
`test/semantics`, `test/rendering`, `test/widgets` and `test/material`
come out at 16171 passing with nothing failing.
Fixes flutter#189902
One request on that: @madenvel reported a `computeChildGeometry`
assertion variant in a comment on that issue, and closing it through
this PR would bury that report. Could that be split into its own issue?
I have not been able to reproduce it, it is described as Linux and
AT-SPI, and I do not know whether this change covers it. I said earlier
that I expected it to survive any fix in this area, but that was about
the two patches this version replaced, and the reasoning does not carry
over. Rebuilding the fragment refreshes its geometry too, so it is
genuinely an open question now rather than a no.
Partially addresses flutter#187198.
The assertions reported there go away. I said I would expect the AXTree
failure to go away as well, but when I tried to check that I could not
back it up. I recorded every semantics update sent to the engine in a
widget test and checked it against the rules the desktop bridge applies.
Neither of @davidhicks980's samples produces a bad update on current
master, with or without this change. The shape from flutter#182444 (Tooltips in
a ListView, and the MenuAnchor + Tooltip one reported there) does, with
the exact same `will not be in the tree and is not the new root` error,
and it does so with or without this change too. So that error has at
least one cause this PR does not touch, and I can't tell which one was
being hit in flutter#187198. The menu item positioning problem also reported
there is separate and this does not touch it.
For the record, flutter#182604 turned out not to be the same defect, even
though it sits downstream of the same refactor. It was fixed by flutter#192139
on the engine side, where `setChildrenInHitTestOrder` was overwriting
the traversal parent that `OverlayPortal` had set. I had said on the two
issues above that all three came down to one thing, which was wrong.
## Pre-launch Checklist
- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [AI contribution guidelines] and understand my
responsibilities, or I am not using AI tools.
- [x] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [x] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [x] I signed the [CLA].
- [x] I listed at least one issue that this PR fixes in the description
above.
- [x] I updated/added relevant documentation (doc comments with `///`).
- [x] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [x] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [x] All existing and new tests are passing.
<!-- 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/
[breaking change policy]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes
[Data Driven Fixes]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
---------
Co-authored-by: Victor Sanni <[email protected]>1 parent 0e62d43 commit 15ddda0
2 files changed
Lines changed: 68 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6606 | 6606 | | |
6607 | 6607 | | |
6608 | 6608 | | |
| 6609 | + | |
6609 | 6610 | | |
6610 | 6611 | | |
6611 | 6612 | | |
| 6613 | + | |
| 6614 | + | |
| 6615 | + | |
6612 | 6616 | | |
6613 | 6617 | | |
6614 | 6618 | | |
| |||
6626 | 6630 | | |
6627 | 6631 | | |
6628 | 6632 | | |
| 6633 | + | |
| 6634 | + | |
| 6635 | + | |
6629 | 6636 | | |
6630 | 6637 | | |
| 6638 | + | |
| 6639 | + | |
| 6640 | + | |
| 6641 | + | |
| 6642 | + | |
| 6643 | + | |
| 6644 | + | |
6631 | 6645 | | |
6632 | 6646 | | |
6633 | 6647 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3242 | 3242 | | |
3243 | 3243 | | |
3244 | 3244 | | |
| 3245 | + | |
| 3246 | + | |
| 3247 | + | |
| 3248 | + | |
| 3249 | + | |
| 3250 | + | |
| 3251 | + | |
| 3252 | + | |
| 3253 | + | |
| 3254 | + | |
| 3255 | + | |
| 3256 | + | |
| 3257 | + | |
| 3258 | + | |
| 3259 | + | |
| 3260 | + | |
| 3261 | + | |
| 3262 | + | |
| 3263 | + | |
| 3264 | + | |
| 3265 | + | |
| 3266 | + | |
| 3267 | + | |
| 3268 | + | |
| 3269 | + | |
| 3270 | + | |
| 3271 | + | |
| 3272 | + | |
| 3273 | + | |
| 3274 | + | |
| 3275 | + | |
| 3276 | + | |
| 3277 | + | |
| 3278 | + | |
| 3279 | + | |
| 3280 | + | |
| 3281 | + | |
| 3282 | + | |
| 3283 | + | |
| 3284 | + | |
| 3285 | + | |
| 3286 | + | |
| 3287 | + | |
| 3288 | + | |
| 3289 | + | |
| 3290 | + | |
| 3291 | + | |
| 3292 | + | |
| 3293 | + | |
| 3294 | + | |
| 3295 | + | |
| 3296 | + | |
| 3297 | + | |
| 3298 | + | |
3245 | 3299 | | |
3246 | 3300 | | |
3247 | 3301 | | |
| |||
0 commit comments