Skip to content

Commit 8009152

Browse files
authored
Fix sibling nodes crash under MergeSemantics (flutter#191587)
<!-- Thanks for filing a pull request! Reviewers are typically assigned within a week of filing a request. To learn more about code review, see our documentation on Tree Hygiene: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md --> fixes flutter#191095 ## 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 documentation (doc comments with `///`). - [ ] 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 [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
1 parent 0460cd3 commit 8009152

2 files changed

Lines changed: 75 additions & 1 deletion

File tree

‎packages/flutter/lib/src/rendering/object.dart‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6404,7 +6404,9 @@ class _RenderObjectSemantics extends _SemanticsFragment with DiagnosticableTreeM
64046404
node.tags!.addAll(tags);
64056405
}
64066406
}
6407-
node.isMergedIntoParent = parentData?.mergeIntoParent ?? false;
6407+
node.isMergedIntoParent =
6408+
configProvider.effective.isMergingSemanticsOfDescendants ||
6409+
(parentData?.mergeIntoParent ?? false);
64086410
}
64096411
}
64106412
_updateSiblingNodesGeometries();

‎packages/flutter/test/widgets/semantics_child_configs_delegate_test.dart‎

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,78 @@ void main() {
316316
expect(boundaryParentObject.hasRebuildSemantics, isTrue);
317317
expect(grandBoundaryParentObject.hasRebuildSemantics, isFalse);
318318
});
319+
320+
testWidgets('MergeSemantics + sibling merge group on update', (WidgetTester tester) async {
321+
final semantics = SemanticsTester(tester);
322+
const first = SemanticsTag('1');
323+
const second = SemanticsTag('2');
324+
const third = SemanticsTag('3');
325+
ChildSemanticsConfigurationsResult delegate(List<SemanticsConfiguration> configs) {
326+
final builder = ChildSemanticsConfigurationsResultBuilder();
327+
final sibling = <SemanticsConfiguration>[];
328+
for (final config in configs) {
329+
if (config.tagsChildrenWith(first) || config.tagsChildrenWith(third)) {
330+
sibling.add(config);
331+
} else {
332+
builder.markAsMergeUp(config);
333+
}
334+
}
335+
builder.markAsSiblingMergeGroup(sibling);
336+
return builder.build();
337+
}
338+
339+
Widget buildTree(String label) {
340+
return Directionality(
341+
textDirection: TextDirection.ltr,
342+
child: MergeSemantics(
343+
child: Semantics(
344+
label: 'parent',
345+
child: TestConfigDelegate(
346+
delegate: delegate,
347+
child: Column(
348+
children: <Widget>[
349+
Semantics(
350+
label: label,
351+
tagForChildren: first,
352+
child: const SizedBox(width: 100, height: 100),
353+
),
354+
Semantics(
355+
label: '2',
356+
tagForChildren: second,
357+
child: const SizedBox(width: 100, height: 100),
358+
),
359+
Semantics(
360+
label: '3',
361+
tagForChildren: third,
362+
child: const SizedBox(width: 100, height: 100),
363+
),
364+
],
365+
),
366+
),
367+
),
368+
),
369+
);
370+
}
371+
372+
await tester.pumpWidget(buildTree('1'));
373+
// Trigger a semantics update on the second frame to verify cached sibling nodes
374+
// maintain isMergedIntoParent = true.
375+
await tester.pumpWidget(buildTree('1 updated'));
376+
377+
expect(tester.takeException(), isNull);
378+
expect(
379+
semantics,
380+
hasSemantics(
381+
TestSemantics.root(
382+
children: <TestSemantics>[TestSemantics.rootChild(label: 'parent\n2\n1 updated\n3')],
383+
),
384+
ignoreId: true,
385+
ignoreRect: true,
386+
ignoreTransform: true,
387+
),
388+
);
389+
semantics.dispose();
390+
});
319391
}
320392

321393
class MarkSemanticsDirtySpy extends SingleChildRenderObjectWidget {

0 commit comments

Comments
 (0)