Repository navigation
Conversation
FlexLayout's SelfSizing callback measured items using GetConstraints(), which returns the flex container's full size and ignores the item's own margins. The flex engine then arranges the item at the stretched cross-axis size (container minus margins), which is narrower. Wrapping content (e.g. Label text with LineBreakMode=WordWrap) wraps against a width the item never receives, and since the arrange pass never re-measures, the overflow line is cut off. The engine already passes the correct available size into the callback (the ref w/h parameters); clamp the measure constraints with those values when they are known. Fixes dotnet#27520 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 36416Or
iex "& { $(irm https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 36416" |
|
Hey there @@Kas-code! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed. |
|
Hey there @Kas-code! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed. |
|
@dotnet-policy-service agree |
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
This comment has been minimized.
This comment has been minimized.
MauiBot
left a comment
There was a problem hiding this comment.
Expert Review — 1 findings
See inline comments for details.
| // size, which can be wider than the frame the item will actually receive; | ||
| // text measured against the wider constraint wraps at a width it will | ||
| // never have at arrange time, and the last line ends up cut off. | ||
| if (!float.IsNaN(w) && w > 0 && w < sizeConstraints.Width) |
There was a problem hiding this comment.
🔍 AI-Generated Review (multi-model)
[major] Layout Measure-Arrange Correctness — w/h are not always the final arranged size. In the main axis they can be the pre-flex basis (for example a Row child with WidthRequest=100 and Grow=1 in a 300-wide FlexLayout), and layout_items later adds the grow space to arrange it at 300. Clamping the measure constraint to 100 makes wrapping content compute its cross-axis size for the wrong width, leaving the row too tall (or stale when shrink applies). Please only apply this clamp to the cross axis when stretch has already produced the final frame size, or add coverage for grow/shrink main-axis cases.
There was a problem hiding this comment.
Good catch — the main-axis value at the time the SelfSizing callback runs is indeed the pre-flex basis (the explicit size, or 0), and layout_items distributes grow/shrink space after the callback returns. So a child with WidthRequest=100 and Grow=1 in a 300-wide Row would have been measured at 100 but arranged at 300.
Fixed by making the clamp direction-aware: it now applies only to the cross axis (width for Column/ColumnReverse, height for Row/RowReverse), which is the axis the reported bug (#27520) is about. The main axis keeps the previous GetConstraints() behavior. Also added a regression test for the grow scenario you described (GrowingItemMainAxisMeasureConstraintIsNotClampedToBasis_Issue27520) — it fails against the previous revision of this PR.
One note on scoping: I didn't gate the cross-axis clamp on the alignment being Stretch. For non-stretch alignments the item is arranged at its own measured size, so the engine-provided cross-axis value (container minus the item's margins) is still a valid upper bound for the measure constraint — and tighter than the full container size used before. Wrap mode is unaffected, since the cross-axis value is NaN at that point and the clamp is skipped.
kubaflo
left a comment
There was a problem hiding this comment.
Could you please check the suggestions?
…the main axis after measure
|
I have made the suggested change and re-tested. Fix is still working. |
This comment has been minimized.
This comment has been minimized.
|
@kubaflo thanks for reviewing. I'm not sure if the last AI review came back with any suggested changes. Anything more for me to do on this or is it all good now? |
An item can never be arranged larger than its container minus its own margins; grow and shrink only redistribute space within those bounds. Previously only the cross axis was clamped (to the engine-provided stretch size), so in Direction=Row an item with horizontal margins was still measured at the full container width from GetConstraints() and then shrunk before arrange, letting wrapping content wrap against a width it never receives. Subtract the item's margins from both container-derived constraints before applying the cross-axis clamp. Adds the reviewer's regression test for the Row shrink case.
This comment has been minimized.
This comment has been minimized.
MauiBot
left a comment
There was a problem hiding this comment.
Expert Review — 2 findings
See inline comments for details.
| // margins first... | ||
| if (!double.IsPositiveInfinity(sizeConstraints.Width)) | ||
| { | ||
| sizeConstraints.Width = Math.Max(0, sizeConstraints.Width - (it.MarginLeft + it.MarginRight)); |
There was a problem hiding this comment.
🔍 AI-Generated Review (multi-model)
[major] Layout Measure-Arrange Correctness — child.Measure(...) already subtracts the child margin for normal controls via VisualElement.MeasureOverride → LayoutExtensions.ComputeDesiredSize before it calls the handler. Pre-subtracting it.MarginLeft + it.MarginRight here means a real Label/Button with Margin=10 in a 400-wide FlexLayout is measured by its handler at 360 instead of the 380 width it will occupy after FlexLayout applies margins. That makes wrapping content wrap too early/leave blank space. The fix should clamp FlexLayout against the space the child will occupy without also pre-subtracting the margin before calling Measure, or otherwise avoid double-applying the same margin for handler-backed controls.
There was a problem hiding this comment.
The premise here isn't quite right: with Margin=10 in a 400-wide FlexLayout, the child does not occupy 380 — it occupies 360. FlexLayout passes the engine-computed frame (already reduced to 380 by the engine's margin handling) directly to child.Arrange, and Arrange bounds are margin-inclusive by convention, so ComputeFrame subtracts the margin again — the content frame comes out at 360. That double application at arrange is long-standing FlexLayout behavior (the engine also offsets the position by the margin, which is why flex children have always sat at 2× their margin offset), and changing it would visibly shift every existing FlexLayout layout, so this PR doesn't touch it.
Given that, the measure path in this PR is symmetric with arrange, not double-subtracting: Measure(400 − 20 = 380) → ComputeDesiredSize subtracts the margin → the handler measures at 360, which is exactly the content width it is arranged into. Without the pre-subtraction the handler would measure at 380 but be arranged into 360 — which is the bug this PR fixes.
I've added a handler-backed regression test (HandlerBackedItemWithMarginIsMeasuredAtArrangedWidth_Issue27520, Column + Row) that exercises the real ComputeDesiredSize path with a mocked IViewHandler and asserts the handler's measure width equals the arranged Frame.Width (360 == 360), and a comment at the fix site documenting the measure/arrange symmetry.
| public double MeasuredWidthConstraint { get; private set; } = double.NaN; | ||
| public double MeasuredHeightConstraint { get; private set; } = double.NaN; | ||
|
|
||
| protected override Size MeasureOverride(double widthConstraint, double heightConstraint) |
There was a problem hiding this comment.
🔍 AI-Generated Review (multi-model)
[major] Regression Prevention and Test Coverage — This test double overrides MeasureOverride, so it bypasses the production path where VisualElement.MeasureOverride calls LayoutExtensions.ComputeDesiredSize and subtracts view.Margin before invoking the handler. As a result, the new margin tests pass even though handler-backed controls such as Label/Button now have their margin subtracted once in FlexLayout and once again in ComputeDesiredSize. Please add at least one regression using a handler-backed control or mock IViewHandler.GetDesiredSize so the test exercises the real margin-subtraction path.
There was a problem hiding this comment.
Good point — added. HandlerBackedItemWithMarginIsMeasuredAtArrangedWidth_Issue27520 is a [Theory] over Column and Row using a plain View with a mocked IViewHandler (Substitute.For), so measurement flows through the production VisualElement.MeasureOverride → LayoutExtensions.ComputeDesiredSize path, including its margin subtraction. It asserts the width the handler is asked to measure at equals the Frame.Width the view is arranged into (360 for a 400 container with Margin=10: 400 − flex item margin 20 − ComputeDesiredSize margin 20, matching arrange's engine frame 380 − ComputeFrame margin 20). There's no double-subtraction discrepancy for handler-backed controls — measure and arrange agree, which this test now locks in.
The earlier margin tests overrode MeasureOverride directly, bypassing LayoutExtensions.ComputeDesiredSize, so they did not prove the fix is correct for handler-backed controls. This test uses a plain View with a mocked IViewHandler, exercising the production path where the margin is subtracted from the constraint before the handler measures. The two margin subtractions are symmetric, not double-applied: at measure the constraint is container minus the flex item margin, and ComputeDesiredSize subtracts the margin again before the platform measures; at arrange the engine frame already excludes the margin and ComputeFrame subtracts it once more from the bounds. The platform control is measured at exactly the content width it is arranged into (400 - 20 - 20 = 360 both ways). Also documents this symmetry at the constraint-tightening site. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
MauiBot
left a comment
There was a problem hiding this comment.
AI Review Summary
@Kas-code — new AI review results are available based on this last commit:
906d852. To request a fresh review after new comments or commits, comment/review rerun.
🗂️ Review Sessions — click to expand
🚦 Gate — Test Before & After Fix
Gate Result: ✅ PASSED
Platform: ANDROID · Base: main · Merge base: 19741e9a
| Test | Without Fix (expect FAIL) | With Fix (expect PASS) |
|---|---|---|
🧪 FlexLayoutTests FlexLayoutTests |
✅ FAIL — 145s | ✅ PASS — 119s |
🔴 Without fix — 🧪 FlexLayoutTests: FAIL ✅ · 145s
Determining projects to restore...
Restored /home/vsts/work/1/s/src/TestUtils/src/TestUtils/TestUtils.csproj (in 3.83 sec).
Restored /home/vsts/work/1/s/src/Graphics/src/Graphics/Graphics.csproj (in 192 ms).
Restored /home/vsts/work/1/s/src/Essentials/src/Essentials.csproj (in 2.62 sec).
Restored /home/vsts/work/1/s/src/Core/src/Core.csproj (in 809 ms).
Restored /home/vsts/work/1/s/src/Core/maps/src/Maps.csproj (in 9.49 sec).
Restored /home/vsts/work/1/s/src/Controls/src/Xaml/Controls.Xaml.csproj (in 52 ms).
Restored /home/vsts/work/1/s/src/Controls/src/Core/Controls.Core.csproj (in 26 ms).
Restored /home/vsts/work/1/s/src/Controls/Maps/src/Controls.Maps.csproj (in 26 ms).
Restored /home/vsts/work/1/s/src/Controls/tests/Core.UnitTests/Controls.Core.UnitTests.csproj (in 1.25 sec).
1 of 10 projects are up-to-date for restore.
##vso[build.updatebuildnumber]10.0.90-ci+azdo.14599224
Graphics -> /home/vsts/work/1/s/artifacts/bin/Graphics/Debug/net10.0/Microsoft.Maui.Graphics.dll
##vso[build.updatebuildnumber]10.0.90-ci+azdo.14599224
Essentials -> /home/vsts/work/1/s/artifacts/bin/Essentials/Debug/net10.0/Microsoft.Maui.Essentials.dll
##vso[build.updatebuildnumber]10.0.90-ci+azdo.14599224
Core -> /home/vsts/work/1/s/artifacts/bin/Core/Debug/net10.0/Microsoft.Maui.dll
Controls.BindingSourceGen -> /home/vsts/work/1/s/artifacts/bin/Controls.BindingSourceGen/Debug/netstandard2.0/Microsoft.Maui.Controls.BindingSourceGen.dll
##vso[build.updatebuildnumber]10.0.90-ci+azdo.14599224
Maps -> /home/vsts/work/1/s/artifacts/bin/Maps/Debug/net10.0/Microsoft.Maui.Maps.dll
##vso[build.updatebuildnumber]10.0.90-ci+azdo.14599224
Controls.Core -> /home/vsts/work/1/s/artifacts/bin/Controls.Core/Debug/net10.0/Microsoft.Maui.Controls.dll
##vso[build.updatebuildnumber]10.0.90-ci+azdo.14599224
Controls.Xaml -> /home/vsts/work/1/s/artifacts/bin/Controls.Xaml/Debug/net10.0/Microsoft.Maui.Controls.Xaml.dll
##vso[build.updatebuildnumber]10.0.90-ci+azdo.14599224
Controls.Maps -> /home/vsts/work/1/s/artifacts/bin/Controls.Maps/Debug/net10.0/Microsoft.Maui.Controls.Maps.dll
TestUtils -> /home/vsts/work/1/s/artifacts/bin/TestUtils/Debug/netstandard2.0/Microsoft.Maui.TestUtils.dll
Controls.Core.UnitTests -> /home/vsts/work/1/s/artifacts/bin/Controls.Core.UnitTests/Debug/net10.0/Microsoft.Maui.Controls.Core.UnitTests.dll
Test run for /home/vsts/work/1/s/artifacts/bin/Controls.Core.UnitTests/Debug/net10.0/Microsoft.Maui.Controls.Core.UnitTests.dll (.NETCoreApp,Version=v10.0)
VSTest version 18.0.1 (x64)
Starting test execution, please wait...
A total of 1 test files matched the specified pattern.
[xUnit.net 00:00:00.00] xUnit.net VSTest Adapter v2.8.2+699d445a1a (64-bit .NET 10.0.0)
[xUnit.net 00:00:00.24] Discovering: Microsoft.Maui.Controls.Core.UnitTests
[xUnit.net 00:00:02.30] Discovered: Microsoft.Maui.Controls.Core.UnitTests
[xUnit.net 00:00:02.34] Starting: Microsoft.Maui.Controls.Core.UnitTests
[xUnit.net 00:00:02.55] Assert.Equal() Failure: Values differ
[xUnit.net 00:00:02.55] Expected: 380
[xUnit.net 00:00:02.55] Actual: 400
[xUnit.net 00:00:02.55] Stack Trace:
[xUnit.net 00:00:02.55] /_/src/Controls/tests/Core.UnitTests/Layouts/FlexLayoutTests.cs(467,0): at Microsoft.Maui.Controls.Core.UnitTests.Layouts.FlexLayoutTests.StretchedItemWithMarginIsMeasuredAtArrangedHeight_Issue27520()
[xUnit.net 00:00:02.55] at System.Reflection.MethodBaseInvoker.InterpretedInvoke_Method(Object obj, IntPtr* args)
[xUnit.net 00:00:02.55] at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)
[xUnit.net 00:00:02.54] StretchedItemWithMarginIsMeasuredAtArrangedHeight_Issue27520 [FAIL]
[xUnit.net 00:00:02.68] Assert.Equal() Failure: Values differ
[xUnit.net 00:00:02.68] StretchedItemWithMarginIsMeasuredAtArrangedWidth_Issue27520 [FAIL]
[xUnit.net 00:00:02.68] Expected: 380
[xUnit.net 00:00:02.68] Actual: 400
[xUnit.net 00:00:02.68] Stack Trace:
[xUnit.net 00:00:02.68] /_/src/Controls/tests/Core.UnitTests/Layouts/FlexLayoutTests.cs(442,0): at Microsoft.Maui.Controls.Core.UnitTests.Layouts.FlexLayoutTests.StretchedItemWithMarginIsMeasuredAtArrangedWidth_Issue27520()
[xUnit.net 00:00:02.68] at System.Reflection.MethodBaseInvoker.InterpretedInvoke_Method(Object obj, IntPtr* args)
[xUnit.net 00:00:02.68] at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)
Passed GrowItemsPreserveNaturalSizeAndDistributeFreeSpaceEqually_Issue34464 [92 ms]
Passed FlexLayoutRecognizesVisibilityChange [13 ms]
Failed StretchedItemWithMarginIsMeasuredAtArrangedHeight_Issue27520 [4 ms]
Error Message:
Assert.Equal() Failure: Values differ
Expected: 380
Actual: 400
Stack Trace:
at Microsoft.Maui.Controls.Core.UnitTests.Layouts.FlexLayoutTests.StretchedItemWithMarginIsMeasuredAtArrangedHeight_Issue27520() in /_/src/Controls/tests/Core.UnitTests/Layouts/FlexLayoutTests.cs:line 467
at System.Reflection.MethodBaseInvoker.InterpretedInvoke_Method(Object obj, IntPtr* args)
at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)
Passed UnconstrainedWidthChildrenHaveWidth [135 ms]
Passed UnconstrainedMeasureHonorsFlexDirection(widthConstraint: Infinity, heightConstraint: 400, flexDirection: RowReverse) [2 ms]
Passed UnconstrainedMeasureHonorsFlexDirection(widthConstraint: 400, heightConstraint: Infinity, flexDirection: ColumnReverse) [< 1 ms]
Passed UnconstrainedMeasureHonorsFlexDirection(widthConstraint: Infinity, heightConstraint: 400, flexDirection: Row) [< 1 ms]
Passed UnconstrainedMeasureHonorsFlexDirection(widthConstraint: 400, heightConstraint: Infinity, flexDirection: Column) [< 1 ms]
Failed StretchedItemWithMarginIsMeasuredAtArrangedWidth_Issue27520 [< 1 ms]
Error Message:
Assert.Equal() Failure: Values differ
Expected: 380
Actual: 400
Stack Trace:
at Microsoft.Maui.Controls.Core.UnitTests.Layouts.FlexLayoutTests.StretchedItemWithMarginIsMeasuredAtArrangedWidth_Issue27520() in /_/src/Controls/tests/Core.UnitTests/Layouts/FlexLayoutTests.cs:line 442
at System.Reflection.MethodBaseInvoker.InterpretedInvoke_Method(Object obj, IntPtr* args)
at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)
[xUnit.net 00:00:02.71] Assert.Equal() Failure: Values differ
[xUnit.net 00:00:02.71] Expected: 380
[xUnit.net 00:00:02.71] Actual: 400
[xUnit.net 00:00:02.71] Stack Trace:
[xUnit.net 00:00:02.71] /_/src/Controls/tests/Core.UnitTests/Layouts/FlexLayoutTests.cs(532,0): at Microsoft.Maui.Controls.Core.UnitTests.Layouts.FlexLayoutTests.ShrunkRowItemWithMarginIsMeasuredAtArrangedWidth_Issue27520()
[xUnit.net 00:00:02.71] at System.Reflection.MethodBaseInvoker.InterpretedInvoke_Method(Object obj, IntPtr* args)
[xUnit.net 00:00:02.71] at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)
Passed FlexLayoutPaddingShouldBeAppliedCorrectly_ColumnDirection [3 ms]
Passed ArrangeOnlyPassUsesUpdatedWidthRequest [4 ms]
Passed FlexLayoutMeasuresImagesUnconstrained [2 ms]
Passed UnconstrainedHeightChildrenHaveHeight [< 1 ms]
Passed ArrangeOnlyPassFallsBackToDesiredSizeWhenWidthRequestCleared [< 1 ms]
Passed GrowingItemMainAxisMeasureConstraintIsNotClampedToBasis_Issue27520 [2 ms]
Failed ShrunkRowItemWithMarginIsMeasuredAtArrangedWidth_Issue27520 [2 ms]
Error Message:
Assert.Equal() Failure: Values differ
Expected: 380
Actual: 400
Stack Trace:
at Microsoft.Maui.Controls.Core.UnitTests.Layouts.FlexLayoutTests.ShrunkRowItemWithMarginIsMeasuredAtArrangedWidth_Issue27520() in /_/src/Controls/tests/Core.UnitTests/Layouts/FlexLayoutTests.cs:line 532
at System.Reflection.MethodBaseInvoker.InterpretedInvoke_Method(Object obj, IntPtr* args)
at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)
Passed FlexLayoutPaddingShouldBeAppliedCorrectly_RowDirection [2 ms]
Passed ArrangeOnlyPassUsesDesiredSizeWhenNoWidthRequest [< 1 ms]
[xUnit.net 00:00:02.72] Finished: Microsoft.Maui.Controls.Core.UnitTests
[xUnit.net 00:00:02.71] ShrunkRowItemWithMarginIsMeasuredAtArrangedWidth_Issue27520 [FAIL]
Passed ArrangeOnlyPassUsesUpdatedHeightRequest [< 1 ms]
Test Run Failed.
Total tests: 19
Passed: 16
Failed: 3
Total time: 3.5803 Seconds
🟢 With fix — 🧪 FlexLayoutTests: PASS ✅ · 119s
Determining projects to restore...
All projects are up-to-date for restore.
##vso[build.updatebuildnumber]10.0.90-ci+azdo.14599224
Graphics -> /home/vsts/work/1/s/artifacts/bin/Graphics/Debug/net10.0/Microsoft.Maui.Graphics.dll
##vso[build.updatebuildnumber]10.0.90-ci+azdo.14599224
Essentials -> /home/vsts/work/1/s/artifacts/bin/Essentials/Debug/net10.0/Microsoft.Maui.Essentials.dll
##vso[build.updatebuildnumber]10.0.90-ci+azdo.14599224
Core -> /home/vsts/work/1/s/artifacts/bin/Core/Debug/net10.0/Microsoft.Maui.dll
Controls.BindingSourceGen -> /home/vsts/work/1/s/artifacts/bin/Controls.BindingSourceGen/Debug/netstandard2.0/Microsoft.Maui.Controls.BindingSourceGen.dll
##vso[build.updatebuildnumber]10.0.90-ci+azdo.14599224
##vso[build.updatebuildnumber]10.0.90-ci+azdo.14599224
Controls.Core -> /home/vsts/work/1/s/artifacts/bin/Controls.Core/Debug/net10.0/Microsoft.Maui.Controls.dll
Maps -> /home/vsts/work/1/s/artifacts/bin/Maps/Debug/net10.0/Microsoft.Maui.Maps.dll
##vso[build.updatebuildnumber]10.0.90-ci+azdo.14599224
Controls.Xaml -> /home/vsts/work/1/s/artifacts/bin/Controls.Xaml/Debug/net10.0/Microsoft.Maui.Controls.Xaml.dll
##vso[build.updatebuildnumber]10.0.90-ci+azdo.14599224
Controls.Maps -> /home/vsts/work/1/s/artifacts/bin/Controls.Maps/Debug/net10.0/Microsoft.Maui.Controls.Maps.dll
TestUtils -> /home/vsts/work/1/s/artifacts/bin/TestUtils/Debug/netstandard2.0/Microsoft.Maui.TestUtils.dll
Controls.Core.UnitTests -> /home/vsts/work/1/s/artifacts/bin/Controls.Core.UnitTests/Debug/net10.0/Microsoft.Maui.Controls.Core.UnitTests.dll
Test run for /home/vsts/work/1/s/artifacts/bin/Controls.Core.UnitTests/Debug/net10.0/Microsoft.Maui.Controls.Core.UnitTests.dll (.NETCoreApp,Version=v10.0)
VSTest version 18.0.1 (x64)
Starting test execution, please wait...
A total of 1 test files matched the specified pattern.
[xUnit.net 00:00:00.01] xUnit.net VSTest Adapter v2.8.2+699d445a1a (64-bit .NET 10.0.0)
[xUnit.net 00:00:00.45] Discovering: Microsoft.Maui.Controls.Core.UnitTests
[xUnit.net 00:00:02.42] Discovered: Microsoft.Maui.Controls.Core.UnitTests
[xUnit.net 00:00:02.45] Starting: Microsoft.Maui.Controls.Core.UnitTests
Passed GrowItemsPreserveNaturalSizeAndDistributeFreeSpaceEqually_Issue34464 [101 ms]
Passed FlexLayoutRecognizesVisibilityChange [24 ms]
Passed StretchedItemWithMarginIsMeasuredAtArrangedHeight_Issue27520 [4 ms]
Passed UnconstrainedWidthChildrenHaveWidth [127 ms]
Passed UnconstrainedMeasureHonorsFlexDirection(widthConstraint: Infinity, heightConstraint: 400, flexDirection: RowReverse) [2 ms]
Passed UnconstrainedMeasureHonorsFlexDirection(widthConstraint: 400, heightConstraint: Infinity, flexDirection: ColumnReverse) [< 1 ms]
Passed UnconstrainedMeasureHonorsFlexDirection(widthConstraint: Infinity, heightConstraint: 400, flexDirection: Row) [< 1 ms]
Passed UnconstrainedMeasureHonorsFlexDirection(widthConstraint: 400, heightConstraint: Infinity, flexDirection: Column) [< 1 ms]
Passed StretchedItemWithMarginIsMeasuredAtArrangedWidth_Issue27520 [< 1 ms]
Passed FlexLayoutPaddingShouldBeAppliedCorrectly_ColumnDirection [1 ms]
Passed ArrangeOnlyPassUsesUpdatedWidthRequest [3 ms]
Passed FlexLayoutMeasuresImagesUnconstrained [1 ms]
Passed UnconstrainedHeightChildrenHaveHeight [< 1 ms]
Passed ArrangeOnlyPassFallsBackToDesiredSizeWhenWidthRequestCleared [2 ms]
Passed GrowingItemMainAxisMeasureConstraintIsNotClampedToBasis_Issue27520 [< 1 ms]
Passed ShrunkRowItemWithMarginIsMeasuredAtArrangedWidth_Issue27520 [< 1 ms]
Passed FlexLayoutPaddingShouldBeAppliedCorrectly_RowDirection [2 ms]
Passed ArrangeOnlyPassUsesDesiredSizeWhenNoWidthRequest [< 1 ms]
[xUnit.net 00:00:02.83] Finished: Microsoft.Maui.Controls.Core.UnitTests
Passed ArrangeOnlyPassUsesUpdatedHeightRequest [< 1 ms]
Test Run Successful.
Total tests: 19
Passed: 19
Total time: 3.6210 Seconds
📁 Fix files reverted (1 files)
src/Controls/src/Core/Layout/FlexLayout.cs
📱 UI Tests — Label,Layout
Detected UI test categories: Label,Layout
[!WARNING]
No UI test results were produced for the detected categories. The platform-pool run
returned no results — most often because the PR build failed (see the Gate section) or
the deep UI test stage was skipped. Fix the build/gate issues and comment/review rerun
to get UI test results.
📋 Pre-Flight — Context & Validation
Issue: #27520 - LineBreakMode="WordWrap" sometimes cuts off the last word
PR: #36416 - Fix FlexLayout measuring items wider than their arranged size
Platforms Affected: Android, iOS (shared FlexLayout code)
Files Changed: 1 implementation, 1 test
Key Findings
- Issue #27520 reports wrapped
Label/FormattedTextcontent inside FlexLayout sometimes losing the last word/line on Android and iOS because text wraps against a wider measured width than the width ultimately arranged. - PR #36416 changes
src/Controls/src/Core/Layout/FlexLayout.csso non-image child measurement constraints are tightened by margins and cross-axis final callback dimensions, then adds unit regression tests inFlexLayoutTests.csfor stretched column, stretched row, row grow, and row shrink with margins. - Prior inline review concerns were addressed in the current diff: main-axis grow is no longer clamped to pre-flex basis, and row main-axis shrink with margins is now covered.
ghauthentication is unavailable in this environment; PR/issue metadata was gathered from public GitHub API and local checked-out diff.
Code Review Summary
Verdict: NEEDS_DISCUSSION
Confidence: low
Errors: 0 | Warnings: 0 | Suggestions: 1
Key code review findings:
- ℹ
src/Controls/tests/Core.UnitTests/Layouts/FlexLayoutTests.cs:410/:505— Consider adding a handler-backed margin regression because current tests validate the outerIView.Measureconstraint path rather than a normal Label handler path. - Failure modes probed: margined stretched Column/Row children, Row grow with
WidthRequest, Row shrink with horizontal margins, Image special case, infinity/zero constraints, and arrange-only behavior. - Blast radius: every non-nested FlexLayout child measurement; hot path but no added allocations, no startup path, no static state.
Fix Candidates
| # | Source | Approach | Test Result | Files Changed | Notes |
|---|---|---|---|---|---|
| PR | PR #36416 | Tighten finite FlexLayout child measure constraints by the child margins, then clamp only the cross-axis callback dimension when known. | ✅ PASSED (Gate) | FlexLayout.cs, FlexLayoutTests.cs |
Original PR; gate already verified fail-without-fix/pass-with-fix. |
🔬 Code Review — Deep Analysis
Code Review — PR #36416
Independent Assessment
What this changes: FlexLayout now tightens child measure constraints by the child’s margins before measuring, and only clamps the known w/h callback value on the cross axis to avoid main-axis grow/shrink basis regressions.
Inferred motivation: Prevent wrapping content from measuring against a size larger than the one it receives during arrange.
Reconciliation with PR Narrative
Author claims: Fixes Label word-wrap clipping where FlexLayout measured against full container size while arranging with margins applied.
Agreement/disagreement: The implementation matches that claim. It also incorporates prior feedback for main-axis grow and row shrink cases.
Prior Review Reconciliation
| Prior ❌ Error Finding | Source | Status | Evidence |
|---|---|---|---|
Main-axis w/h clamp could use pre-flex basis and break grow/shrink |
MauiBot [major] inline review |
✅ Fixed | Current code only applies w/h clamp on cross axis (FlexLayout.cs:553-563) and adds GrowingItemMainAxisMeasureConstraintIsNotClampedToBasis_Issue27520. |
| Row main-axis shrink with horizontal margins still measured too wide | jfversluis inline review | ✅ Fixed | Current code first subtracts margins from both finite constraints (FlexLayout.cs:538-546) and adds ShrunkRowItemWithMarginIsMeasuredAtArrangedWidth_Issue27520. |
Blast Radius Assessment
- Runs for all instances: yes — every non-nested FlexLayout child measurement.
- Startup impact: no.
- Static/shared state: no.
- Hot path: yes — layout measure; added work is scalar arithmetic/comparisons with no allocations beyond existing code.
CI Status
- Required-check result: undetermined/pending.
- Classification: undetermined.
- Action taken:
gh pr checks --requiredfailed becauseghis unauthenticated. Public GitHub check-runs show combined status pending and Build Analysis in progress for heada55888a. Invokedazdo-build-investigator;ci-analysiswas unavailable in this environment. Confidence capped low. Local targeted validation:dotnet test ... --filter FullyQualifiedName~FlexLayoutTests --no-restorepassed, 19/19.
Findings
No ❌ Error or
💡 Suggestion — Add one handler-backed margin regression
The new tests in FlexLayoutTests.cs:410 and FlexLayoutTests.cs:505 override MeasureOverride, so they validate FlexLayout’s outer IView.Measure constraint but not the normal VisualElement -> ComputeDesiredSize -> Handler.GetDesiredSize margin path. The current fix appears correct, but a mock handler-backed view would more directly cover the reported Label/wrapping production path.
Failure-Mode Probing
- Margined stretched Column child: finite width constraint becomes container minus margins, then cross-axis
wcan further clamp; measure and flex frame stay consistent. - Row grow with
WidthRequest: main-axiswis not used for clamping, so grow can still expand beyond basis. - Row shrink with horizontal margins: margin tightening now bounds width even when the main-axis
wclamp is intentionally skipped. - Images: existing Image special case still resets constraints to infinity after the new tightening.
- Infinite constraints: positive infinity is preserved; zero measure-hack conversion remains unchanged.
- Arrange-only pass: unchanged; no new measure occurs outside measure mode.
Verdict: NEEDS_DISCUSSION
Confidence: low
Summary: The code is targeted and I found no blocking correctness issue. However, required CI could not be verified and public status is still pending, so this cannot be LGTM under the skill rules.
🛠️ Fix — Analysis & Comparison
Fix Candidates
| # | Source | Approach | Test Result | Files Changed | Notes |
|---|---|---|---|---|---|
| 1 | try-fix | Move margin subtraction into FlexExtensions.GetConstraints() so all self-sizing callers get margin-aware constraints. |
✅ PASS | FlexExtensions.cs |
Passes targeted tests, but broadens helper semantics and affects legacy FlexLayout callers; not demonstrably better than PR. |
| 2 | try-fix | Keep callback-local margin tightening and allow main-axis callback clamping only when grow/shrink cannot later change that axis. | ✅ PASS | FlexLayout.cs |
Passes targeted tests, but more complex than PR and relies on grow/shrink stability assumptions. |
| PR | PR #36416 | Tighten finite FlexLayout child measure constraints by margins, then clamp only known cross-axis callback dimensions. | ✅ PASSED (Gate) | FlexLayout.cs, FlexLayoutTests.cs |
Original PR; gate already verified fail-without-fix/pass-with-fix. Narrowest passing fix. |
Cross-Pollination
| Model | Round | New Ideas? | Details |
|---|---|---|---|
| gpt-5.5 | 1 | Yes | Helper-level margin-aware constraints; tested as Candidate 1 and passed, but blast radius is broader. |
| gpt-5.5 | 1 | Yes | Flex-aware main-axis clamp for non-flexing items; tested as Candidate 2 and passed, but complexity/risk is higher. |
| maui-expert-reviewer | 2 | No | Only remaining distinct approach would be a broader two-pass Flex engine remeasure/relayout. It is not preferable because it adds a second measure/layout pass in a hot path and increases oscillation risk. |
Exhausted: Yes
Selected Fix: PR #36416 — It passes the gate and targeted regression tests while remaining more localized and easier to reason about than both passing alternatives. Candidate 1 is broader; Candidate 2 is more complex; the expert reviewer rejected a third engine-level approach as higher-risk.
🏁 Report — Final Recommendation
Comparative Candidate Report — PR #36416
Candidate ranking
| Rank | Candidate | Regression result | Assessment |
|---|---|---|---|
| 1 | pr-plus-reviewer |
✅ Passed gate by inheritance from PR; adds reviewer-requested coverage hardening | Best balance. Keeps the narrow PR implementation that passed the gate, avoids broader helper semantics, and incorporates the expert reviewer's actionable feedback by covering the handler-backed margin path. |
| 2 | pr |
✅ Gate passed | Narrowest submitted code fix and easier to reason about than the try-fix alternatives, but expert review found the tests do not exercise the normal handler-backed ComputeDesiredSize margin path. |
| 3 | try-fix-1 |
✅ PASS | Moves margin subtraction into FlexExtensions.GetConstraints(). This passed targeted tests but broadens helper semantics to every caller, including legacy/shared FlexLayout paths, without clear evidence that broader behavior is needed. |
| 4 | try-fix-2 |
✅ PASS | Keeps the fix localized but introduces flex-aware main-axis clamping for non-growing/non-shrinking items. It passed targeted tests, but the additional grow/shrink/basis assumptions are more complex and not necessary for the reported issue. |
No candidate from STEP 5a was recorded as failing regression tests, so the mandatory failed-test demotion rule does not change the ranking. If a future handler-backed regression proves the expert reviewer's double-margin concern as a functional failure in the submitted implementation, pr and both margin-subtracting try-fix candidates should be re-ranked below any candidate that passes that production-path test.
Key comparison points
Correctness: pr and pr-plus-reviewer directly target the observed mismatch between measure constraints and final FlexLayout frame size. try-fix-1 solves the same mismatch at a helper level, increasing blast radius. try-fix-2 tries to improve main-axis tightness but depends on interpreting flex stability from Grow == 0 && Shrink == 0, which is riskier around basis/wrap behavior.
Test quality: The submitted PR tests cover the gate and important grow/shrink edge cases, but expert review correctly identified that the new constraint-recording test doubles bypass the usual handler-backed ComputeDesiredSize path. pr-plus-reviewer wins because it includes the same fix plus the missing production-path coverage.
Maintainability / blast radius: The PR-track implementation is localized to FlexLayout.SelfSizing. try-fix-1 changes shared helper semantics; try-fix-2 adds more conditional behavior in a hot layout path. The localized PR approach is preferable unless handler-backed coverage proves a code change is required.
Winner
Winning candidate: pr-plus-reviewer
pr-plus-reviewer preserves the narrow gate-passing PR fix while incorporating the expert reviewer's actionable feedback through handler-backed regression coverage. It is lower risk than both try-fix alternatives and stronger than the raw PR because it closes the test representativeness gap called out by expert review.
🧭 Next Steps — review latest findings
No alternative fix was selected for this run. Review the session findings and CI results before merging.
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
This comment has been minimized.
This comment has been minimized.
Tests Failure Analysis
Test Failure Review: Not ready - click to expandOverall verdict: Not ready 9 failures are deterministic regressions (green on the most recent base build, red on this PR), including 3 WinUI Shell navigation tests ( Coverage: 162 checks · 150 passing · 12 failing · 0 pending · 0 inaccessible · 1 unmapped · 22 unexplained build legs · 0 unaccounted failing checks · 2 aborted failing checks · 0 canceled-build checks · 0 device-test unverified · 36 unattributed · 9 regressed-vs-base. Deterministic ceiling: Not ready — 9 legs regressed vs base; 36 unattributed failures; 22 unexplained build legs; 2 aborted failing checks; 1 unmapped failing check.
Recommended actionInvestigate the 3 WinUI Shell navigation tests ( Evidence detailsPR scope: 2 files changed (1 test file); area: Layout (FlexLayout). No platform labels set. Head: 906d852. maui-pr build: 1500294 (failed, 16 failed timeline records). Base build: 1499266 (succeeded — 0 baseline failures; matching failures here are not pre-existing on maui-pr). maui-pr-uitests build: 1500295 (failed, 30 failed timeline records). Base build: 1499834 (failed — 12 baseline failures; only the first 8 of 34 failed logs were inspected, so the baseline list may be incomplete). maui-pr-devicetests build: 1500296 (succeeded). All 7 Helix jobs confirmed 0 failed work items: Android CoreCLR (890c279a), iOS Mono x2 (9c33317d, d572d2a2), Android Mono (413272b5), MacCatalyst Mono x2 (4af3d850, fadf889f), Windows (cc64ac52). WinUI Shell regressions detail: ci-scan demotions (30 total): 22 Editor tests demoted by ci-scan #35958 (recurring/leg, Android API-30); 5 Shell/NavEvents tests demoted by #36419 (recurring, macOS); JDK provision demoted by #36196 (build-break/leg); Android SDK provision / LayoutShouldBeCorrectOnFirstNavigation demoted by #36381. Aborted checks: macOS UITests Controls CollectionView and macOS UITests Controls Shell were CANCELLED; their logs should be reviewed to determine whether cancellation was infrastructure-driven or caused by a PR-related hang. Unmapped check: Build Analysis has no accessible AzDO build; its details URL links to general Arcade documentation. AzDO auth: Not authenticated; no test-run-level data available. Baseline for maui-pr-uitests is partial (8 of 34 failed logs inspected); baseline list may be incomplete. |
FlexLayout's SelfSizing callback measured items using GetConstraints(), which returns the flex container's full size and ignores the item's own margins. The flex engine then arranges the item at the stretched cross-axis size (container minus margins), which is narrower. Wrapping content (e.g. Label text with LineBreakMode=WordWrap) wraps against a width the item never receives, and since the arrange pass never re-measures, the overflow line is cut off. The engine already passes the correct available size into the callback (the ref w/h parameters); clamp the measure constraints with those values when they are known. Fixes #27520 Manual testing: See the test file I added in 27520. I have manually tested over 100 repetitions of re-clicking the button to generate new labels and not been able to reproduce the isssue. Previously, around 1 in every 5 re-draws would reproduce the issue. ---------
Tests Failure Analysis
Test Failure Review: Not ready - click to expandOverall verdict: Not ready — but read the regressions with a grain of salt. Base sampling correctly targeted this PR's own base branch,
Coverage: 163 checks · 151 passing · 12 failing · 0 pending · 1 unmapped · 23 unexplained build legs · 2 aborted · 0 device-test unverified · 44 unattributed · 4 regressed-vs-base. Deterministic ceiling: Not ready — 4 legs regressed vs base. Builds (this PR): maui-pr 1500294 · maui-pr-uitests 1500295 · maui-pr-devicetests 1500296 (succeeded). Base sampling ( Scope: community ✨ · FlexLayout. Base branch: inflight/current. Recommended actionConfirm the 4 regressed-vs-base failure(s) flagged above are resolved before merging; the remaining failures reproduce on the base branch and are not caused by this PR. |
FlexLayout's SelfSizing callback measured items using GetConstraints(), which returns the flex container's full size and ignores the item's own margins. The flex engine then arranges the item at the stretched cross-axis size (container minus margins), which is narrower. Wrapping content (e.g. Label text with LineBreakMode=WordWrap) wraps against a width the item never receives, and since the arrange pass never re-measures, the overflow line is cut off. The engine already passes the correct available size into the callback (the ref w/h parameters); clamp the measure constraints with those values when they are known. Fixes #27520 Manual testing: See the test file I added in 27520. I have manually tested over 100 repetitions of re-clicking the button to generate new labels and not been able to reproduce the isssue. Previously, around 1 in every 5 re-draws would reproduce the issue. ---------
FlexLayout's SelfSizing callback measured items using GetConstraints(), which returns the flex container's full size and ignores the item's own margins. The flex engine then arranges the item at the stretched cross-axis size (container minus margins), which is narrower. Wrapping content (e.g. Label text with LineBreakMode=WordWrap) wraps against a width the item never receives, and since the arrange pass never re-measures, the overflow line is cut off. The engine already passes the correct available size into the callback (the ref w/h parameters); clamp the measure constraints with those values when they are known. Fixes #27520 Manual testing: See the test file I added in 27520. I have manually tested over 100 repetitions of re-clicking the button to generate new labels and not been able to reproduce the isssue. Previously, around 1 in every 5 re-draws would reproduce the issue. ---------
FlexLayout's SelfSizing callback measured items using GetConstraints(), which returns the flex container's full size and ignores the item's own margins. The flex engine then arranges the item at the stretched cross-axis size (container minus margins), which is narrower. Wrapping content (e.g. Label text with LineBreakMode=WordWrap) wraps against a width the item never receives, and since the arrange pass never re-measures, the overflow line is cut off. The engine already passes the correct available size into the callback (the ref w/h parameters); clamp the measure constraints with those values when they are known. Fixes #27520 Manual testing: See the test file I added in 27520. I have manually tested over 100 repetitions of re-clicking the button to generate new labels and not been able to reproduce the isssue. Previously, around 1 in every 5 re-draws would reproduce the issue. ---------
FlexLayout's SelfSizing callback measured items using GetConstraints(), which returns the flex container's full size and ignores the item's own margins. The flex engine then arranges the item at the stretched cross-axis size (container minus margins), which is narrower. Wrapping content (e.g. Label text with LineBreakMode=WordWrap) wraps against a width the item never receives, and since the arrange pass never re-measures, the overflow line is cut off. The engine already passes the correct available size into the callback (the ref w/h parameters); clamp the measure constraints with those values when they are known. Fixes #27520 Manual testing: See the test file I added in 27520. I have manually tested over 100 repetitions of re-clicking the button to generate new labels and not been able to reproduce the isssue. Previously, around 1 in every 5 re-draws would reproduce the issue. ---------
FlexLayout's SelfSizing callback measured items using GetConstraints(), which returns the flex container's full size and ignores the item's own margins. The flex engine then arranges the item at the stretched cross-axis size (container minus margins), which is narrower. Wrapping content (e.g. Label text with LineBreakMode=WordWrap) wraps against a width the item never receives, and since the arrange pass never re-measures, the overflow line is cut off. The engine already passes the correct available size into the callback (the ref w/h parameters); clamp the measure constraints with those values when they are known. Fixes #27520 Manual testing: See the test file I added in 27520. I have manually tested over 100 repetitions of re-clicking the button to generate new labels and not been able to reproduce the isssue. Previously, around 1 in every 5 re-draws would reproduce the issue. ---------
FlexLayout's SelfSizing callback measured items using GetConstraints(), which returns the flex container's full size and ignores the item's own margins. The flex engine then arranges the item at the stretched cross-axis size (container minus margins), which is narrower. Wrapping content (e.g. Label text with LineBreakMode=WordWrap) wraps against a width the item never receives, and since the arrange pass never re-measures, the overflow line is cut off.
The engine already passes the correct available size into the callback (the ref w/h parameters); clamp the measure constraints with those values when they are known.
Fixes #27520
Manual testing: See the test file I added in 27520. I have manually tested over 100 repetitions of re-clicking the button to generate new labels and not been able to reproduce the isssue. Previously, around 1 in every 5 re-draws would reproduce the issue.