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
import{cookies}from"next/headers";exportdefaultfunctionHomePage(){return(<main><formaction={serverAction}><button>Click</button></form></main>);}asyncfunctionserverAction(){"use server";awaitcookies();// <- this throws in Next.js 15.1.0 when JS is disabled on the clientconsole.log("action called");// <- this statement is reached in Next.js 15.0.0}
Start the application in development (next dev)
Open the application in the web browser
Open the devTools and disable Javascript. Refresh the page.
Click the button
Current vs. Expected behavior
Expected behavior
The server action runs successfully.
Actual behavior
The server action throws, leading to a blank page. The thrown error is:
⨯ Error: `cookies` was called outside a request scope. Read more: https://nextjs.org/docs/messages/next-dynamic-api-wrong-context
at cookies (src/app/page.tsx:15:15)
13 | async function serverAction() {
14 | "use server";
> 15 | await cookies(); // <- this throws in Next.js 15.1.0 when JS is disabled on the client
| ^
16 | console.log("action called"); // <- this statement is reached in Next.js 15.0.0
17 | } {
page: '/'
}
✓ Compiled /_error in 355ms (807 modules)
POST / 500 in 861ms
Provide environment information
Operating System:
Platform: linux
Arch: x64
Version: #52-Ubuntu SMP PREEMPT_DYNAMIC Thu Dec 5 13:09:44 UTC 2024
Available memory (MB): 31798
Available CPU cores: 24
Binaries:
Node: 20.14.0
npm: 10.7.0
Yarn: 1.22.19
pnpm: N/A
Relevant Packages:
next: 15.1.4 // Latest available version is detected (15.1.4).
eslint-config-next: 15.0.3
react: 19.0.0
react-dom: 19.0.0
typescript: 5.7.3
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)
next dev (local), next start (local)
Additional context
I think my problem is a regression that was introduced in Next 15.1.0. When I downgrade to 15.0.0, I do not encounter the problem.
// No problem with these dependencies"dependencies": {"react": "19.0.0-rc-65a56d0e-20241020","react-dom": "19.0.0-rc-65a56d0e-20241020","next": "15.0.0"}
The problem only occurs when JavaScript is disabled on the client. Could it have something to do with hydration?
I only tested the code locally.
The text was updated successfully, but these errors were encountered:
Link to the code that reproduces this issue
https://github.com/debel27/next-issue_server-action-context
To Reproduce
All the relevant code is in this file:
src/app/page.tsx
next dev
)Current vs. Expected behavior
Expected behavior
The server action runs successfully.
Actual behavior
The server action throws, leading to a blank page. The thrown error is:
Provide environment information
Operating System: Platform: linux Arch: x64 Version: #52-Ubuntu SMP PREEMPT_DYNAMIC Thu Dec 5 13:09:44 UTC 2024 Available memory (MB): 31798 Available CPU cores: 24 Binaries: Node: 20.14.0 npm: 10.7.0 Yarn: 1.22.19 pnpm: N/A Relevant Packages: next: 15.1.4 // Latest available version is detected (15.1.4). eslint-config-next: 15.0.3 react: 19.0.0 react-dom: 19.0.0 typescript: 5.7.3 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)
next dev (local), next start (local)
Additional context
I think my problem is a regression that was introduced in Next 15.1.0. When I downgrade to 15.0.0, I do not encounter the problem.
The problem only occurs when JavaScript is disabled on the client. Could it have something to do with hydration?
I only tested the code locally.
The text was updated successfully, but these errors were encountered: