Replies: 1 comment
-
I found same problem as of mine on stackoverflow :- https://stackoverflow.com/questions/77842295/how-to-make-a-single-request-with-next-js-and-generate-metadata |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Goals
Non-Goals
Background
Currently, Next.js makes separate API/DB calls in both the generateMetadata function and the page component. This leads to redundant data fetching, increasing load times and server load. There are no built-in alternatives in Next.js to share data between these functions, forcing developers to implement custom caching or memoization solutions. A built-in solution would streamline the process, improving performance and developer experience.
Proposal
Feature Request: Optimize Metadata Generation and Page Rendering to Avoid Duplicate API/DB Calls
Description
In the current implementation of Next.js, when using the
generateMetadata
function along with a page component, it often results in duplicate API/DB calls. This occurs because bothgenerateMetadata
and the page component make separate requests to fetch the same data, which can lead to increased load times and unnecessary server load.Example
Consider the following example where we fetch product information:
In this setup,
getProduct
is called twice—once ingenerateMetadata
and once in the page component, leading to two separate requests.Proposed Solution
Introduce a built-in mechanism in Next.js to share data between
generateMetadata
and the page component, ensuring that the data is fetched only once and reused across both.Potential API
Unified Data Fetching Context:
generateMetadata
and the page component.Caching Mechanism:
generateMetadata
and the page component without additional requests.Example Usage
Benefits
Request for Implementation
We request the Next.js team to consider implementing this feature in a future release to optimize the process of metadata generation and page rendering.
Thank you for your consideration and for the excellent work on Next.js.
Beta Was this translation helpful? Give feedback.
All reactions