nextjs - ✅(Solved) Fix Race condition results in multiple threads working on server action queue, corrupting state.canonicalUrl [1 pull requests, 1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
vercel/next.js#90467Fetched 2026-04-08 00:20:04
View on GitHub
Comments
1
Participants
2
Timeline
5
Reactions
2
Timeline (top)
labeled ×2commented ×1cross-referenced ×1issue_type_added ×1

Fix Action

Fixed

PR fix notes

PR #91044: fix(app-router): discard queued server actions on navigation

Description (problem / solution / changelog)

What?

Discard all queued server actions when a navigation/restore is dispatched so stale queued actions cannot commit state after a route change.

Why?

Issue #90467 reports queued server actions racing with navigation and clobbering state.canonicalUrl (and related router state). Previously only the currently pending action was discarded; queued actions could still run after navigation and overwrite the new route state.

How?

  • Mark every queued action as discarded when a navigation/restore is dispatched.
  • Keep the navigation action as the last queued action so subsequent actions queue behind it.
  • Added an e2e regression test that queues multiple actions, navigates away, and asserts we remain on the destination page.

Fixes #90467

Tests

  • pnpm lint-eslint packages/next/src/client/components/app-router-instance.ts test/e2e/app-dir/actions/app-action.test.ts
  • Unable to run pnpm testonly-start-webpack ... locally because packages/next/dist/build/jest/jest was missing (build not generated in this environment).

Changed files

  • packages/next/src/client/components/app-router-instance.ts (modified, +8/-5)
  • test/e2e/app-dir/actions/app-action.test.ts (modified, +22/-0)

Code Example

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 23.4.0: Fri Mar 15 00:11:08 PDT 2024; root:xnu-10063.101.17~1/RELEASE_ARM64_T8122
  Available memory (MB): 16384
  Available CPU cores: 8
Binaries:
  Node: 22.12.0
  npm: 10.9.0
  Yarn: 1.22.22
  pnpm: 10.8.0
Relevant Packages:
  next: 16.2.0-canary.59 // Latest available version is detected (16.2.0-canary.59).
  eslint-config-next: N/A
  react: 19.2.4
  react-dom: 19.2.4
  typescript: 5.9.3
Next.js Config:
  output: standalone
RAW_BUFFERClick to expand / collapse

Link to the code that reproduces this issue

https://github.com/newportandy/next-16-action-queue-race-condition

To Reproduce

  1. npm install && npm run build
  2. npm start
  3. Open http://localhost:3000/page-a
  4. While the yellow "Loading..." box is showing (50 fast server actions queuing up), click the blue "Navigate to Page B" button
  5. Wait for Page B to render, you'll see what the current state.canonicalUrl is set to (it alternates as the two thread fight over it)
  6. Depending on which thread ran last, clicking "Save" on Page B will either work as expected or redirect you incorrectly to /page-a

Current vs. Expected behavior

Current behaviour: Depending on which thread ran last, submitting a server action on page B will either correctly stay on page B, or it will redirect to page A.

Expected behaviour: The server action doesn't redirect to page A arbitrarily.

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 23.4.0: Fri Mar 15 00:11:08 PDT 2024; root:xnu-10063.101.17~1/RELEASE_ARM64_T8122
  Available memory (MB): 16384
  Available CPU cores: 8
Binaries:
  Node: 22.12.0
  npm: 10.9.0
  Yarn: 1.22.22
  pnpm: 10.8.0
Relevant Packages:
  next: 16.2.0-canary.59 // Latest available version is detected (16.2.0-canary.59).
  eslint-config-next: N/A
  react: 19.2.4
  react-dom: 19.2.4
  typescript: 5.9.3
Next.js Config:
  output: standalone

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

Dynamic Routes, Server Actions

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

next dev (local), next start (local), Other (Deployed)

Additional context

This issue seems to first appear in 16.0.0, testing with 15.5.12 doesn't surface the same state corruption issue.

extent analysis

Fix: Disable concurrent server‑action execution (serialize actions)

Next 16 runs server actions concurrently. When you navigate while a batch of actions is still queued,

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

nextjs - ✅(Solved) Fix Race condition results in multiple threads working on server action queue, corrupting state.canonicalUrl [1 pull requests, 1 comments, 2 participants]