Block/Flexbox/Grid: floor content width and child stretch/available sizes at zero - #1178
Merged
Merged
Conversation
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
Base automatically changed from
devin/1788439473-grid-skip-unaffected-contributions
to
main
September 3, 2026 14:22
…h at zero A block container whose padding/border exceeds its width, or a child whose horizontal margins exceed the container's content width, previously produced negative content/stretch widths that were passed down as known dimensions and available space (and to measure functions). Browsers floor these at zero.
…n margins exceed the container Stretched flex items whose cross-axis margins exceeded the line were given a negative used cross size, and flex/grid items were measured with negative known dimensions / available space. Blink clamps every child constraint at zero (CalculateChildAvailableSize, stretch = max(border+padding, available - margins)); do the same here. Adds a Chrome-generated flex fixture (items end up 0 wide, matching Chrome) and a hand-written test asserting that block/flex/grid leaves never receive negative layout inputs.
nicoburns
force-pushed
the
devin/1788440338-block-clamp-negative-widths
branch
from
September 3, 2026 14:22
51bcfcd to
50d5d2d
Compare
nicoburns
enabled auto-merge (squash)
September 3, 2026 14:22
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.
Objective
Stacked on #1177. Several places computed "container (or grid area / flex line) size minus insets/margins" and passed the result on unfloored, so when padding/border or a child's margins exceed the container, children received negative
known_dimensions/available_space/ percentage bases — and in the flexbox case a negative used size.Block (
perform_final_layout_on_in_flow_children):All floored at zero (
.max(0.0)), including the float-avoidingslot.stretch_width.max(min_auto_width)case.Flexbox: the container's inner available space (
determine_available_space), the cross-axis stretch size handed to items as a known dimension (determine_flex_base_size, the intrinsic-main-size pass),main_stretch_size,cross_stretch_size, and the final stretched cross size indetermine_used_cross_size(line_cross_size - margins) are floored at zero. The last one is user-visible: a stretched item in a column container whose horizontal margins exceed the container width ended up withwidth = -20in the final layout (Chrome:0).Grid:
grid_area_size - marginsinGridItem::available_space/keyword sizing and inalign_and_position_itemfloored at zero (only measure-function inputs were affected; final item sizes were already floored).This matches Blink, which never hands a child a negative constraint:
CalculateChildAvailableSize→ShrinkLogicalSize(..).ClampNegativeToZero(), stretch resolves tomax(border+padding, available − margins), fit-content to(available − margins).ClampNegativeToZero(), andResolveInlineLengthDCHECK_GE(available_size, 0).Tests:
block_margin_x_exceeds_container_width,block_padding_exceeds_container_width,flex_column_stretch_margin_x_exceeds_container_width(childrenwidth="0"at the margin/padding edge; all fail onmain, pass here).tests/hand_written/negative_available_space.rs: block / flex-column / grid containers with a margin-overflowing leaf; asserts the leaf's measure function never sees a negative known dimension or definite available space and that the leaf is 0 wide (all three fail onmain).Context
Follow-up from the investigation in #1177 (negative inline widths were observed inside the discarded min-content pass that #1177 removes, but the arithmetic is wrong regardless). Downstream, DioxusLabs/blitz#835 additionally clamps Blitz's own margin/inset subtraction in inline layout; that covers a different subtraction (Blitz's, after
known_dimensions/node_sizeoverride the available space) so both are kept.I could not construct a grid fixture where Chrome and Taffy disagree on final layout (grid already floors item sizes; a %/
1fr/wrapping grandchild under a 0-wide item resolves the same from −20 and 0), so the grid change is covered by the hand-written measure-input test only.Link to Devin session: https://dioxus.staging.devinenterprise.com/sessions/3a0b8cc210c041d8955c841fb2a76a8e
Open in Devin Desktop: https://dioxus.staging.devinenterprise.com/desktop/session/3a0b8cc210c041d8955c841fb2a76a8e?variant=devin-insiders
Requested by: @nicoburns