Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docs: Issue Next 14 generate a localized sitemap #66167

Closed
wh0sumit opened this issue May 24, 2024 · 6 comments
Closed

Docs: Issue Next 14 generate a localized sitemap #66167

wh0sumit opened this issue May 24, 2024 · 6 comments
Labels
Documentation Related to Next.js' official documentation. locked

Comments

@wh0sumit
Copy link

What is the update you wish to see?

I am experiencing an issue with the sitemap generation using the alternates key for localized URLs.

here is the link : https://nextjs.org/docs/app/api-reference/file-conventions/metadata/sitemap

Is there any context that might help us understand?

The generated XML does not reflect the expected format when alternates are included.

However, when I remove the alternates key, the sitemap is generated correctly.

To Reproduce

Steps to reproduce the behavior:

  • Use Next.js version ^14.2.3.
  • Implement the sitemap generation with alternates as shown in the documentation.

Here is the code used:

import { MetadataRoute } from 'next';

export default function sitemap(): MetadataRoute.Sitemap {
  return [
    {
      url: 'https://acme.com',
      lastModified: new Date(),
      alternates: {
        languages: {
          es: 'https://acme.com/es',
          de: 'https://acme.com/de',
        },
      },
    },
    {
      url: 'https://acme.com/about',
      lastModified: new Date(),
      alternates: {
        languages: {
          es: 'https://acme.com/es/about',
          de: 'https://acme.com/de/about',
        },
      },
    },
    {
      url: 'https://acme.com/blog',
      lastModified: new Date(),
      alternates: {
        languages: {
          es: 'https://acme.com/es/blog',
          de: 'https://acme.com/de/blog',
        },
      },
    },
  ];
}

Expected behavior

The generated XML sitemap should correctly reflect the alternate language URLs.

Actual behavior

The XML sitemap does not format the alternate language URLs as expected. Instead, it shows an incorrect structure.

Screenshots

With alternates (incorrect format):

image

Without alternates (correct format):

image

System information

OS: Windows
Browser: Chrome
Version of Next.js: 14.2.3
Version of Node.js: 21.7.1

Additional context :

I am unsure whether this is a bug in the implementation or a documentation issue. Please advise if there is an alternative way to achieve the correct sitemap structure with alternates or if this feature can be improved.

Does the docs page already exist? Please link to it.

https://nextjs.org/docs/app/api-reference/file-conventions/metadata/sitemap

@wh0sumit wh0sumit added the Documentation Related to Next.js' official documentation. label May 24, 2024
@wh0sumit wh0sumit changed the title Docs: Issue with alternates with Next 14 generate a localized sitemap Docs: Issue Next 14 generate a localized sitemap May 24, 2024
@Kirill-Ponomarenko
Copy link

Kirill-Ponomarenko commented May 24, 2024

Yeah, I have this to. Even copying exact example from docs gives this issue

I managed to track down it to the
https://github.com/vercel/next.js/blob/canary/packages/next/src/build/webpack/loaders/metadata/resolve-route-data.ts#L68

 content += `<xhtml:link rel="alternate" hreflang="${language}" href="${
          languages[language as keyof typeof languages]
        }" />\n`

If I remove :link part, website starts to serve xml file as is. But I guess it's invalid sitemap. And I don't understand what exactly breaks it. I followed data up to here
https://github.com/vercel/next.js/blob/canary/packages/next/src/build/webpack/loaders/next-metadata-route-loader.ts#L240
And it's fine. Have no idea what breaks it later

@GrahamQuan
Copy link

They also not update the version-history, where i18n + sitemap feature in the next@14.2.0 version.

I am using next@14.1.4 got TS type error and then update next to 14.2.3 but got wrong sitemap.xml output

https://nextjs.org/docs/app/api-reference/file-conventions/metadata/sitemap#version-history

@gabriel-logan
Copy link

I'm having same issue,

#66363

@gabriel-logan
Copy link

VI aqui que se voce acessar view-source:http://localhost:3000/sitemap.xml o site map na verdade esta sendo gerado corretamente, se tu olhahr tambem o network response, aparentemente esta sendo gerado corretamente, mas não tenho certeza.

Network
image

View Source
image

@huozhi
Copy link
Member

huozhi commented Jun 1, 2024

It needs to follow the spec of google international sitemap docs: https://developers.google.com/search/docs/specialty/international/localized-versions

The XML is valid for crawler to read and the content type is expected. It's only the view source panel is not correctly displaying that content properly. If you have other problems about crawler indexing the sitemap with errors, please let us know.

@huozhi huozhi closed this as completed Jun 1, 2024
Copy link
Contributor

This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 15, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Documentation Related to Next.js' official documentation. locked
Projects
None yet
Development

No branches or pull requests

5 participants