Repository navigation
fix: render the ids inside svg icons the same way on every request - #593
Conversation
Iconify renames ids with a counter shared by every server render, so an unchanged page rendered different HTML on each request. NuxtIconSvg now prefixes them with useId(), which also matches between server and client. Closes #585 Amp-Thread-ID: https://ampcode.com/threads/T-01a219e0-f941-74ac-b1e4-c4a4cd886bc9
commit: |
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
…onSvg> The direct path renamed ids with Iconify's replaceIDs, whose counter is shared by every server render, which brought back nuxt#585 for icons already in memory. It now uses the useId-prefixed replaceIDs from nuxt#593. Amp-Thread-ID: https://ampcode.com/threads/T-01a219e0-f941-74ac-b1e4-c4a4cd886bc9
In svg mode, the ids inside an icon (gradients, clip paths, masks) come from a counter that Iconify keeps at module level and never resets. On the server, every request moves it forward, so an unchanged page renders different HTML each time:
fill6/fill7, thenfill8/fill9on the next request. That defeats ETags and ISR, where Vercel only skips a write when the output is identical. The first icon also keeps its raw id (fill), which can collide with ids already on the page.Closes #585
What changed
NuxtIconSvgnow renames the ids itself, in thecustomisecallback that Iconify runs before its ownreplaceIDs. Each instance usesuseId()as its prefix, so ids look likev_2ID0: unique per icon, the same on every request, and the same on the server and the client. Acustomizegiven to the icon still runs first.Evidence
The new test in
test/svg-mode.test.tsrenders a gradient icon twice in thesvg-modefixture and expects identical HTML, a different id for each icon, andurl(#…)pointing at its own gradient.main, it fails: the first response hasid="fill6"andid="fill7", the second hasid="fill8"andid="fill9".vue-tscare clean.I also checked these once and didn't commit the checks:
v_2ID0andv_3ID0, there were no console warnings, and a screenshot showed both gradients painted.href,xlink:href,url(#…), animationbegin="0;anim.end", ids containing dots, and an id that's a prefix of another (a,ab) all came out right, and repeated calls gave the same output.Details
idto Iconify, as SVG mode: ids inside icons come from a global counter, so the same page renders different HTML on every request #585 suggests: that worked in@iconify/vue5.0.0, whereidset the prefix. This repo is on^5.0.5. Since 5.0.4,replaceIDs(body)takes no prefix and<Icon>only copiesidonto the<svg>.id='…'(single quotes), so Iconify'sreplaceIDs, which only matchesid="…", leaves them alone. If Iconify ever changes that regex, it would rename them again: output goes back to today's request-dependent ids, but the SVGs keep working because references are renamed too.<NuxtIconSvg>and Iconify components #578: its direct render path callsreplaceIDs(body)from Iconify, so it would need to use this helper with auseId()prefix too.ELI5
Some icons label their parts so they can point at them, like "paint this circle with gradient #1". The server picked those labels from a counter that never reset, so every page load got new labels and looked like a new page. Now each icon gets labels from its position on the page, so the same page always comes out the same.