Skip to content

Deactivate the children mounted before a sibling fails to mount - #194274

Draft
RaedDev wants to merge 1 commit into
flutter:masterfrom
RaedDev:multichild-failed-mount-cleanup
Draft

RaedDev wants to merge 1 commit into
flutter:masterfrom
RaedDev:multichild-failed-mount-cleanup

Conversation

@RaedDev

@RaedDev RaedDev commented Oct 13, 2026

Copy link
Copy Markdown

When a child of a MultiChildRenderObjectWidget throws while mounting (in initState, didChangeDependencies, a TabBar with no TabController, etc.), the siblings that already mounted are never deactivated. MultiChildRenderObjectElement.mount assigns _children only after the loop finishes, so _deactivateFailedSubtreeRecursively hits a LateInitializationError in visitChildren, which is swallowed. Those siblings stay registered as dependents of the inherited widgets above, and removing one of those inherited widgets later fails '_dependents.isEmpty': is not true.

This PR assigns the children that did mount to _children before rethrowing, so the existing failed-mount clean-up deactivates them. The happy path is unchanged.

Fixes #194273

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-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.

🤖 Generated with Claude Code

MultiChildRenderObjectElement.mount assigned _children only after every child
mounted, so when a child threw while mounting, the clean-up of the failed mount
could not visit the siblings mounted before it. They stayed registered as
dependents of the inherited widgets above, and removing one of those later
failed the '_dependents.isEmpty' assertion.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot added the framework flutter/packages/flutter repository. See also f: labels. label Oct 13, 2026
@google-cla

google-cla Bot commented Oct 13, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Children mounted before a sibling that throws while mounting are never deactivated ('_dependents.isEmpty' later)

1 participant