Skip to content

Commit

Permalink
Prevent LayoutBuilder from rebuilding more than once (#147856)
Browse files Browse the repository at this point in the history
Fixes flutter/flutter#146379: introduces `Element.buildScope` which `BuildOwner.buildScope` uses to identify subtrees that need skipping (those with different `BuildScope`s). 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
  • Loading branch information
LongCatIsLooong authored May 29, 2024
1 parent bc097c6 commit bafdb12
Show file tree
Hide file tree
Showing 8 changed files with 712 additions and 248 deletions.
9 changes: 3 additions & 6 deletions packages/flutter/lib/src/rendering/object.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1999,8 +1999,7 @@ abstract class RenderObject with DiagnosticableTreeMixin implements HitTestTarge
}

if (!activeLayoutRoot._debugMutationsLocked) {
final RenderObject? p = activeLayoutRoot.debugLayoutParent;
activeLayoutRoot = p is RenderObject ? p : null;
activeLayoutRoot = activeLayoutRoot.debugLayoutParent;
} else {
// activeLayoutRoot found.
break;
Expand Down Expand Up @@ -3004,7 +3003,7 @@ abstract class RenderObject with DiagnosticableTreeMixin implements HitTestTarge
owner!._nodesNeedingPaint.add(this);
owner!.requestVisualUpdate();
}
} else if (parent is RenderObject) {
} else if (parent != null) {
parent!.markNeedsPaint();
} else {
assert(() {
Expand All @@ -3020,9 +3019,7 @@ abstract class RenderObject with DiagnosticableTreeMixin implements HitTestTarge
//
// Trees rooted at a RenderView do not go through this
// code path because RenderViews are repaint boundaries.
if (owner != null) {
owner!.requestVisualUpdate();
}
owner?.requestVisualUpdate();
}
}

Expand Down
Loading

0 comments on commit bafdb12

Please sign in to comment.