-
Notifications
You must be signed in to change notification settings - Fork 27.2k
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
Fetch Cache misses on Build. API being called for every page generation twice on nextjs 13.5.4 #56355
Comments
Have same problem
|
Please note that even if you don't get the error you may get duplicated API requests. Can you check your server access logs and confirm if you have more API requests than expected? Check this both in local and deployment because you may not get the error in local but the issue is there. I think the error happens when there's 2 requests being called simultanously and one fails to set Cache. |
Replace |
@domosedov what version of nextjs are you using? Have you checked in the server logs that you don't get multiple API calls for the same fetch? |
This has been plaguing next js in the latest versions and the problem is that the response size is too big, so the cache just fails. You can find like 3 issues explaining the same issue. |
new bugs downgrade next to 13.4.12 |
@diaz-hfc I don't think the problem has to do with the response size. I've tried with very small sized response and I have the same issue. In my example project I fetch 5 blog posts and that is 28kb. |
I'm not sure why this is not being paid attention to, its a big issue in my opinion. |
Also having this issue on every other build. Every time it's the same document, which has a large size. That makes me think it has to do with response size as well. Weird thing is it works sometimes, and sometimes not. Locally it always works. |
I've faced the same issue. After looking at the incremental cache, it seems to be related to this commit which added an IPC Server. By bypassing it manually the filesystem cache seems to be working again. Just try and remove this from packages/next/src/server/lib/incremental-cache/index.ts, and then it works :
|
This uses an IPC server (if available) for incremental cache methods to help prevent race conditions when reading/writing from cache and also to dedupe requests in cases where multiple cache reads are in flight. This cuts down on data fetching across the different build-time workers. Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
Link to the code that reproduces this issue
https://github.com/MasteringBOX/fetch-bug
To Reproduce
Current vs. Expected behavior
This project uses the app router.
Expected: I would expect the API to be called once when I call getData in generateStaticParams.
Current: I get 1 API call in generateStaticParams and then 2 API calls per page in a SSG page ([slug]/page). In a 5 SSG project I get 11 API calls instead of 1. In my current project this escalates to 1000 API calls instead of 10 in build.
I also get this error in some of the API calls, the error does not appear consistently through different versions of node and nextjs.
This happens in next 13.5.4 and 13.5.4-canary.11. It also fails in a lot of previous versions. 13.4.3 works ok in local in Node 20 and 18. In vercel I still get extra API calls in next 13.4.3 but not as many.
Verify canary release
Provide environment information
Operating System: Platform: darwin Arch: arm64 Version: Darwin Kernel Version 22.3.0: Mon Jan 30 20:39:46 PST 2023; root:xnu-8792.81.3~2/RELEASE_ARM64_T6020 Binaries: Node: 18.12.1 npm: 8.19.2 Yarn: N/A pnpm: N/A Relevant Packages: next: 13.5.4 eslint-config-next: 13.5.3 react: 18.2.0 react-dom: 18.2.0 typescript: 5.2.2 Next.js Config: output: N/A
Which area(s) are affected? (Select all that apply)
App Router, Data fetching (gS(S)P, getInitialProps)
Additional context
I tested this in many nextjs versions. The latest I could find that works is 13.4.3. But even there the Vercel build will make a lot of extra calls, increasing build time and consuming more server resources.
Apart from the minimal reproducible example, I created another project with more fetch calls and pages that really showcases the severity of the issue. This one is not commented.
https://github.com/MasteringBOX/fetch-cache-bug
The text was updated successfully, but these errors were encountered: