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

[languageAlternates] hreflang rendered with wrong case (hrefLang)

Open AntoineKM opened this issue 3 years ago • 5 comments

Reopening this issue: #656

<link rel="alternate" hrefLang="fr" href="https://example.com/fr" />

Should be:

<link rel="alternate" hreflang="fr" href="https://example.com/fr" />

AntoineKM avatar Feb 28 '22 12:02 AntoineKM

@AntoineKM Can you provide a complete information on how to reproduce the current challenge?

nyedidikeke avatar Mar 06 '22 19:03 nyedidikeke

@AntoineKM Can you provide a complete information on how to reproduce the current challenge?

sure

this is what i've done:

const Head: React.FC = () => {
  const { locales, asPath } = useRouter();

  const languageAlternates =
    locales &&
    locales.map((locale) => ({
      hrefLang: locale,
      href: `${APP.URL}/${locale}${asPath}`,
    }));

  return <NextSeo languageAlternates={languageAlternates} />;
};

AntoineKM avatar Mar 06 '22 19:03 AntoineKM

Some news ?

AntoineKM avatar Mar 21 '22 13:03 AntoineKM

On #656 @garmeeh wrote:

Hey @romaincointepas can you provide an recreation of this? Just checking here and for me it renders correctly.

The best way to reproduce is by view raw output of cURL as some browsers (e.g. Chrome) will internally apply a fix by lowercasing the attribute. Even passing the out output of cURL through tidy will do this.

Here's an example that shows the attribute present with incorrect case:

curl -s 'https://www.yourbusinessnumber.com/' | grep -oi 'hreflang'

Seems to be an upstream issue with React since the JSX <link> tag only accepts hrefLang as attribute, which is what next-seo is using.

rnbrady avatar Mar 27 '23 13:03 rnbrady

Confirmed this is an upstream issue facebook/react #12403.

Their view is that HTML is not case sensitive so there's no reason to lowercase the attribute names.

rnbrady avatar Mar 27 '23 14:03 rnbrady