nextjs - ✅(Solved) Fix Alternates media in multiple generated sitemap [1 pull requests, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
vercel/next.js#85103Fetched 2026-04-08 02:17:27
View on GitHub
Comments
0
Participants
1
Timeline
3
Reactions
4
Author
Participants
Timeline (top)
cross-referenced ×1issue_type_added ×1labeled ×1

Fix Action

Fixed

PR fix notes

PR #85104: Update resolveSitemap for generated sitemap

Description (problem / solution / changelog)

What?

  • Update the function resolveSitemap to includes alternates media
  • Fixes #85103

How?

  • Add the media to metadata types
  • Add loop for each alternates media
  • Add tests to check correct generation of the sitemap

Changed files

  • packages/next/src/build/webpack/loaders/metadata/resolve-route-data.test.ts (modified, +6/-0)
  • packages/next/src/build/webpack/loaders/metadata/resolve-route-data.ts (modified, +12/-1)
  • packages/next/src/lib/metadata/types/metadata-interface.ts (modified, +3/-0)

Code Example

<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml">
<url>
<loc>https://example.com/pathname/1</loc>
<xhtml:link rel="alternate" media="only screen and (max-width: 640px)" href="https://m.example.com/pathname/1" />
</url>
</urlset>

---

<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml">
<url>
<loc>https://example.com/pathname/1</loc>
</url>
</urlset>

---

Operating System:
  Platform: linux
  Arch: x64
  Version: #1 SMP PREEMPT_DYNAMIC Sun Aug  6 20:05:33 UTC 2023
  Available memory (MB): 4102
  Available CPU cores: 2
Binaries:
  Node: 20.9.0
  npm: 9.8.1
  Yarn: 1.22.19
  pnpm: 8.10.2
Relevant Packages:
  next: 16.0.0-canary.15 // Latest available version is detected (16.0.0-canary.15).
  eslint-config-next: N/A
  react: 19.2.0
  react-dom: 19.2.0
  typescript: 5.3.3
Next.js Config:
  output: N/A
RAW_BUFFERClick to expand / collapse

Link to the code that reproduces this issue

https://codesandbox.io/p/devbox/practical-raman-plx3jf

To Reproduce

  1. Start the app (next dev)
  2. Go to /pathname/sitemap/0.xml
  3. See that we don't have the tag alternate for media

Current vs. Expected behavior

Expected xml

<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml">
<url>
<loc>https://example.com/pathname/1</loc>
<xhtml:link rel="alternate" media="only screen and (max-width: 640px)" href="https://m.example.com/pathname/1" />
</url>
</urlset>

Actual xml

<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml">
<url>
<loc>https://example.com/pathname/1</loc>
</url>
</urlset>

Provide environment information

Operating System:
  Platform: linux
  Arch: x64
  Version: #1 SMP PREEMPT_DYNAMIC Sun Aug  6 20:05:33 UTC 2023
  Available memory (MB): 4102
  Available CPU cores: 2
Binaries:
  Node: 20.9.0
  npm: 9.8.1
  Yarn: 1.22.19
  pnpm: 8.10.2
Relevant Packages:
  next: 16.0.0-canary.15 // Latest available version is detected (16.0.0-canary.15).
  eslint-config-next: N/A
  react: 19.2.0
  react-dom: 19.2.0
  typescript: 5.3.3
Next.js Config:
  output: N/A

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

Webpack

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

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

Additional context

No response

extent analysis

TL;DR

The missing xhtml:link tag with rel="alternate" attribute in the sitemap XML is likely due to a configuration or code issue in the Next.js application, and can be fixed by modifying the code that generates the sitemap.

Guidance

  • Review the code that generates the sitemap XML to ensure it includes the necessary xhtml:link tag with rel="alternate" attribute.
  • Check the Next.js configuration and code for any overrides or customizations that may be affecting the sitemap generation.
  • Verify that the xmlns:xhtml namespace is correctly defined in the sitemap XML to allow for the xhtml:link tag.
  • Inspect the network requests and responses in the browser's developer tools to see if the sitemap XML is being generated and returned correctly.

Example

No code snippet can be provided without more information about the specific code that generates the sitemap XML.

Notes

The issue may be related to a specific configuration or code change in the Next.js application, and more information about the code and configuration would be needed to provide a more specific solution.

Recommendation

Apply workaround: Modify the code that generates the sitemap XML to include the necessary xhtml:link tag with rel="alternate" attribute, as the exact cause of the issue is unclear and may require further investigation.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING