[PR #1078] [MERGED] refactor(server): dedupe action/page/route-handler error response building #1075

Closed
opened 2026-05-06 13:11:51 +02:00 by BreizhHardware · 0 comments

📋 Pull Request Information

Original PR: https://github.com/cloudflare/vinext/pull/1078
Author: @james-elicx
Created: 5/5/2026
Status: Merged
Merged: 5/5/2026
Merged by: @james-elicx

Base: mainHead: refactor/dedupe-action-error-handling


📝 Commits (1)

  • aef08ee refactor(server): dedupe action/page/route-handler error response building

📊 Changes

4 files changed (+121 additions, -52 deletions)

View changed files

📝 packages/vinext/src/server/app-page-execution.ts (+8 -6)
📝 packages/vinext/src/server/app-route-handler-policy.ts (+8 -7)
📝 packages/vinext/src/server/app-server-action-execution.ts (+30 -39)
packages/vinext/src/server/next-error-digest.ts (+75 -0)

📄 Description

Summary

  • Extract the four byte-identical new Response(\"Payload Too Large\", { status: 413 }) calls in app-server-action-execution.ts into a local payloadTooLargeResponse() helper.
  • Extract the three near-identical NEXT_REDIRECT / NEXT_NOT_FOUND / NEXT_HTTP_ERROR_FALLBACK error.digest parsers into a new shared module packages/vinext/src/server/next-error-digest.ts exposing getNextErrorDigest, parseNextRedirectDigest, and parseNextHttpErrorDigest.

Follow-up to #1058.

Files changed

  • packages/vinext/src/server/next-error-digest.ts (new) — shared digest parsing helpers.
  • packages/vinext/src/server/app-server-action-execution.ts — uses the new helpers in getActionControlResponse, getActionRedirect, and isActionHttpFallback; replaces 4× inline 413 responses with a local payloadTooLargeResponse() (only used in this file).
  • packages/vinext/src/server/app-page-execution.tsresolveAppPageSpecialError now uses the shared parsers.
  • packages/vinext/src/server/app-route-handler-policy.tsresolveAppRouteHandlerSpecialError now uses the shared parsers.

Preserved per-call-site behaviour

The shared parsers return only the raw shape ({ type, url, status } for redirects, { status } for HTTP error fallbacks). Each caller still owns its own post-processing:

  • app-server-action-execution.ts keeps the Number.isInteger(statusCode) guard for HTTP error digests in getActionControlResponse.
  • app-server-action-execution.ts getActionRedirect keeps the full { status, type, url } shape (only this site uses the redirect type).
  • app-route-handler-policy.ts keeps new URL(redirectUrl, requestUrl).toString() resolution and the isAction ? 303 : redirect.status override.
  • app-page-execution.ts keeps the basePath-and-cookie merging at the call site.

Minor unification

parseNextRedirectDigest returns null when the encoded URL segment is missing — matching the existing guard in app-server-action-execution.ts. The page and route-handler call sites previously would have thrown URIError from decodeURIComponent(undefined) for a malformed NEXT_REDIRECT; digest with no URL; they now treat it as not-a-redirect and let the error propagate. This case is unreachable for any digest Next.js actually emits.

Test plan

  • pnpm vp test run tests/app-router.test.ts — 308 tests pass
  • pnpm fmt --write on touched files — clean
  • pnpm knip — clean
  • tsc --noEmit on the vinext package — clean

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/cloudflare/vinext/pull/1078 **Author:** [@james-elicx](https://github.com/james-elicx) **Created:** 5/5/2026 **Status:** ✅ Merged **Merged:** 5/5/2026 **Merged by:** [@james-elicx](https://github.com/james-elicx) **Base:** `main` ← **Head:** `refactor/dedupe-action-error-handling` --- ### 📝 Commits (1) - [`aef08ee`](https://github.com/cloudflare/vinext/commit/aef08ee3ed2d1d0452d32ee2aa28ab1bd09cf06a) refactor(server): dedupe action/page/route-handler error response building ### 📊 Changes **4 files changed** (+121 additions, -52 deletions) <details> <summary>View changed files</summary> 📝 `packages/vinext/src/server/app-page-execution.ts` (+8 -6) 📝 `packages/vinext/src/server/app-route-handler-policy.ts` (+8 -7) 📝 `packages/vinext/src/server/app-server-action-execution.ts` (+30 -39) ➕ `packages/vinext/src/server/next-error-digest.ts` (+75 -0) </details> ### 📄 Description ## Summary - Extract the four byte-identical `new Response(\"Payload Too Large\", { status: 413 })` calls in `app-server-action-execution.ts` into a local `payloadTooLargeResponse()` helper. - Extract the three near-identical NEXT_REDIRECT / NEXT_NOT_FOUND / NEXT_HTTP_ERROR_FALLBACK `error.digest` parsers into a new shared module `packages/vinext/src/server/next-error-digest.ts` exposing `getNextErrorDigest`, `parseNextRedirectDigest`, and `parseNextHttpErrorDigest`. Follow-up to #1058. ## Files changed - `packages/vinext/src/server/next-error-digest.ts` (new) — shared digest parsing helpers. - `packages/vinext/src/server/app-server-action-execution.ts` — uses the new helpers in `getActionControlResponse`, `getActionRedirect`, and `isActionHttpFallback`; replaces 4× inline 413 responses with a local `payloadTooLargeResponse()` (only used in this file). - `packages/vinext/src/server/app-page-execution.ts` — `resolveAppPageSpecialError` now uses the shared parsers. - `packages/vinext/src/server/app-route-handler-policy.ts` — `resolveAppRouteHandlerSpecialError` now uses the shared parsers. ## Preserved per-call-site behaviour The shared parsers return only the raw shape (`{ type, url, status }` for redirects, `{ status }` for HTTP error fallbacks). Each caller still owns its own post-processing: - `app-server-action-execution.ts` keeps the `Number.isInteger(statusCode)` guard for HTTP error digests in `getActionControlResponse`. - `app-server-action-execution.ts` `getActionRedirect` keeps the full `{ status, type, url }` shape (only this site uses the redirect `type`). - `app-route-handler-policy.ts` keeps `new URL(redirectUrl, requestUrl).toString()` resolution and the `isAction ? 303 : redirect.status` override. - `app-page-execution.ts` keeps the basePath-and-cookie merging at the call site. ## Minor unification `parseNextRedirectDigest` returns `null` when the encoded URL segment is missing — matching the existing guard in `app-server-action-execution.ts`. The page and route-handler call sites previously would have thrown `URIError` from `decodeURIComponent(undefined)` for a malformed `NEXT_REDIRECT;` digest with no URL; they now treat it as not-a-redirect and let the error propagate. This case is unreachable for any digest Next.js actually emits. ## Test plan - [x] `pnpm vp test run tests/app-router.test.ts` — 308 tests pass - [x] `pnpm fmt --write` on touched files — clean - [x] `pnpm knip` — clean - [x] `tsc --noEmit` on the vinext package — clean 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
BreizhHardware 2026-05-06 13:11:51 +02:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/vinext#1075
No description provided.