nextjs - ✅(Solved) Fix 500 error instead of 404 when answering a POST request with form data [2 pull requests, 11 comments, 5 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

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#90090Fetched 2026-04-08 00:20:49
View on GitHub
Comments
11
Participants
5
Timeline
36
Reactions
0
Timeline (top)
commented ×11subscribed ×10mentioned ×8cross-referenced ×2

Fix Action

Fixed

PR fix notes

PR #90101: fix: return 404 instead of 500 for multipart POST without server action

Description (problem / solution / changelog)

What?

When a POST request with multipart/form-data content type is sent to a route that has server actions, but the request itself doesn't contain valid action IDs in the form data, the server returns a 500 error instead of the expected 404.

Why?

The action handler treats any multipart POST as a potential MPA server action. When areAllActionIdsValid() returns false (no valid action IDs in form data), it throws an error:

Failed to find Server Action. This request might be from an older or newer deployment.

This results in a 500 response. However, if there are no valid action IDs in the form data, the request was never intended to be a server action — it's just a regular multipart POST to a non-existent route (or a route that doesn't handle POST).

The existing TODO comments on both code paths acknowledged this:

// TODO: This can be from skew or manipulated input. We should handle this case more gracefully

How?

Changed both the Edge and Node.js runtime paths to return null instead of throwing when areAllActionIdsValid() returns false. Returning null from the action handler lets normal routing take over, which correctly returns 404.

This is consistent with the existing behavior a few lines below, where decodeAction returns a non-function:

} else {
  // We couldn't decode an action, so this POST request turned out not to be a server action request.
  return null
}

Fixes #90090

  • Related issues linked using fixes #number
  • Tests not needed (behavior change is from 500 → 404 for non-action requests; existing MPA action tests cover the action paths)

Changed files

  • packages/next/src/server/app-render/action-handler.ts (modified, +6/-10)
  • test/e2e/app-dir/actions-unrecognized/actions-unrecognized.test.ts (modified, +6/-32)

PR #91129: Fix POST with form data returning 500 instead of 404

Description (problem / solution / changelog)

Summary

  • When a multipart/form-data POST request is sent to a route that doesn't have a server action, Next.js returns a 500 error instead of 404
  • The root cause is in action-handler.ts: when areAllActionIdsValid() returns false for a non-fetch multipart POST, the handler throws an error instead of returning null to fall through to normal routing
  • Changed both occurrences (Web API path and Node.js streaming path) to return null instead of throwing, allowing normal 404 routing to occur

Fixes #90090

Test plan

  • Added e2e test test/e2e/app-dir/post-formdata-404/ that verifies:
    • POST with multipart/form-data to a non-existent route returns 404
    • POST with multipart/form-data to an existing route without server actions returns 404

This contribution was developed with AI assistance (Claude Code).

Changed files

  • packages/next/src/server/app-render/action-handler.ts (modified, +6/-10)
  • test/e2e/app-dir/post-formdata-404/app/layout.tsx (added, +11/-0)
  • test/e2e/app-dir/post-formdata-404/app/page.tsx (added, +3/-0)
  • test/e2e/app-dir/post-formdata-404/app/with-action/page.tsx (added, +10/-0)
  • test/e2e/app-dir/post-formdata-404/next.config.js (added, +2/-0)
  • test/e2e/app-dir/post-formdata-404/post-formdata-404.test.ts (added, +31/-0)

Code Example

Operating System:
  Platform: linux
  Arch: x64
  Version: #29~24.04.1-Ubuntu SMP PREEMPT_DYNAMIC Thu Jun 26 14:16:59 UTC 2
  Available memory (MB): 63932
  Available CPU cores: 22
Binaries:
  Node: 22.22.0
  npm: 10.9.4
  Yarn: 1.22.22
  pnpm: 9.15.5
Relevant Packages:
  next: 16.1.6 // Latest available version is detected (16.1.6).
  eslint-config-next: N/A
  react: 19.2.3
  react-dom: 19.2.3
  typescript: 5.9.3
Next.js Config:
  output: N/A
RAW_BUFFERClick to expand / collapse

Link to the code that reproduces this issue

https://github.com/vinassefranche/next-js-server-action-issue-with-form-data

To Reproduce

  1. Start the application in dev mode (pnpm dev)
  2. Run node send-form-data-request.mjs

Current vs. Expected behavior

I expect a 404 status code being returned instead of a 500 status code

Provide environment information

Operating System:
  Platform: linux
  Arch: x64
  Version: #29~24.04.1-Ubuntu SMP PREEMPT_DYNAMIC Thu Jun 26 14:16:59 UTC 2
  Available memory (MB): 63932
  Available CPU cores: 22
Binaries:
  Node: 22.22.0
  npm: 10.9.4
  Yarn: 1.22.22
  pnpm: 9.15.5
Relevant Packages:
  next: 16.1.6 // Latest available version is detected (16.1.6).
  eslint-config-next: N/A
  react: 19.2.3
  react-dom: 19.2.3
  typescript: 5.9.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), next start (local)

Additional context

extent analysis

Fix Plan

Server Action Fix

The issue is caused by a bug in Next.js server actions when handling form data. The fix involves updating the next package to the latest version, which includes a patch for this issue.

Step-by-Step Solution

  1. Update next package:

pnpm update next

2. **Verify the update**:
   ```bash
npm ls next

This should show the updated version of next.

Code Changes

No code changes are required in your application. The fix is handled by the updated next package.

Temporary Workaround

If you cannot update the next package immediately, you can use a temporary workaround by creating a custom server action handler. However, this is not recommended as it may introduce additional complexity and bugs.

Verification

To verify that the fix worked, run the following command:

node send-form-data-request.mjs

This should return a 404 status code instead of a 500 status code.

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 500 error instead of 404 when answering a POST request with form data [2 pull requests, 11 comments, 5 participants]