Repository navigation
Commit a3ee5e3
Fix OverlayPortal layout in shrink-wrapped overlays (flutter#193079)
When an `Overlay` sizes itself to its content,
`_RenderLayoutSurrogateProxyBox.performLayout` re-derived the
constraints for its deferred child instead of using the ones the theater
actually uses:
```dart
final BoxConstraints theaterConstraints = theater.constraints;
final Size boxSize = theaterConstraints.biggest.isFinite
? theaterConstraints.biggest
: theater.size;
```
This is wrong in two ways:
1. In the unbounded case it reads `theater.size` from a descendant
mid-layout, which trips `RenderBox.size accessed beyond the scope of
resize, layout, or permitted parent access` (`sizeAccessAllowed`). This
is the crash in flutter#192861.
2. When the overlay has `alwaysSizeToContent: true` *and* bounded
incoming constraints, it falls into the first branch and uses
`constraints.biggest` — but the theater sized itself to its content, so
the overlay child is laid out against constraints the theater never
used. There is no crash here, just a silently mis-sized overlay child.
`_RenderTheater.performLayout` already computes the correct value for
its non-positioned children. This PR caches it in
`_nonPositionedChildConstraints` and has the surrogate reuse it, so
there is a single source of truth and no ancestor size read.
| Theater state | Before | After |
| --- | --- | --- |
| Bounded, `alwaysSizeToContent: false` | `constraints.biggest` |
unchanged |
| Unbounded | `theater.size` (illegal read) | same value, no illegal
read |
| Bounded, `alwaysSizeToContent: true` | `constraints.biggest` (wrong) |
content size |
The field is assigned before any non-size-determining child is laid out.
It cannot be read before that assignment: the theater is always an
ancestor of its layout surrogates, so a surrogate's first layout is only
reachable from `_RenderTheater.performLayout`, and the only subtree laid
out before the assignment is the size-determining one, which the
existing `_layingOutSizeDeterminingChild` guard already skips. I added a
comment recording this, since the invariant spans two classes.
This also restores the `assert(size == theater.size)` invariant in
`_RenderDeferredLayoutBox`, which case 2 above could violate.
Fixes flutter#192861
## Tests
Added a regression test to `overlay_portal_test.dart`, run over both
unbounded and `alwaysSizeToContent` overlays, covering open → resize
while open → close → reopen, with `verifyTreeIsClean()` at each step.
Without the source change, the unbounded variant throws the assertion
from the issue and the bounded variant sizes the overlay child to
800x600 instead of 100x100.
Local results: all 7331 tests in `packages/flutter/test/widgets/` pass,
plus `dropdown_menu_test.dart`, `dropdown_test.dart`,
`menu_anchor_test.dart` and `tooltip_test.dart`. The only failures I saw
(`widget_inspector` screenshot, two dropdown goldens) reproduce
identically on an unmodified checkout.
## 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 in-code documentation (doc comments with
`///`).
- [x] If this PR introduces a new feature or capability, I created and
linked a website documentation issue or PR in [flutter/website] (or
verified none is needed).
- [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/
[flutter/tests]: https://github.com/flutter/tests
[flutter/website]: https://github.com/flutter/website
[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
---------
Co-authored-by: Victor Sanni <[email protected]>1 parent fca9fd9 commit a3ee5e3
2 files changed
Lines changed: 115 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1391 | 1391 | | |
1392 | 1392 | | |
1393 | 1393 | | |
1394 | | - | |
| 1394 | + | |
1395 | 1395 | | |
1396 | 1396 | | |
1397 | 1397 | | |
| |||
1401 | 1401 | | |
1402 | 1402 | | |
1403 | 1403 | | |
1404 | | - | |
| 1404 | + | |
1405 | 1405 | | |
1406 | 1406 | | |
1407 | 1407 | | |
| |||
1460 | 1460 | | |
1461 | 1461 | | |
1462 | 1462 | | |
| 1463 | + | |
| 1464 | + | |
| 1465 | + | |
| 1466 | + | |
| 1467 | + | |
| 1468 | + | |
| 1469 | + | |
| 1470 | + | |
| 1471 | + | |
| 1472 | + | |
1463 | 1473 | | |
1464 | 1474 | | |
1465 | 1475 | | |
| |||
1474 | 1484 | | |
1475 | 1485 | | |
1476 | 1486 | | |
1477 | | - | |
| 1487 | + | |
1478 | 1488 | | |
1479 | 1489 | | |
1480 | | - | |
| 1490 | + | |
1481 | 1491 | | |
1482 | 1492 | | |
1483 | 1493 | | |
| |||
2796 | 2806 | | |
2797 | 2807 | | |
2798 | 2808 | | |
2799 | | - | |
2800 | | - | |
2801 | | - | |
2802 | | - | |
2803 | | - | |
| 2809 | + | |
2804 | 2810 | | |
2805 | 2811 | | |
2806 | 2812 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
662 | 662 | | |
663 | 663 | | |
664 | 664 | | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
| 746 | + | |
| 747 | + | |
| 748 | + | |
| 749 | + | |
| 750 | + | |
| 751 | + | |
| 752 | + | |
| 753 | + | |
| 754 | + | |
| 755 | + | |
| 756 | + | |
| 757 | + | |
| 758 | + | |
| 759 | + | |
| 760 | + | |
| 761 | + | |
| 762 | + | |
| 763 | + | |
| 764 | + | |
665 | 765 | | |
666 | 766 | | |
667 | 767 | | |
| |||
0 commit comments