Skip to content

alternates metadata are not correctly merged #74361

@axeleroy

Description

@axeleroy

Link to the code that reproduces this issue

https://github.com/axeleroy/nextjs-alternates-repro

To Reproduce

  1. Start the dev server
  2. Navigate to http://localhost:3000
  3. Inspect the page. The alternates are
<link rel="alternate" hrefLang="en-US" href="https://nextjs.org/en-US"/>
<link rel="alternate" hrefLang="de-DE" href="https://nextjs.org/de-DE"/>
  1. Navigate to http://localhost:3000/sub-page-1
  2. Inspect the page. The alternates are
<link rel="alternate" type="application/rss+xml" href="https://example.tld/feed.xml"/>
  1. Navigate to http://localhost:3000/sub-page-1
  2. Inspect the page. The alternates are
<link rel="canonical" href="https://example.tld/sub-page-2"/>

Current vs. Expected behavior

  1. Start the dev server
  2. Navigate to http://localhost:3000
  3. Inspect the page. The alternates should be
<link rel="alternate" type="application/rss+xml" href="https://example.tld/feed.xml"/>
<link rel="alternate" hrefLang="en-US" href="https://nextjs.org/en-US"/>
<link rel="alternate" hrefLang="de-DE" href="https://nextjs.org/de-DE"/>

instead of

<link rel="alternate" hrefLang="en-US" href="https://nextjs.org/en-US"/>
<link rel="alternate" hrefLang="de-DE" href="https://nextjs.org/de-DE"/>
  1. Navigate to http://localhost:3000/sub-page-1
  2. Inspect the page. The alternates are
<link rel="alternate" type="application/rss+xml" href="https://example.tld/feed.xml"/>
  1. Navigate to http://localhost:3000/sub-page-1
  2. Inspect the page. The alternates should be
<link rel="alternate" type="application/rss+xml" href="https://example.tld/feed.xml"/>
<link rel="canonical" href="https://example.tld/sub-page-2"/>

instead of

<link rel="canonical" href="https://example.tld/sub-page-2"/>

Provide environment information

Operating System:
  Platform: linux
  Arch: x64
  Version: #51-Ubuntu SMP PREEMPT_DYNAMIC Sat Nov  9 17:58:29 UTC 2024
  Available memory (MB): 7680
  Available CPU cores: 8
Binaries:
  Node: 20.12.2
  npm: 10.5.0
  Yarn: 1.9.4
  pnpm: 8.15.4
Relevant Packages:
  next: 15.1.3 // Latest available version is detected (15.1.3).
  eslint-config-next: N/A
  react: 19.0.0
  react-dom: 19.0.0
  typescript: 5.7.2
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

Metadata

Which stage(s) are affected? (Select all that apply)

next dev (local), next build (local), next start (local), Vercel (Deployed), Other (Deployed)

Additional context

In addition to the stages mentioned above, I have also noted that the issue happens regardless of whether Turbo is used or not and on Static HTML exports.

Metadata

Metadata

Assignees

No one assigned

    Labels

    MetadataRelated to Next.js' Metadata API.

    Type

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions