Skip to content

fix(layout): measure non-stretch children at the width they receive - #162

Merged
grindlemire merged 6 commits into
mainfrom
fix/nonstretch-wrap-measure
Sep 16, 2026
Merged

grindlemire merged 6 commits into
mainfrom
fix/nonstretch-wrap-measure

Conversation

@grindlemire

@grindlemire grindlemire commented Sep 16, 2026 •

Copy link
Copy Markdown
Owner

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

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

codecov Bot commented Sep 16, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 84.55%. Comparing base (64e001a) to head (53ae676).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@greptile-apps

greptile-apps Bot commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

The PR appears safe to merge; the follow-up changes address the outstanding constraint and margin inconsistencies without establishing a new regression.

Summary

This PR aligns width-dependent height measurement with the widths ultimately assigned during column layout.

  • Measures non-stretch auto-width children at the available-width clamp used during alignment.
  • Applies minimum and maximum width constraints consistently during wrapping measurement and final layout.
  • Accounts for horizontal and vertical child margins in recursive column height measurement.
  • Adds focused regression coverage for wrapping, constraints, margins, nested columns, and sibling placement.
Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart LR
    A[Column content width] --> B[Subtract horizontal margins]
    B --> C[Resolve stretch, auto, or explicit width]
    C --> D[Apply min/max width constraints]
    D --> E[Measure HeightForWidth]
    E --> F[Allocate wrapped height]
    F --> G[Add vertical margins and gap]
    G --> H[Position following sibling]
Loading

Reviews (2) · Last reviewed commit: "fix(layout): account for child margins i..."

Comment thread internal/layout/flex.go Resolved
Comment thread internal/layout/flex.go Resolved
Comment thread element_layout.go Resolved
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.
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
@grindlemire

Copy link
Copy Markdown
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.
@grindlemire
grindlemire merged commit 118a647 into main Sep 16, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant