next-sitemap icon indicating copy to clipboard operation
next-sitemap copied to clipboard

Sitemap fails when adding alternate refs.

Open jimmi-rbn opened this issue 3 years ago • 1 comments

Describe the bug When adding alternate refs the sitemap returns "broken" and with an error message in console saying: Uncaught TypeError: Cannot read properties of null (reading 'childNodes')

To Reproduce Install as documentation stated and add `const fields = [ { loc: "/additional-page-2", changefreq: "yearly", priority: 0.7, lastmod: new Date().toISOString(),

  // acts only on '/additional-page-2'
  alternateRefs: [
    {
      href: "https://es.example.com",
      hreflang: "es",
    },
    {
      href: "https://fr.example.com",
      hreflang: "fr",
    },
  ],
},

];`

Expected behavior Show sitemap with alternate refs (xhtml:link ref="alternate") IT seems like the xmlns props is wrong. See https://shop.change.com/sitemap.xml for a working version.

With alternate refs: image

Without alternate refs: image

Additional context "next": "^12.2.5", "next-sitemap": "^3.1.21",

jimmi-rbn avatar Aug 31 '22 14:08 jimmi-rbn

I am suspecting a bug from the browser. Similar to that: https://stackoverflow.com/questions/60564479/sitemap-xml-with-xhtmllink-rel-alternate-hreflang-href-for-multilang

I tried on my end and I have the exact same thing as you. Using a chrome extension to view XML was able to display correctly formated XML though

rsylvian avatar Sep 02 '22 00:09 rsylvian

I am facing a similar issue with the pretty print of xml files in the browser. here https://bugs.chromium.org/p/chromium/issues/detail?id=580033 it says that:

"the alternate ref declaration puts the parsers to the XHTML mode and handles the document as an XHTML document. The rendering results makes sense if browsers parsed the document as an XHTML."

even though it is not a major problem, any suggestions for a temporary work around.

varadan13 avatar Sep 27 '22 06:09 varadan13

According to this thread https://stackoverflow.com/questions/45274063/xml-format-in-browsers-when-added-xhtml if change xmlns:* links from http to https everything works fine. I tried modifying the sitemap.xml file and it works as expected. However, I couldn't find a way to modify sitemap files from configs. Any suggestions?

olehkhalin avatar Oct 17 '22 11:10 olehkhalin

@olehkhalin Thanks for pointing this out. Fixed: #509

iamvishnusankar avatar Oct 17 '22 13:10 iamvishnusankar

Cool, thanks 👍

olehkhalin avatar Oct 17 '22 13:10 olehkhalin

@iamvishnusankar for some reason this fix is not included in the most recent (for the current moment) release v3.1.32

Serhii-the-Dev avatar Nov 26 '22 21:11 Serhii-the-Dev

Same as @Serhii-the-Dev mentioned. The fix works in v3.1.29, but fail again after v3.1.30

Kamigami55 avatar Dec 13 '22 06:12 Kamigami55

Hi @Kamigami55 I applied the schema manually (by replacing it with a regex inside a generated XML body), however it turned out it was an incorrect approach: Google Search Console is labeling such a sitemap as one containing invalid namespaces. So despite it's not rendering visually correct in a browser, I did a rollback to http schema in order to make it work with SEO tools. The bottom line is: correct namespace for the sitemap file should use http schema as defined in the protocol.

Serhii-the-Dev avatar Dec 13 '22 10:12 Serhii-the-Dev

@iamvishnusankar Also failing for me after version 3.1.30

pinktonio avatar May 09 '23 05:05 pinktonio