Skip to content

--computed: read an auto margin as auto, not the px it resolved to - #81

Merged
tmashara merged 1 commit into
mainfrom
claude/issue-75-computed-margin
Oct 29, 2026
Merged

tmashara merged 1 commit into
mainfrom
claude/issue-75-computed-margin

Conversation

@tmashara

@tmashara tmashara commented Oct 29, 2026 •

Copy link
Copy Markdown
Owner

What

probe() in src/locate.ts now records a margin whose computed value (computedStyleMap()) is auto as auto, instead of the px getComputedStyle resolved it to. One helper, used by both the --computed walk and pixel mode's dom lines. Every other value reads exactly as before, so margin-left 24px→16px still reads the same. An accepted entry whose dom named an auto margin's px (e.g. .container margin-left 60px→0px) no longer matches, since elements is part of the fingerprint: that change is now gone or reads auto→…, so re-accept it if it still shows. No other accepted entry changes.

Why

getComputedStyle returns the used value for an auto margin, and that depends on the layout path Chrome takes: a centred block reads the centring px, a grid item with the same margin: 0 auto reads 0px while sitting in the same place. That is the .container margin-left 60px → 0px noise in #75. The computed value is auto by spec regardless of layout, so the noise is removed at the read.

Now:

  • auto on both sides: no finding.
  • auto → 60px (centring replaced with a fixed margin): margin-left auto→60px, a real CSS change, reported truthfully.
  • An auto margin whose used value changes because the container narrowed: no margin finding; the width change that caused it is.

Why not the issue's "drop the margin change when the box is unchanged" rule

  • It would hide real changes: a real margin-bottom moves only the next sibling (or the parent, or collapses through to the parent's sibling), a margin-right on an inline/flex item moves only the next sibling, a margin-left under justify-content: flex-end moves only the previous siblings. The element's own box stays put in all of these, so a correct rule has to watch own box + siblings + parent + parent's siblings.
  • It would still be noisy: rects are absolute, so any height change above the element moves it and its siblings, which is exactly the CSS-change run the issue is about.
  • It costs a rect per snapshot entry, rounding and scroll caveats, a Snapshot shape change and a memoized walk in collapseInherited. The auto read is one helper in one file.

If you specifically want the "used position" variant the issue mentions as an alternative, say so; this addresses the cause it works around.

Ceilings: without computedStyleMap (non-Chromium) values read as px, as today. Pseudo-elements keep getComputedStyle (no computedStyleMap for them). An over-constrained margin-right that's reported but ignored still shows; separate ticket if it comes up.

How tested

New visual test in tests/visual/computed.test.ts: same margin: 0 auto element in block vs grid layout. Before the fix it reported margin-right 590px→0px and margin-left 590px→0px; with it, no margin finding and the snapshot reads auto. Control in the same test: margin: 0 60px on the right reports auto→60px. typecheck, lint, format:check, npm test (305 pass) and npm run test:visual (335 pass) all green. Docs: docs/output.md and skills/renderdiff/reference.md.

Fixes #75

🤖 Generated with Claude Code

The resolved px of an auto margin depends on the layout path (a grid
item's reads 0px, a centred block's the centring px), so it showed up
as margin-left 60px→0px noise on CSS-only changes.

Fixes #75

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@tmashara
tmashara merged commit 3713d54 into main Oct 29, 2026
3 checks passed
@tmashara
tmashara deleted the claude/issue-75-computed-margin branch October 29, 2026 17:52
@tmashara tmashara mentioned this pull request Oct 29, 2026
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.

--computed: drop margin changes when the box is unchanged

1 participant