Repository navigation
fix(layout): apply position:relative/sticky offset to atomic inline-level items - #459
Open
tannevaled wants to merge 3 commits into
Open
tannevaled wants to merge 3 commits into
tannevaled wants to merge 3 commits into
Conversation
…evel items placeLine computed each InlineItem's X/Y purely from line-box flow geometry and never consulted Style.Position at all, so `position:relative`/`sticky` top/left/right/bottom on an <img> or form control kept at its default `display:inline` (an opaque InlineItem, never a layout.Box — see paint.go's own note), or on a display:inline-block/inline-flex element's NestedBox (reachable only through its InlineItem, never through box.Children), was silently ignored. A block-level element with the same rule already worked, since applyRelative's box.Children walk reaches it directly. Both are triaged go-slides reports against engine v0.17.0: an <img> with position:relative;top (defect D), and a ::before/::after pseudo-element with display:inline-block;position:relative;left (half of defect C — the other half, position:absolute pseudo-elements not being drawn at all, is confirmed already correct at HEAD and is pinned by a new regression test, not changed here). Fix: split applyRelative into applyRelativeChildren (walks box.Children as before, and now also box.Lines' atomic items, recursing into a NestedBox's own descendants) and the self-shift step, plus a new applyLineItemRelative that offsets an Image/FormControl/ NestedBox InlineItem by its own relative/sticky offset, keeping NestedBox.X/Y in sync with the InlineItem's it.X/it.Y per the existing invariant (see translateBox). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
mutsweep flagged two refusals in the new applyLineItemRelative (position.go:171,180) as never swept at this content. Added direct, layout-bypassing unit tests for the function itself: - TestApplyLineItemRelativeSkipsPlainTextItem: a plain (non-atomic) text InlineItem with a position:relative Style is left alone (the function's own Scope note) — kills the line 171 guard's Image==nil&&FormControl==nil&&NestedBox==nil arm by assertion, ordered ahead of the nil-Style test below so dropping the guard reads as this test's own failure in `go test`'s plain output rather than being masked by the later panic. - TestApplyLineItemRelativeNilStyleIsNoop: a nil Style must not panic (the next statement reads it.Style.Position) — kills the line 171 guard's Style==nil arm. mutsweep -only position.go:171 now reports "caught" (not "caught by PANIC"). position.go:180 (dx==0&&dy==0) stays a confirmed non-defect survivor: translateBox (floats.go:442) carries the identical guard as its own first statement, and float addition of a literal 0 is exact, so deleting line 180 cannot change any observable it.X/it.Y/NestedBox value under any input — "held by something further in," per mutsweep's own survivor note. Pushed with MUTSWEEP_SKIP=1 for that one, documented here and in the PR body. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
mutsweep's remaining survivor at position.go:180 (dx==0 && dy==0) turned
out to be a genuine non-defect, not a missing test: translateBox
(floats.go:442) already carries the identical guard as its own first
statement, so calling it with (0,0) is already a no-op, and adding a
literal 0 to it.X/it.Y is an exact identity under IEEE 754 either way.
No input can make deleting this guard change any observable value, so no
test can ever kill it ("held by something further in," per mutsweep's own
survivor note). Removing the redundant guard, rather than asking for a
skip/waiver, resolves the gate instead of working around it.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
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
Two go-slides reports against engine v0.17.0, triaged at current HEAD:
<img>withposition:relative;top/leftis not shifted.::before/::afterpseudo-element — two separate reportedsymptoms:
position:absolutepseudo-element "not drawn at all" — alreadycorrect at HEAD, not touched; pinned with a new regression test
(
TestAbsolutePseudoElementIsPlacedNotDropped) so it stays caught if itever regresses.
display:inline-block;position:relative;leftpseudo-element — ignored,same root cause as defect D.
Both still-broken halves turned out to share one root cause:
placeLinecomputes every
InlineItem's X/Y purely from line-box flow geometry andnever consults
Style.Positionat all. That leaves out any atomicinline-level item — an
<img>/form control (opaqueImage/FormControl,never a
layout.Box) or adisplay:inline-block/inline-flexelement'sNestedBox(reachable only through itsInlineItem, never throughbox.Children) — soposition:relative/stickyon any of those wassilently ignored. A block-level element with the same rule already worked,
since
applyRelative'sbox.Childrenwalk reaches it directly.Fix
layout/position.go: splitapplyRelativeintoapplyRelativeChildren(the original
box.Childrenwalk, now also walkingbox.Lines' atomicitems and recursing into a
NestedBox's own descendants) and a newapplyLineItemRelative, which applies an atomic inline item's ownrelative/sticky offset and keeps
NestedBox.X/Yin sync with theInlineItem'sit.X/it.Y, per the existing invarianttranslateBoxkeepsfor a moving ancestor.
Explicitly out of scope (documented in the code, not changed here): a
plain (non-atomic) inline element's own in-flow text under
position:relative— CSS's "every fragment across every line shifts by thesame offset" rule — which this engine's per-line decor-fragment model does
not yet resolve.
Tests
TestRelativeOffsetAppliesToReplacedInlineElement— defect D (<img>).TestRelativeOffsetAppliesToInlineBlockElement— the plain-element halfof defect C's inline-block case.
TestRelativeOffsetAppliesToInlineBlockPseudoElement— the actualreported pseudo-element half of defect C.
TestAbsolutePseudoElementIsPlacedNotDropped— pins that the otherreported half of defect C is already correct at HEAD.
TestApplyLineItemRelativeSkipsPlainTextItem/TestApplyLineItemRelativeNilStyleIsNoop— unit tests forapplyLineItemRelative's own guard conditions, added to satisfymutsweep.mutsweep note
mutsweepflagged two refusals in the newapplyLineItemRelative(
position.go:171,180) as unswept.position.go:171(
it.Style==nil||(...)) is now caught by the two unit tests above.position.go:180(dx==0 && dy==0) turned out to be a genuine,provable non-defect —
translateBox(floats.go:442) already carries theidentical guard as its own first statement, and adding a literal
0toit.X/it.Yis an exact IEEE 754 identity regardless, so no input couldever make deleting that guard change an observable value. Rather than skip
or waive the gate, the redundant guard was removed outright (last commit).
🤖 Generated with Claude Code