Skip to content

fix(unhead): dedupe <link rel="alternate"> - #655

Merged
harlan-zw merged 3 commits into
mainfrom
fix/alternate
Feb 6, 2026
Merged

harlan-zw merged 3 commits into
mainfrom
fix/alternate

Conversation

@danielroe

@danielroe danielroe commented Feb 5, 2026 •

Copy link
Copy Markdown
Member

🔗 Linked issue

resolves nuxt/nuxt#32670
closes nuxt/nuxt#34150

❓ Type of change

  • 📖 Documentation (updates to the documentation or readme)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • 👌 Enhancement (improving an existing functionality)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

📚 Description

previously rel=alternate links were not deduped and on hydration would be duplicated

@danielroe
danielroe requested a review from harlan-zw February 5, 2026 20:09
Co-authored-by: onmax <[email protected]>
@github-actions

github-actions Bot commented Feb 5, 2026 •

Copy link
Copy Markdown
Contributor

Bundle Size Analysis

Bundle Size Gzipped
Client (Minimal) 11.2 kB → 11.3 kB 🔴 +0.1 kB 4.7 kB
Server (Minimal) 10.1 kB → 10.2 kB 🔴 +0.1 kB 4.2 kB
Vue Client (Minimal) 12.2 kB → 12.3 kB 🔴 +0.1 kB 5.1 kB
Vue Server (Minimal) 10.9 kB → 11 kB 🔴 +0.1 kB 4.6 kB

@harlan-zw

Copy link
Copy Markdown
Collaborator

Great stuff, thanks :)

@harlan-zw
harlan-zw merged commit fdabe65 into main Feb 6, 2026
5 checks passed
return 'canonical'

if (name === 'link' && props.rel === 'alternate') {
return `alternate:${props.hreflang || props.type || 'x-default'}:${props.href || ''}`

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understand correctly, with this change alternate links are only deduplicated if their href are identical, but prevents deduplication based on key or id.

Is there a specific reason for including the href in the dedupe key?

Suggested change
return `alternate:${props.hreflang || props.type || 'x-default'}:${props.href || ''}`
return `alternate:${props.hreflang || props.type || 'x-default'}`

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was just meant to dedupe for hydration purposes

does a custom key not work?

@harlan-zw harlan-zw Feb 8, 2026 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh ye probably don't need href, any exactinsights for what we need @BobbieGoede 🙏 mindful of breaking any i18n features

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change breaks functionality in i18n for localized dynamic parameters, these translations are fetched/updated at a later point:

<link id="i18n-alt-nl" rel="alternate" href="http://localhost:3000/nl/products/big-chair" hreflang="nl">
<link id="i18n-alt-nl" rel="alternate" href="http://localhost:3000/nl/products/grote-stoel" hreflang="nl">

I was using id to ensure deduplication which is broken now, but I think removing href from the dedupe key should allow for deduplication without it (not only deduplicating duplicate urls).

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@danielroe your change prevents the key and id logic from being reached below, so it breaks custom keys: 38815ec#diff-bdce5db600ceed2c1bafdfa8fbc98c0e3f948c2db00fe2b0bac0611a54d856bbR53-R59

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe just move it below custom key logic?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think moving it below would work, but I also think removing href from the key makes sense, at least for alternate links with a hreflang.

@harlan-zw harlan-zw Feb 8, 2026 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return alternate:${props.hreflang || props.type || 'x-default'} this looks good to me and can land a release for it if it works for you @BobbieGoede

@BobbieGoede BobbieGoede Feb 8, 2026 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that works for nuxt-i18n, just ran the tests locally with that change @harlan-zw

@danielroe danielroe Feb 8, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my apologies for this!

😢

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.

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

3 participants