-
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
Next 13 fetch in server component stuck forever if response is larger than ~15kb #41853
Comments
Sounds like a reprisal of this type of issue: |
@Escapado I think line 4 i.e. this API https://apimocha.com/next13/75posts returns an invalid response body for JSON. they don't have an opening array tag "[". I had the same problem even though the API was returning valid JSON. But, works fine when I use axios. |
Thanks @renomureza. I fixed that. However the issue still stands it's reproducible if you for example try the following mock apis: |
@Escapado Instead of using fetch try using axios, it worked for me. |
This hurts me deeply |
Thanks for reporting, I did some digging, and the issue seems to be Currently, on the server, Next.js uses So current workarounds are:
module.exports = {
experimental: {
enableUndici: true
}
} |
This comment was marked as resolved.
This comment was marked as resolved.
using node-fetch solved this |
What version did you use? As @balazsorban44 mentioned, Next.js also uses node-fetch under the hood. Perhaps they are using a different version? |
@nowaythatworked node-fetch v3.2.10 |
#41988 I see now.... the payload on this one is about 300kb |
Investigated this one on my flight back from Next.js Conf, it's a known issue with cloning responses of |
When deploying to Vercel, on [email protected], I still see this problem.
Could the problem be that this function lives at Using Node 16.X ~ |
FYI to @timneutkens, I can confirm that this is still broken when deploying to Vercel (same as what @icyJoseph is seeing). Neither manually setting Server Components that fetch large payloads hang until the serverless function times out. I added some debug output and determined that my Vercel deployment is running Node.js v16.16.0. |
Same problem here. Still broken on deploy,but works fine in dev now. The max version of node on vercel is 16.6. Perhaps now is a time to enable node 18? |
FYI, I just confirmed that this Vercel deployment aspect is fixed in v13.0.2-canary.1 via #42382 |
I am seeing this warning now but do not have this option configured: #42441 |
Hi this should be updated in |
I can confirm it is fixed. Thanks! |
This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
Verify canary release
Provide environment information
What browser are you using? (if relevant)
No response
How are you deploying your application? (if relevant)
No response
Describe the Bug
When fetching data as described in the docs, the fetch function gets stuck and never resolves, if the payload reaches a certain size.
I created a minimal stackblitz and a mock api to reproduce the problem. If I fetch 75 posts from the mock api it will never resolve, if I only fetch 50 it works fine. Since I was able to reproduce this problem with multiple mock apis and even when using something like supabase to fetch some data I think it might be a size issue? Here the difference is 14kb vs 20kb for the two requests.
EDIT:
I tried to nail the problem down further. fetch does indeed resolve but
.json()
does not. Does this have to do with the highWaterMark buffer size limit on nodejs streams?Expected Behavior
Fetch should not get stuck forever.
Link to reproduction
https://stackblitz.com/edit/nextjs-vv7ryj?file=app/page.tsx
To Reproduce
pages.tsx
to fetch 75 instead of 50 postsThe text was updated successfully, but these errors were encountered: