Replies: 17 comments 5 replies
-
Dealing with a similar problem here and would appreciate any advice on this. |
Beta Was this translation helpful? Give feedback.
-
I have the same problem. In ISR, if the user slides the screen, dozens of page links come into view, if each page has a common menu component, and the menu component will request menu data, it will directly post dozens of menu requests . They appear not to be cached and cause a lot of wastes. |
Beta Was this translation helpful? Give feedback.
-
Is there a solution to this problem? It's been a long time, it can hardly be called "stable" behavior |
Beta Was this translation helpful? Give feedback.
-
Same problem here. With a single UserProvider on layout-level, I get 3 calls to appwrite for fetiching the user info :( |
Beta Was this translation helpful? Give feedback.
-
Any solutions? |
Beta Was this translation helpful? Give feedback.
-
Same problem |
Beta Was this translation helpful? Give feedback.
-
I have same problem |
Beta Was this translation helpful? Give feedback.
-
I really hate this concept that has been set by the Vercel team: fire API requests everywhere and deal with duplicates later 😢 It's against all the practices that we have been learning in PHP or other frameworks past 20 years. |
Beta Was this translation helpful? Give feedback.
-
Any update yall? Making 10 billion request to auth 🥱 |
Beta Was this translation helpful? Give feedback.
-
I hate this design. Forcing me to use modified |
Beta Was this translation helpful? Give feedback.
-
Any news here guys? |
Beta Was this translation helpful? Give feedback.
-
You can disable your reactStrictMode, is enable by default. You can disable this in your next.config.js /** @type {import('next').NextConfig} */
const nextConfig = {
reactStrictMode: false,
};
module.exports = nextConfig; Now your browser is make only one requests per endpoint. |
Beta Was this translation helpful? Give feedback.
-
Any updates on it? I have tried to wrap mt function in a react |
Beta Was this translation helpful? Give feedback.
-
Adding a value experimental: {
staticWorkerRequestDeduping: true
} to However, be careful, they specifically hidden this on |
Beta Was this translation helpful? Give feedback.
-
If they are statically generated anyway, how about just moving the query outside the component and using a reference to it? The whole pattern of doing requests in a loop is kinda weird. |
Beta Was this translation helpful? Give feedback.
-
Summary
How is request deduplication supposed to work with a layout consisting of both client, server, and static pages?
Even though all pages are rendered at build time using generate static params, each rendering of a slug page seems to be counted as an "individual rendering process". I.e. the cache is dropped as soon as a static slug page has completed rendering. Also, a shared layout and all components included seems to be re-rendered once per slug page.
Since the cache seems to be dropped between each slug page, this leads to a lot of duplicated requests if any requests are made in a shared layout or for example in a shared navigation component. How to avoid duplicated requests when for example combining SSG slug pages in a layout together with a navigation bar with dynamic links to each slug page?
Additional information
I have a layout with a navigation component and both statically generated pages and non static pages as children. Generate static params seems to work as intended and successfully generate all pages as it should with data fetched from an API. When running the application, no requests for the static pages are made to fetch data which is what I want.
However, during
next build
I'm having a hard time understanding what happens. I get a lot of identical requests which also rate limits me from certain APIs. Here is an example:src/app/static/layout.tsx
src/app/static/[id]/page.tsx
This causes a lot of requests to supabase.co/rest/v1/posts?select=id%2Ctitle during
npm run build
, even though they are the same, which can be seen below.In my head, I thought these requests would be deduped, but they seem not to be. I'm not sure how to solve this. For my navigation bar example, where the navigation bar is a client component, I want to do a request in my layout and pass props to the navigation bar component, and this without sending duplicated requests for every [slug] page I have beneath.
Changing the Navigation component into a server components, and fetching data within Navigation does not change the behavior. Requests are still duplicated for every page that includes the Navigation component.
src/app/static/navigation.tsx
Build output:
I've also tried using React cache function but it does not change anything. Regardless if react cache or fetch is used, the component seems to be rendered once per slug and requests are sent once per slug.
Looking at the documentation https://beta.nextjs.org/docs/data-fetching/fundamentals#automatic-fetch-request-deduping:
In the dynamic scenario layout and navigation is rendered on the first page load and requests are deduplicated. Navigating to slug pages does not re-render the layout and navigation bar, therefore no requests are sent from layout and navigation.
But when it comes to the SSG case... Even though everything is rendered at the same time using generate static params, each rendering of a slug page seems to be counted as an "individual rendering process". I.e. the cache is dropped as soon as a static slug page has completed rendering. Also, the layout and all components included seems to be re-rendered per slug.
Slugs sharing a layout does not seem to be taken into account during SSG and generate static params. For the SSG case, I think the whole build should be counted as a rendering process. I.e. the cache should be kept during the whole build until all static pages are rendered. Also, shared components in a shared layout should only be rendered once.
But what do I know. I'm lost... 😢
But basically I have some questions:
I'm probably doing something obviously wrong, are there any examples how to combine statically generated pages (with generateStaticParams and [slugs]) together with a client navigation components using the same layout? Most navigation examples use a static link map defined in json, i.e. not generated based on the result of api calls.
How does deduplication work outside of generateStaticParams? The only way I have managed to solve this is to write my own cache function but according to the documentation, it seems to be suggested to let next handle caching, which is what I'm trying to achieve.
Beta Was this translation helpful? Give feedback.
All reactions