Skip to content

fix: render the ids inside svg icons the same way on every request - #593

Merged
atinux merged 2 commits into
mainfrom
fix/deterministic-svg-ids
Nov 27, 2026
Merged

atinux merged 2 commits into
mainfrom
fix/deterministic-svg-ids

Conversation

@atinux

@atinux atinux commented Nov 26, 2026

Copy link
Copy Markdown
Member

Written by an AI agent on behalf of @atinux.

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, then fill8/fill9 on 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

NuxtIconSvg now renames the ids itself, in the customise callback that Iconify runs before its own replaceIDs. Each instance uses useId() as its prefix, so ids look like v_2ID0: unique per icon, the same on every request, and the same on the server and the client. A customize given to the icon still runs first.

Evidence

The new test in test/svg-mode.test.ts renders a gradient icon twice in the svg-mode fixture and expects identical HTML, a different id for each icon, and url(#…) pointing at its own gradient.

  • On main, it fails: the first response has id="fill6" and id="fill7", the second has id="fill8" and id="fill9".
  • On this branch, it passes. All 136 tests pass, and lint and vue-tsc are clean.

I also checked these once and didn't commit the checks:

  • Hydration: in a temporary browser test, the SSR and client DOM both had v_2ID0 and v_3ID0, there were no console warnings, and a screenshot showed both gradients painted.
  • Edge cases: I ran the rename with Iconify 5.0.5's own pass after it. href, xlink:href, url(#…), animation begin="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

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.

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
@pkg-pr-new

pkg-pr-new Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
npm i https://pkg.pr.new/@nuxt/icon@593

commit: fd9769e

@coderabbitai

coderabbitai Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

SVG mode now uses Vue’s useId to create an ID prefix and rewrites IDs and matching references in customised SVG bodies. The SVG-mode fixture adds two custom gradient icons. Tests check that repeated requests return identical HTML and that each icon references its own gradient ID.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Severity of issue fixed: Medium

Merge Risk: Minimal · up to fd976 · assessed changes only

Path filters excluded changed files. This rating applies only to the assessed changes.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: SVG IDs inside icons are rendered the same way on every request. It matches the raw summary, which describes a stable, prefixed ID rename in NuxtIconSvg, and the objec…
Description check Passed The description explains the problem (a module-level counter in Iconify causes request-dependent IDs that defeat ETags and ISR), the change (renaming IDs in the customise callback with useId() as pref…
Linked Issues check Passed [#585] requires request-independent SVG ids in SVG mode, with server and client ids that match. The change adds replaceIDs(body, prefix) in src/runtime/components/svg.ts. NuxtIconSvg uses Vue `u…
Out of Scope Changes check Passed All visible changes support stable SVG ids in SVG mode. The changes are: the replaceIDs helper and its use in NuxtIconSvg (src/runtime/components/svg.ts); two custom:gradient icon instances in…
Full details: Title check

Explanation

The title names the main change: SVG IDs inside icons are rendered the same way on every request. It matches the raw summary, which describes a stable, prefixed ID rename in NuxtIconSvg, and the objectives, which target deterministic IDs across requests. The title does not cover the server/client consistency or the new helper, but that detail is not required.

Full details: Description check

Explanation

The description explains the problem (a module-level counter in Iconify causes request-dependent IDs that defeat ETags and ISR), the change (renaming IDs in the customise callback with useId() as prefix), test evidence, and trade-offs. It matches the raw summary and objectives closely.

Full details: Linked Issues check

Explanation

[#585] requires request-independent SVG ids in SVG mode, with server and client ids that match. The change adds replaceIDs(body, prefix) in src/runtime/components/svg.ts. NuxtIconSvg uses Vue useId() as the prefix and renames ids in the customise callback before Iconify's own replaceIDs. The resulting ids depend on component position, not on a module-level counter. This meets the objective. The issue's suggested id prop does not apply to the repository's ^5.0.5 Iconify version, so a different route is acceptable. The test in test/svg-mode.test.ts checks identical HTML across two requests, distinct ids per icon, and correct url(#…) references. This covers the automated-test requirement. I did not run the test. The fixture test/fixtures/svg-mode/icons/gradient.svg is excluded from review (rule !**/*.svg), so the fixture content is unverified. The implementation and assertions are reviewable and support compliance. Hydration checks are uncommitted and are not counted as evidence. The single-quoted id output relies on Iconify's double-quote-only regex. This is a fragility, not a current unmet requirement.

Full details: Out of Scope Changes check

Explanation

All visible changes support stable SVG ids in SVG mode. The changes are: the replaceIDs helper and its use in NuxtIconSvg (src/runtime/components/svg.ts); two custom:gradient icon instances in the fixture template (test/fixtures/svg-mode/app.vue); a custom collection in the fixture config (test/svg-mode/nuxt.config.ts); and the test assertions (test/svg-mode.test.ts). Fixture and test changes exist to exercise the new behaviour, so they count as supporting changes. The excluded gradient.svg file is test input only. No unrelated change appears in the summary. The verdict relies on the whole-PR summary, not a full diff read.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 38e3b338-b980-4ca7-834f-ccbb499ffb9a
Commits

Reviewing files that changed from the base of the PR and between 653d7cd and fd9769e.

Files ignored due to path filters: 1

  • test/fixtures/svg-mode/icons/gradient.svg is excluded by !**/*.svg
Files selected for processing: 1

  • test/svg-mode.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

@atinux
atinux merged commit 3891655 into main Nov 27, 2026
5 checks passed
@atinux
atinux deleted the fix/deterministic-svg-ids branch November 27, 2026 10:16
@github-actions github-actions Bot mentioned this pull request Nov 27, 2026
atinux added a commit to brunobelloni/icon that referenced this pull request Nov 27, 2026
…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
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.

SVG mode: ids inside icons come from a global counter, so the same page renders different HTML on every request

1 participant