Skip to content

fix(layout): apply position:relative/sticky offset to atomic inline-level items - #459

Open
tannevaled wants to merge 3 commits into
mainfrom
worktree-agent-a78ab238dc46f4541
Open

tannevaled wants to merge 3 commits into
mainfrom
worktree-agent-a78ab238dc46f4541

Conversation

@tannevaled

Copy link
Copy Markdown
Contributor

Summary

Two go-slides reports against engine v0.17.0, triaged at current HEAD:

  • Defect D: an <img> with position:relative;top/left is not shifted.
  • Defect C: a ::before/::after pseudo-element — two separate reported
    symptoms:
    • position:absolute pseudo-element "not drawn at all" — already
      correct at HEAD
      , not touched; pinned with a new regression test
      (TestAbsolutePseudoElementIsPlacedNotDropped) so it stays caught if it
      ever regresses.
    • display:inline-block;position:relative;left pseudo-element — ignored,
      same root cause as defect D.

Both still-broken halves turned out to share one root cause: placeLine
computes every InlineItem's X/Y purely from line-box flow geometry and
never consults Style.Position at all. That leaves out any atomic
inline-level item — an <img>/form control (opaque Image/FormControl,
never a layout.Box) or a display:inline-block/inline-flex element's
NestedBox (reachable only through its InlineItem, never through
box.Children) — so position:relative/sticky on any of those was
silently ignored. A block-level element with the same rule already worked,
since applyRelative's box.Children walk reaches it directly.

Fix

layout/position.go: split applyRelative into applyRelativeChildren
(the original box.Children walk, now also walking box.Lines' atomic
items and recursing into a NestedBox's own descendants) and a new
applyLineItemRelative, which applies an atomic inline item's own
relative/sticky offset and keeps NestedBox.X/Y in sync with the
InlineItem's it.X/it.Y, per the existing invariant translateBox keeps
for 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 the
same offset" rule — which this engine's per-line decor-fragment model does
not yet resolve.

Tests

  • TestRelativeOffsetAppliesToReplacedInlineElement — defect D (<img>).
  • TestRelativeOffsetAppliesToInlineBlockElement — the plain-element half
    of defect C's inline-block case.
  • TestRelativeOffsetAppliesToInlineBlockPseudoElement — the actual
    reported pseudo-element half of defect C.
  • TestAbsolutePseudoElementIsPlacedNotDropped — pins that the other
    reported half of defect C is already correct at HEAD.
  • TestApplyLineItemRelativeSkipsPlainTextItem /
    TestApplyLineItemRelativeNilStyleIsNoop — unit tests for
    applyLineItemRelative's own guard conditions, added to satisfy
    mutsweep.

mutsweep note

mutsweep flagged two refusals in the new applyLineItemRelative
(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 the
identical guard as its own first statement, and adding a literal 0 to
it.X/it.Y is an exact IEEE 754 identity regardless, so no input could
ever 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

tannevaled and others added 3 commits November 29, 2026 18:45
…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant