Open Barzi-Ahmed opened 3 months ago
@Barzi-Ahmed, the sitemap generation looks fine if you look at it in the network tab. The issue is not with NextJs sitemap generation it's with
I didn't understand. Please tell me how do I solve this issue.
I don't think there'a anything to fix? Are worried that the browser renders it like that?
Your file outputs:
<?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://acme.com</loc>
<xhtml:link rel="alternate" hreflang="es" href="https://acme.com/es" />
<xhtml:link rel="alternate" hreflang="de" href="https://acme.com/de" />
<lastmod>2024-07-22T12:44:55.131Z</lastmod>
</url>
<url>
<loc>https://acme.com/about</loc>
<xhtml:link rel="alternate" hreflang="es" href="https://acme.com/es/about" />
<xhtml:link rel="alternate" hreflang="de" href="https://acme.com/de/about" />
<lastmod>2024-07-22T12:44:55.131Z</lastmod>
</url>
<url>
<loc>https://acme.com/blog</loc>
<xhtml:link rel="alternate" hreflang="es" href="https://acme.com/es/blog" />
<xhtml:link rel="alternate" hreflang="de" href="https://acme.com/de/blog" />
<lastmod>2024-07-22T12:44:55.131Z</lastmod>
</url>
</urlset>
And I think that's fine... You can do:
new DOMParser().parseFromString(`<?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://acme.com</loc>
<xhtml:link rel="alternate" hreflang="es" href="https://acme.com/es" />
<xhtml:link rel="alternate" hreflang="de" href="https://acme.com/de" />
<lastmod>2024-07-22T12:44:55.131Z</lastmod>
</url>
<url>
<loc>https://acme.com/about</loc>
<xhtml:link rel="alternate" hreflang="es" href="https://acme.com/es/about" />
<xhtml:link rel="alternate" hreflang="de" href="https://acme.com/de/about" />
<lastmod>2024-07-22T12:44:55.131Z</lastmod>
</url>
<url>
<loc>https://acme.com/blog</loc>
<xhtml:link rel="alternate" hreflang="es" href="https://acme.com/es/blog" />
<xhtml:link rel="alternate" hreflang="de" href="https://acme.com/de/blog" />
<lastmod>2024-07-22T12:44:55.131Z</lastmod>
</url>
</urlset>
`, 'text/xml')
And it will parse it correctly. I think the issue is just that the styling Chrome is giving to the page, is a bit jarring.
This is because the Chrome stylesheet for some of your tags, has
display: none;
, but that's for humans, not robots
I think it is more appropriate to test your sitemap using cURL, or other means more similar to how it'd be consumed, not a browser...
Well as already noted, you dont really need the sitemap to 'render' nicely in a browser.
A browser is not the intended audience for a sitemap.
The sitemap is for consumption by a special bot. It readsy the XML directly, it doesnt care about trying to render it. The sitemap works. You need to go to your sitemap at localhost:3000/sitemap.xml, right-click to save the page, and open it in a text editor. Alternatively, you can check it in your browser’s console.
I have the same issue, yes I agree that the page source is correct, but I've checked sitemap (download sitemap.xml and upload) via sitemap checker and it's not valid.
I have the same issue, yes I agree that the page source is correct, but I've checked sitemap (download sitemap.xml and upload) via sitemap checker and it's not valid.
What is that checker raising as issue(s)?
Well as already noted, you dont really need the sitemap to 'render' nicely in a browser.
A browser is not the intended audience for a sitemap.
The sitemap is for consumption by a special bot. It readsy the XML directly, it doesnt care about trying to render it. The sitemap works. You need to go to your sitemap at localhost:3000/sitemap.xml, right-click to save the page, and open it in a text editor. Alternatively, you can check it in your browser’s console.
You are correct, thank you for the explanation.
Link to the code that reproduces this issue
https://github.com/Barzi-Ahmed/my-app
To Reproduce
STORY: When creating sitemap.ts and using this same code from docs, this is the result I get:
I have searched through GitHub issues and found https://github.com/vercel/next.js/issues/63764, and there it is mentioned that you should use Next 14.2, but I already use the latest version of Next.js (details below), and this means it is still not fixed.
Current vs. Expected behavior
Obviously the mentioned sitemap sample doesn't render correctly at all as a normal XML page.
Provide environment information
Which area(s) are affected? (Select all that apply)
Internationalization (i18n)
Which stage(s) are affected? (Select all that apply)
next dev (local), next build (local), next start (local), Vercel (Deployed), Other (Deployed)
Additional context
I use Chrome Version 126.0.6478.127 (Official Build) (64-bit)