Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent LayoutBuilder from rebuilding more than once #147856

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

LongCatIsLooong
Copy link
Contributor

@LongCatIsLooong LongCatIsLooong commented May 6, 2024

Fixes #146379: introduces Element.buildScope which BuildOwner.buildScope uses to identify subtrees that need skipping (those with different BuildScopes). If Element.update calls updateChild then dirty children will still be rebuilt regardless of their build scopes.

This also introduces LayoutBuilder.applyDoubleRebuildFix migration flag which should only live for a week or less.

Caveats:

LayoutBuilder's render object calls markNeedsLayout if a descendant Element is dirty. Since markNeedsLayout also implies markNeedsPaint, the render object is going to be very repaint/relayout-happy.

Tests:

Presubmits with the migration flag set to true: https://github.com/flutter/flutter/pull/147856/checks?check_run_id=24629865893

Pre-launch Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@github-actions github-actions bot added framework flutter/packages/flutter repository. See also f: labels. f: scrolling Viewports, list views, slivers, etc. labels May 6, 2024
@github-actions github-actions bot removed the f: scrolling Viewports, list views, slivers, etc. label May 6, 2024
/// for its descendants. The [LayoutBuilder] widget, for example, establishes its
/// own [BuildScope] such that no descendant [Element]s may rebuild prematurely
/// until the incoming constraints are known.
final class BuildScope {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change moves dirty element tracking / rebuilding logic from BuildOwner to BuildScope, and keeps GlobalKey management stuff in BuildOwner

@LongCatIsLooong LongCatIsLooong force-pushed the layout-builder-build-once branch 2 times, most recently from 6f7bae5 to 622f4c0 Compare May 10, 2024 03:47
@LongCatIsLooong LongCatIsLooong marked this pull request as ready for review May 10, 2024 03:47
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.

LayoutBuilder's descendant widgets should not rebuild more than once in the same frame
1 participant