next.js icon indicating copy to clipboard operation
next.js copied to clipboard

Next js 13 moves all meta tags to the head tag including schema markup meta tags

Open mjad218 opened this issue 3 years ago • 2 comments

Verify canary release

  • [X] I verified that the issue exists in the latest Next.js canary release

Provide environment information

    Operating System: 
      Platform: win32 
      Arch: x64       
      Version: Windows 10 Home
    Binaries:
      Node: 18.12.1   
      npm: N/A        
      Yarn: N/A       
      pnpm: N/A       
    Relevant packages:
      next: 13.0.2    
      eslint-config-next: 13.0.2
      react: 18.2.0   
      react-dom: 18.2.0

What browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

No response

Describe the Bug

I have schema markup on my application https://schema.org/.

I place some meta tags inside the header for example to let search engines understand the page better.

<meta itemProp="accessibilityControl" content="fullMouseControl"/>
<meta itemProp="accessibilityHazard" content="noFlashingHazard" />
<meta itemProp="accessibilityHazard" content="noMotionSimulationHazard"/>
<meta itemProp="accessibilityHazard" content="noSoundHazard" />
<meta itemProp="accessibilityAPI" content="ARIA" />

Currently, I see these tags moved inside the head tag.

They should remain at their current position in the DOM tree.

Expected Behavior

Next js 13 should keep certain meta tags at their current position in the DOM tree.

Link to reproduction

N/A

To Reproduce

Just create a new next 13 app and place some meta tags inside the body or any other element.

mjad218 avatar Nov 08 '22 20:11 mjad218

Looks similar to https://github.com/vercel/next.js/issues/42268

SergeySypalo avatar Nov 11 '22 08:11 SergeySypalo

@balazsorban44 Can you please address this issue?

It causes a lot of errors in my Google Search Console. (SEO Related Errors).

mjad218 avatar Nov 18 '22 13:11 mjad218

I'm experiencing this issue as well with Next 13.1.1 using the experimental app dir.

bpossolo avatar Jan 13 '23 04:01 bpossolo

Just updated to NextJS 13.1.2, the same issue.

SergeySypalo avatar Jan 13 '23 09:01 SergeySypalo

We're experiencing this issue on 13.1.5 with pages/ (not app/)

klarstrup avatar Jan 26 '23 21:01 klarstrup

That's strange, I just double-checked the site running on 13.1.5, and I don't have this issue with /pages dir, only with /app (I have a new/test version of a website locally, waiting for this bug to be fixed, and checking on every new build, but so far no luck.

SergeySypalo avatar Jan 26 '23 22:01 SergeySypalo

Just update to 13.1.6 - the same issue in the /app dir, in /pages - all good.

SergeySypalo avatar Jan 28 '23 08:01 SergeySypalo

Another clue for this happening with /pages too (still in 13.1.6) is that we are using suspense in that universe (via @tanstack/query)

klarstrup avatar Feb 07 '23 13:02 klarstrup

Found an interesting thing today, then decided to try from newly create NextJS 13.2.1 from scratch and use /app directory npx create-next-app@latest --experimental-app Then copied <div itemscope itemtype="https://schema.org/NewsArticle"> with its contents from https://developers.google.com/search/docs/appearance/structured-data/article And it worked as expected 😀 When I compared what was is the difference between this project and a test one I have, the dealbreaker was itemProp in my test site vs itemprop in Google example, same applies to other item... Schema.org metadata. I remember VSCode previously suggested me to change from all lowercase to 1 uppercase letter, otherwise highlighted a page as containing errors. Going to move my devops blog to a newer version finally 🙂

SergeySypalo avatar Feb 25 '23 08:02 SergeySypalo

@SergeySypalo i was trying to get the attribute/meta tag based microdata to work but eventually dumped it for the json+ld style syntax. It works much better, Google recommends it and you can encapsulate all the microdata into a single easy to read component. I highly recommend it instead.

bpossolo avatar Feb 25 '23 09:02 bpossolo

Yeah, I know that, and it works just fine for some simple metadata, like data published, author, etc. But if I want to create a how-to guide, I would technically need to duplicate all steps from the article to the metadata.

SergeySypalo avatar Feb 25 '23 13:02 SergeySypalo

Updated today to 13.2.2 and it's broken again, reverted to 13.2.1 and metatags rendered as expected within the body.

SergeySypalo avatar Mar 01 '23 07:03 SergeySypalo

Turns out my problem, which I think is in fact separate from this one, was caused in my project by using react@next (18.3.0-next-0f4a83596-20230110 to be precise). Returning to [email protected] has restored sanity to my project.

Repro for my actual bug: npx create-next-app@latest and npm install react@next react-dom@next, now any <meta> tags that were supposed to render within <div id="__next"> will render before it, right into <body>.

klarstrup avatar Mar 03 '23 13:03 klarstrup

Turns out this was the erroneous behavior I was happening upon: https://github.com/facebook/react/pull/26256

klarstrup avatar Mar 05 '23 00:03 klarstrup

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

github-actions[bot] avatar Apr 07 '23 12:04 github-actions[bot]