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

generateMetadata() in root layout.tsx is called on every navigation #62165

Open
kevinmitch14 opened this issue Feb 16, 2024 · 1 comment
Open
Labels
bug Issue was opened via the bug report template.

Comments

@kevinmitch14
Copy link
Contributor

Link to the code that reproduces this issue

https://github.com/kevinmitch14/reproduction-app

To Reproduce

Go to page /1 and continue to navigate through pages via Link (1, 2, 3, 4...)

Current vs. Expected behavior

Behaviour:
When using fetch, results in generateMetadata() are the same on every refresh/navigation.
When not using fetch() or adding a an artificial delay, the computation is done on every page navigation.

Expectations:
generateMetadata() in layout.tsx is not called on every navigation. Similar to how layout.tsx does not re-render/re-fetch on navigation.

Context: I want to display a metadata icon based on the route. I need to fetch the image from a remote DB. This image does not change, it only needs to be fetched in root layout. I am not using fetch

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 23.0.0: Fri Sep 15 14:41:43 PDT 2023; root:xnu-10002.1.13~1/RELEASE_ARM64_T6000
Binaries:
  Node: 20.9.0
  npm: 10.1.0
  Yarn: 1.22.19
  pnpm: 8.15.1
Relevant Packages:
  next: 14.1.1-canary.57 // Latest available version is detected (14.1.1-canary.57).
  eslint-config-next: N/A
  react: 18.2.0
  react-dom: 18.2.0
  typescript: 5.1.3
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

Metadata (metadata, generateMetadata, next/head)

Which stage(s) are affected? (Select all that apply)

next dev (local), next start (local)

Additional context

I also have another issue filed at #62162. Would be good to clarify if cache() is relevant to generateMetadata(). It seems it is from the docs, but it is not clear if generateMetadata() has access to the cache context.

@kevinmitch14 kevinmitch14 added the bug Issue was opened via the bug report template. label Feb 16, 2024
@ViKi10000
Copy link

can i work on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue was opened via the bug report template.
Projects
None yet
Development

No branches or pull requests

2 participants