Commit ef584a8
fix(css): emit the base reset for tags evicted from the defaultStyle cache
generateDedupedBaseCSS built the per-tag base reset by reading cache.defaultStyle
directly. That cache is an EvictingMap capped at MAX_DEFAULT_STYLE (30), and the
reset is generated at the very end of a capture — so any document using more than
30 distinct tags had its earliest-registered tags already evicted. The lookup
returned undefined and `continue` silently emitted no reset rule for them.
The base reset is what neutralizes the UA stylesheet inside the foreignObject.
Without it those tags fall back to UA defaults, so properties the page had reset
to the CSS initial value (and which are therefore diffed out of the element's
generated class) reappear: h1..h3/p margins, hr borders, list padding. The capture
then reflows taller than the source, shifting every later section down.
Which tags are affected depends on registration order, so the corruption is silent
and varies from page to page. Observed on a real site: 39 distinct tags, and the
tags at first-appearance ranks 15-23 (picture, main, h1, h2, h3, strong, p, hr)
all lost their reset while h4 at rank 25 survived. Four <h3>s regained the UA
1em margin-block-start, growing the article by 121px and pushing a button 171px
down over the section below it.
Resolve through getDefaultStyleForTag instead: it is memoized, idempotent, and
re-derives an evicted entry on demand. NO_DEFAULTS_TAGS still yields {} and is
dropped by the existing empty-key guard, so SVG/head tags are unaffected.
Tests cover both the end-to-end path (a >30-tag capture keeps h3 in the reset)
and the unit invariant (every used tag with defaults appears in the output, even
from a cleared cache). Both fail without the fix.
Note for reviewers: the fillers in the end-to-end test must have distinct UA
styling. Tags that compute identically (aside/section/nav/header/…) collide on
the style-key memo in styles.js, never call getDefaultStyleForTag, and so never
occupy a cache slot — with those the capture registers only 28 tags, stays under
the cap and the bug does not trigger.
Closes #468
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>1 parent 3d95744 commit ef584a8
2 files changed
Lines changed: 87 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
277 | 277 | | |
278 | 278 | | |
279 | 279 | | |
280 | | - | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
281 | 289 | | |
282 | 290 | | |
283 | 291 | | |
| |||
0 commit comments