generateMetadata()
in root layout.tsx
is called on every navigation
#62165
Labels
bug
Issue was opened via the bug report template.
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 ingenerateMetadata()
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 togenerateMetadata()
. It seems it is from the docs, but it is not clear if generateMetadata() has access to the cache context.The text was updated successfully, but these errors were encountered: