You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Observe that Next.js will patch it again, because the __nextPatched property no longer exists on the patched fetch and that's what it checks for.
So now globalThis.fetch is wrapped multiple times with the same Next.js patch, sandwiching any other patches in between.
See repo for example reproduction. Reloads result in 504s, errors in the log are:
Error: Your function was stopped as it did not return an initial response within 25s
Current vs. Expected behavior
Current behaviour is that fetch gets wrapped multiple times, potentially again and again each request in the edge runtime. One outcome of this is that fetch calls deadlock (unclear exactly why – something to do with the internals of the patch implementation), leading to 504 errors.
Expected behaviour is that it only wraps once, and then fetch calls (even if wrapped by another patch), will succeed.
Provide environment information
Operating System:
Platform: darwin
Arch: arm64
Version: Darwin Kernel Version 23.4.0: Fri Mar 15 00:10:42 PDT 2024; root:xnu-10063.101.17~1/RELEASE_ARM64_T6000
Available memory (MB): 32768
Available CPU cores: 10
Binaries:
Node: 20.12.2
npm: 10.5.2
Yarn: 4.1.1
pnpm: 9.0.6
Relevant Packages:
next: 14.2.3 // Latest available version is detected (14.2.3).
eslint-config-next: N/A
react: 18.3.1
react-dom: 18.3.1
typescript: 5.4.5
Next.js Config:
output: N/A
Which area(s) are affected? (Select all that apply)
Runtime
Which stage(s) are affected? (Select all that apply)
Vercel (Deployed)
Additional context
Suggestion is to not set a property on the thing you're patching to then check if it's been patched or not. Perhaps set a symbol on globalThis or similar?
Also probably worth looking into why the patch can't be applied recursively in the first place (ie, what's causing the deadlocks).
Also, ideally, remove the patch altogether and provide the functionality in another way 🙏
The text was updated successfully, but these errors were encountered:
Link to the code that reproduces this issue
https://github.com/mhart/nextjs-patch-bug
Live at: https://nextjs-bug-eight.vercel.app/ (try reloading a few times)
To Reproduce
globalThis.fetch
after Next.js has already patched it__nextPatched
property no longer exists on the patched fetch and that's what it checks for.globalThis.fetch
is wrapped multiple times with the same Next.js patch, sandwiching any other patches in between.See repo for example reproduction. Reloads result in 504s, errors in the log are:
Current vs. Expected behavior
Current behaviour is that fetch gets wrapped multiple times, potentially again and again each request in the edge runtime. One outcome of this is that fetch calls deadlock (unclear exactly why – something to do with the internals of the patch implementation), leading to 504 errors.
Expected behaviour is that it only wraps once, and then fetch calls (even if wrapped by another patch), will succeed.
Provide environment information
Operating System: Platform: darwin Arch: arm64 Version: Darwin Kernel Version 23.4.0: Fri Mar 15 00:10:42 PDT 2024; root:xnu-10063.101.17~1/RELEASE_ARM64_T6000 Available memory (MB): 32768 Available CPU cores: 10 Binaries: Node: 20.12.2 npm: 10.5.2 Yarn: 4.1.1 pnpm: 9.0.6 Relevant Packages: next: 14.2.3 // Latest available version is detected (14.2.3). eslint-config-next: N/A react: 18.3.1 react-dom: 18.3.1 typescript: 5.4.5 Next.js Config: output: N/A
Which area(s) are affected? (Select all that apply)
Runtime
Which stage(s) are affected? (Select all that apply)
Vercel (Deployed)
Additional context
Suggestion is to not set a property on the thing you're patching to then check if it's been patched or not. Perhaps set a symbol on globalThis or similar?
Also probably worth looking into why the patch can't be applied recursively in the first place (ie, what's causing the deadlocks).
Also, ideally, remove the patch altogether and provide the functionality in another way 🙏
The text was updated successfully, but these errors were encountered: