Repository navigation
fix(layout): measure non-stretch children at the width they receive - #162
Merged
Merged
Conversation
In a column, recomputeTextWrapping measured a non-stretch auto-width child at its unclamped intrinsic width while Phase 5 laid it out at min(intrinsic, available). When the container was narrower than the child, wrapping forced by the clamp went unmeasured and the child was allocated too little height, so its content overflowed into the sibling below. Measure at the clamped width instead, and apply the same clamp in Element.HeightForWidth's column branch so nested measurement matches. Fixes #130
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #162 +/- ##
==========================================
+ Coverage 84.49% 84.55% +0.05%
==========================================
Files 169 169
Lines 21535 21543 +8
==========================================
+ Hits 18197 18215 +18
+ Misses 2669 2660 -9
+ Partials 669 668 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Contributor
|
Replace the HeightForWidth pin test with the nested percent-width row scenario, which fails against main's element_layout.go and against measuring at full width in flex.go. Assert the width the engine hook is measured at in calculate_colwrap_test.go.
…pping One IntrinsicSize call per child instead of two for non-stretch column children (table intrinsic size recomputes column widths). Note the multi-line wrapped column limitation in the comment.
This was referenced Sep 16, 2026
computeBorderBox clamps a column child's slot with MinWidth and MaxWidth, but both wrap measurement sites measured at the unclamped slot, so the allocated height was wrong whenever the constraint changed wrapping. Share the clamp through layout.ClampWidth and apply it in recomputeTextWrapping and the column branch of Element.HeightForWidth. Fixes #164
The column branch of Element.HeightForWidth measured every child at the full content width and summed bare heights, while layout subtracts the horizontal margin before measuring and adds the vertical margin to the main size. Subtract the horizontal margin before the stretch and clamp branches and add the vertical margin to the total so a nested column reports the height layout will give its children. Fixes #165
Owner
Author
|
@greptileai please review again |
The flat column in TestColumnChildMeasuredAtMinMaxWidth only reached recomputeTextWrapping, so removing ClampWidth from Element.HeightForWidth left the root suite green. The table now nests the child in an auto-height column so every min/max case checks inner.HeightForWidth against the engine's layout, failing at either site when the clamp is dropped. The HeightForWidth comments around the width computation were merged into a single two-line comment.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When a column container is narrower than a non-stretch auto-width child (items-start, self-start, self-center and so on), the alignment phase clamps the child's width to the available space, but the text wrapping pass was still measuring it at its unclamped intrinsic width. Any wrapping the clamp forces went unmeasured, so the child was allocated its unwrapped height and its content spilled into the sibling below. A table with intrinsic width 32 inside a flex-col items-start w-20 container is the concrete case from the issue: the cells wrapped to two rows while the table kept one, and the next element rendered on top of the second row.
recomputeTextWrapping now measures non-stretch auto-width children at min(intrinsic, available), the same width they receive in the alignment phase. Element.HeightForWidth's column branch applies the same clamp so a nested container reports a matching height. Stretch children and explicitly sized children are unchanged, and a container wider than the child still lays it out at its intrinsic width.
Two related gaps in the same functions are fixed here as well. computeBorderBox clamps a column child's slot with MinWidth and MaxWidth, but both wrap measurement sites measured at the unclamped slot, so a max width that forced extra wrapping left the child short of rows and a min width above the slot gave it extra rows. The clamp is now shared through layout.ClampWidth and applied at both sites. The column branch of Element.HeightForWidth also measured each child at the full content width and summed bare heights, ignoring margins the engine already accounts for, so a nested column reported less height than layout gave its children. It now subtracts the horizontal margin before measuring and adds the vertical margin to the total.
Fixes #130
Fixes #164
Fixes #165