Repository navigation
fix(layout): absorb a margin collapsing through to an isolated box's own edge - #441
Merged
Merged
Conversation
…own edge layoutIsolated (table cells, flex/grid items) and placeFloat both start a fresh block formatting context, where CSS 2.1's own collapsing rule stops. A descendant's leading or trailing margin that collapsed through to that edge had nowhere left to go but was discarded instead of landing in the box's own height. Found on news.ycombinator.com: .votearrow's margin box (3px top + 10px + 6px bottom = 19px) inside a table cell rendered as 10px. Confirmed via a live Chromium comparison of the real markup and CSS. Co-Authored-By: Claude Sonnet 5 <[email protected]>
Co-Authored-By: Claude Sonnet 5 <[email protected]>
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.
Summary
Fixes a margin that collapses through to the edge of an isolated layout (a table cell, a float) being silently discarded instead of landing inside that box's own height.
Closes #440.
layoutIsolated(layout/flex.go, used for table cells, flex/grid items, and replaced-element sizing) andplaceFloat(layout/floats.go) both start a fresh block formatting context, because the node they lay out establishes its own (CSS 2.1 §8.3.1/§9.4.1). A descendant's margin that collapses through to either edge of that isolated layout has nowhere further to go.Confirmed real trigger: news.ycombinator.com's own vote-arrow icon,
.votearrow{width:10px;height:10px;margin:3px 2px 6px}inside a table cell's<center><a>wrapper. Margin box = 3+10+6 = 19px. A live Chromium comparison of the real page and real stylesheet (installed Playwright's bundled Chrome for Testing for this, since this environment had none) confirms the real row height is 19px; this engine rendered it at 10px. This was the unresolved root cause behind FIDELITY.md's own "HN's title row is ~3px shorter than Chrome's" gap (round 149), which had correctly guessed the vote-arrow cell as the likely source but never isolated why.place()already folds an absorbed top margin into the box's ownY(firstContentTop) — correct for an ordinary nested block sharing its parent's own BFC, but wrong for the outermost isolated box, which has no real parent position to shift into. Now folded into height instead, withYpinned to the isolated origin.place()defers it into the BFC's own pendingcarry, materialized only byfb.commit()— both call sites discarded that commit's result. Now extends the box's height.Y: ordinary inline content (no block children) can also leaveYnon-zero for an unrelated, benign reason (line-box ascent/leading), and folding that into height too would double-count it — caught live during testing (a plain<span>1.</span>cell was inflated), fixed, and covered by a regression test.fakeMeasurertest-harness line-height discrepancy, confirmed identical with or without this fix — out of scope here). FIDELITY.md's own Known-gaps bullet is updated to say so honestly.Test plan
layout/isolatedmargin_test.go: the table-cell case (exact 19px), the float case (same mechanism, mirrored), and the inline-content regression guard.go build/go vet/gofmt -l/go test ./.../govulncheck ./...clean.layoutpackage coverage 100.0% (the floor).webengine_nojs webengine_nonet webengine_fontsextbuild-tag lane builds and vets clean.🤖 Generated with Claude Code