Skip to content
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

Regression in v15.1.0: cookies() throws in server action #74790

Open
debel27 opened this issue Jan 11, 2025 · 0 comments
Open

Regression in v15.1.0: cookies() throws in server action #74790

debel27 opened this issue Jan 11, 2025 · 0 comments
Labels
bug Issue was opened via the bug report template. Runtime Related to Node.js or Edge Runtime with Next.js.

Comments

@debel27
Copy link

debel27 commented Jan 11, 2025

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

import { cookies } from "next/headers";

export default function HomePage() {
  return (
    <main>
     <form action={serverAction}>
       <button>Click</button>
     </form>
    </main>
  );
}

async function serverAction() {
  "use server";
  await cookies(); // <- this throws in Next.js 15.1.0 when JS is disabled on the client
  console.log("action called"); // <- this statement is reached in Next.js 15.0.0
}
  1. Start the application in development (next dev)
  2. Open the application in the web browser
  3. Open the devTools and disable Javascript. Refresh the page.
  4. 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.

@debel27 debel27 added the bug Issue was opened via the bug report template. label Jan 11, 2025
@github-actions github-actions bot added the Runtime Related to Node.js or Edge Runtime with Next.js. label Jan 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue was opened via the bug report template. Runtime Related to Node.js or Edge Runtime with Next.js.
Projects
None yet
Development

No branches or pull requests

1 participant