Skip to content

fix(nuxt): dedupe rel="alternate" link tags - #34150

Closed
onmax wants to merge 1 commit into
nuxt:mainfrom
onmax:fix/link-alternate-duplication
Closed

onmax wants to merge 1 commit into
nuxt:mainfrom
onmax:fix/link-alternate-duplication

Conversation

@onmax

@onmax onmax commented Jan 23, 2026 •

Copy link
Copy Markdown
Member

Fixes #32670

Problem

<Link rel="alternate"> duplicates in client HTML after hydration.

Solution

Auto-generate dedupe key for rel="alternate" links based on hreflang.

StackBlitz

Link Expected
Bug nuxt-32670 ❌ Duplicate link
Fix nuxt-32670-fixed ✅ Single link

What to check

  1. Open DevTools → Elements → <head>
  2. Search for link[rel="alternate"]
    • Bug: appears twice after hydration
    • Fixed: appears once
  3. link[rel="canonical"] should appear once in both (already working)

CLI Reproduction

git clone --depth 1 --filter=blob:none --sparse --branch repro/nuxt-32670 https://github.com/onmax/repros.git
cd repros && git sparse-checkout set nuxt-32670
cd nuxt-32670 && pnpm i && pnpm dev

@onmax
onmax requested a review from danielroe as a code owner January 23, 2026 20:31
@bolt-new-by-stackblitz

Copy link
Copy Markdown

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@github-actions github-actions Bot added 4.x 🐛 bug Something isn't working as expected labels Jan 23, 2026
@pkg-pr-new

pkg-pr-new Bot commented Jan 23, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@nuxt/kit

npm i https://pkg.pr.new/@nuxt/kit@34150

@nuxt/nitro-server

npm i https://pkg.pr.new/@nuxt/nitro-server@34150

nuxt

npm i https://pkg.pr.new/nuxt@34150

@nuxt/rspack-builder

npm i https://pkg.pr.new/@nuxt/rspack-builder@34150

@nuxt/schema

npm i https://pkg.pr.new/@nuxt/schema@34150

@nuxt/vite-builder

npm i https://pkg.pr.new/@nuxt/vite-builder@34150

@nuxt/webpack-builder

npm i https://pkg.pr.new/@nuxt/webpack-builder@34150

commit: 6d09983

@coderabbitai

coderabbitai Bot commented Jan 23, 2026 •

Copy link
Copy Markdown
Contributor

Walkthrough

The Link component in the Nuxt head runtime now captures the vnode key into a vnodeKey variable and computes a fallback deduplication key when rel="alternate" and no vnode key exists, synthesising it from hreflang (defaulting to x-default) and href. The computed key is passed to normalizeProps so alternate links can be deduplicated. A test that previously expected failure for duplicated alternate links was converted to a regular test.

Possibly related PRs

  • nuxt/nuxt PR 33963: Changes how per-node keys are derived and passed to normalizeProps in packages/nuxt/src/head/runtime/components.ts, directly touching the same key flow.
  • nuxt/nuxt PR 33958: Updates head-tag deduplication to use the component vnode key for link tags, including logic for alternate-link key synthesis.
  • nuxt/nuxt PR 32792: Addresses duplicated <link rel="alternate"> behavior and adds tests targeting the same duplication scenario.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: fixing deduplication of rel="alternate" link tags, which is the primary objective of this PR.
Description check ✅ Passed The description is well-related to the changeset, providing problem statement, solution approach, reproduction links, and testing instructions for the rel="alternate" deduplication fix.
Linked Issues check ✅ Passed The PR directly addresses issue #32670 by implementing auto-generated dedupe keys for rel="alternate" links based on hreflang, preventing client-side duplication after hydration.
Out of Scope Changes check ✅ Passed All changes are in-scope: the Link component modification implements the deduplication fix, and the test update validates the fix by converting a failing test to a passing one.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@codspeed

codspeed Bot commented Jan 23, 2026 •

Copy link
Copy Markdown

CodSpeed Performance Report

Merging this PR will improve performance by 11.43%

Comparing onmax:fix/link-alternate-duplication (6d09983) with main (825b2c2)

Summary

⚡ 1 improved benchmark
✅ 9 untouched benchmarks

Performance Changes

Benchmark BASE HEAD Efficiency
⚡ writeTypes in the basic-types fixture 93.8 ms 84.2 ms +11.43%

@onmax
onmax force-pushed the fix/link-alternate-duplication branch from c3b7c8d to 6d09983 Compare January 23, 2026 20:51
@danielroe

Copy link
Copy Markdown
Member

I believe this should be fixed upstream instead: unjs/unhead#655

@danielroe
danielroe marked this pull request as draft February 5, 2026 20:47
@harlan-zw

Copy link
Copy Markdown
Contributor

Thanks for your work on this @onmax, available in Unhead v2.1.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

4.x 🐛 bug Something isn't working as expected

Projects

None yet

Development

Successfully merging this pull request may close these issues.

<Link rel="alternate"> duplicated in the client-side HTML

3 participants