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

[NEXT-666] Nested Open Graph metadata overwrites root metadata #46434

Closed
1 task done
vxna opened this issue Feb 26, 2023 · 5 comments
Closed
1 task done

[NEXT-666] Nested Open Graph metadata overwrites root metadata #46434

vxna opened this issue Feb 26, 2023 · 5 comments
Assignees
Labels
Metadata Related to Next.js' Metadata API.

Comments

@vxna
Copy link

vxna commented Feb 26, 2023

Verify canary release

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

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 22.3.0: Mon Jan 30 20:38:37 PST 2023; root:xnu-8792.81.3~2/RELEASE_ARM64_T6000
Binaries:
  Node: 16.19.1
  npm: 8.19.3
  Yarn: 1.22.19
  pnpm: 7.28.0
Relevant packages:
  next: 13.2.2-canary.1
  eslint-config-next: N/A
  react: 18.2.0
  react-dom: 18.2.0

Which area(s) of Next.js are affected? (leave empty if unsure)

Metadata (metadata, generateMetadata, next/head, head.js)

Link to the code that reproduces this issue

https://github.com/vxna/next-nested-metadata-merge-repro

To Reproduce

Navigate the index and nested page back and forth and check meta tags in devtools:

CleanShot.2023-02-26.at.10.37.58.mp4

Describe the Bug

Existing Open Graph metadata keys from the root layout aren't getting merged, but completely overwritten with the nested page metadata. That leads into the unused (at the nested page level) keys like type, siteName or url are just gone.

https://github.com/vxna/next-nested-metadata-merge-repro/blob/main/app/layout.tsx#L32-L45
https://github.com/vxna/next-nested-metadata-merge-repro/blob/main/app/nested/page.tsx#L18-L27

Expected Behavior

Objects are merged together to form the final metadata output. Duplicate keys are replaced based on their ordering.

https://beta.nextjs.org/docs/api-reference/metadata#ordering

Which browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

No response

NEXT-666

@vxna vxna added the bug Issue was opened via the bug report template. label Feb 26, 2023
@huozhi huozhi self-assigned this Feb 27, 2023
@huozhi huozhi added Metadata Related to Next.js' Metadata API. and removed bug Issue was opened via the bug report template. labels Feb 27, 2023
@timneutkens timneutkens added the linear: next Confirmed issue that is tracked by the Next.js team. label Feb 27, 2023
@timneutkens timneutkens changed the title Nested Open Graph metadata overwrites root metadata [NEXT-666] Nested Open Graph metadata overwrites root metadata Feb 27, 2023
@pf1gura
Copy link

pf1gura commented Feb 27, 2023

Same thing happens for robots, keys are overridden instead of deep merged.

@huozhi
Copy link
Member

huozhi commented Feb 27, 2023

As the documentation mentioned, it's by designed, you need to speicify the full information as well. We merged the first layer of properties, but we don't merge the deeper layers of those properties.

Objects are merged together to form the final metadata output. Duplicate keys are replaced based on their ordering. Learn more about pages and layouts.

One bad case might happen could be when you don't want to specify some property, but it might accidently deep merge with the few layers away topper level metadata, resulting in unexpected metadata.

@huozhi huozhi closed this as completed Feb 27, 2023
@pf1gura
Copy link

pf1gura commented Feb 27, 2023

In our case properties that are dynamic are not included in metadata for root layout, so this exact issue you described does not happen.

If objects are not deep merged then in most cases specifying this in root layout does not make sense and should not be done.


Objects are merged together to form the final metadata output. Duplicate keys are replaced based on their ordering.

I did not interpret this line in documentation as "objects won't be deep merged", in fact I understood the opposite of it. If the decision on deep merging is final can the documentation be more clear about this?

@timneutkens timneutkens reopened this Feb 27, 2023
@huozhi huozhi reopened this Mar 7, 2023
@huozhi huozhi removed the linear: next Confirmed issue that is tracked by the Next.js team. label Mar 7, 2023
@huozhi huozhi reopened this Mar 7, 2023
@vxna vxna closed this as not planned Won't fix, can't repro, duplicate, stale Mar 7, 2023
@huozhi huozhi reopened this Mar 7, 2023
@huozhi
Copy link
Member

huozhi commented Mar 7, 2023

@pf1gura we're tracking the doc updates internally so I'll close this issue for now 🙏 Will rephrase the description on beta docs later

@github-actions
Copy link
Contributor

github-actions bot commented Apr 7, 2023

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 github-actions bot locked as resolved and limited conversation to collaborators Apr 7, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Metadata Related to Next.js' Metadata API.
Projects
None yet
Development

No branches or pull requests

4 participants