Calling Server Action in Dynamic Route Resets globalThis, but Not in Static Route
stevenwang223 opened this issue · 0 comments
Link to the code that reproduces this issue
https://github.com/stevenwang223/dynamic-route-issue
To Reproduce
Run npm install
Start the application (npm run dev)
Go to http://localhost:3000/safd (note: this is a dynamic route, the [id] does not matter)
- Click on "Test Server Action" button a few times.
- Look at the logs, you'll see "Creating new Test Client" show up each time the button is pressed.
Now, go to the main home page and do the same thing (note: this is NOT the dynamic route)
- Click on "Test Server Action" button a few times.
- Look at the logs, you will NOT see "Creating new Test Client" show up. Indicating that the singleClient was preserved.
Screenshot of Logs from Calling Server Action in Static Route
Screenshot of Logs from Calling Server Action in Dynamic Route
Current vs. Expected behavior
I expect the behavior to be the same in static and dynamic route.
Also, could you please explain why triggering a Server Action results in a log showing that a POST request was made to the URL?
Apologies in advance is this is not a bug. I am merely trying to understand why this is happening and couldn't find anything after reading the documentation and searching online.
Provide environment information
Operating System:
Platform: darwin
Arch: arm64
Version: Darwin Kernel Version 24.1.0: Thu Oct 10 21:03:15 PDT 2024; root:xnu-11215.41.3~2/RELEASE_ARM64_T6000
Available memory (MB): 16384
Available CPU cores: 10
Binaries:
Node: 20.10.0
npm: 10.2.3
Yarn: N/A
pnpm: 9.3.0
Relevant Packages:
next: 15.1.1-canary.16 // Latest available version is detected (15.1.1-canary.16).
eslint-config-next: 15.1.2
react: 19.0.0
react-dom: 19.0.0
typescript: 5.7.2
Next.js Config:
output: N/A
Which area(s) are affected? (Select all that apply)
Not sure
Which stage(s) are affected? (Select all that apply)
next dev (local), Vercel (Deployed)
Additional context
When I deploy my app in vercel and I look at vercel's logs, I do not see the log indicating that the singleTon client is re-created each time a server action is triggered.