vercel / vercel/next.js

Server Action hangs when called via setTimeout immediately after router.push in next dev mode

Open
#78,985 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Server Actions
Dominant language
JavaScript
Stars
142k
Forks
32.5k
Avg merge
2d 14h
Merged PRs (30d)
351

Description

Link to the code that reproduces this issue

https://codesandbox.io/p/devbox/awesome-bird-yzvqtv

To Reproduce

There is an issue where a Server Action’s Promise does not resolve when called shortly after a navigation event.

  1. Start the application in development (next dev)
  2. Navigate to /page2 from /page1 via Link
  3. In /page2, a ClientComponent runs router.push("?asdf") inside useEffect
  4. Immediately after, it invokes a Server Action(getServerNow) via setTimeout(..., 0)
  5. The Server Action promise never resolves or rejects (in dev mode)

✅ Increasing the setTimeout delay (e.g., to 1000ms) allows the Server Action to resolve normally.
✅ This issue does not occur in production builds.

Current vs. Expected behavior

Expected:
The Server Action should resolve (or reject) properly even when invoked via setTimeout(..., 0) after router.push().

Actual (in next dev):
The Promise from the Server Action hangs—then() or catch() are never called.

Provide environment information
Operating System:
  Platform: linux
  Arch: x64
  Version: #1 SMP PREEMPT_DYNAMIC Sun Aug  6 20:05:33 UTC 2023
  Available memory (MB): 4242
  Available CPU cores: 2
Binaries:
  Node: 20.9.0
  npm: 9.8.1
  Yarn: 1.22.19
  pnpm: 8.10.2
Relevant Packages:
  next: 15.4.0-canary.28 // Latest available version is detected (15.4.0-canary.28).
  eslint-config-next: N/A
  react: 19.1.0
  react-dom: 19.1.0
  typescript: 5.3.3
Next.js Config:
  output: N/A
Which area(s) are affected? (Select all that apply)

Server Actions

Which stage(s) are affected? (Select all that apply)

next dev (local)

Additional context

This issue only occurs in next dev mode. It does not occur after next build && next start.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked CodeSandbox reproduction and follow the listed navigation flow in next dev: navigate from /page1 to /page2, trigger router.push("?asdf"), then call getServerNow through setTimeout(..., 0). Done means the Server Action promise resolves or rejects in development, while the existing production behavior remains unchanged.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, nextjs, react
Domain
backend, web-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.