fix(deploy): plain-text 404 for invalid _next/static in Pages Router worker#1630
Conversation
…worker The Pages Router Cloudflare worker template generated by `vinext deploy` forwarded asset-shaped misses to `renderPage`, which renders the full HTML 404 page (with bootstrap scripts + CSS) instead of the plain-text "Not Found" body Next.js emits. The App Router worker entry and prod server already short-circuit these requests; only the Pages Router worker template was missing the check. Adds `isNextStaticPath` + `notFoundStaticAssetResponse` to `generatePagesRouterWorkerEntry()` so invalid `_next/static/*` requests (including those under `basePath` or `assetPrefix`) return `text/plain; charset=utf-8` "Not Found" before the renderer runs. Matches Next.js: packages/next/src/server/lib/router-server.ts. Fixes #1337
|
/bigbonk review |
commit: |
|
There was a problem hiding this comment.
Clean, well-scoped fix. The change is a straightforward port of the existing isNextStaticPath + notFoundStaticAssetResponse short-circuit pattern to the one remaining code path that was missing it.
Correctness: The placement mirrors app-router-entry.ts exactly — after isOpenRedirectShaped but before filterInternalHeaders / basePath stripping / middleware. This is the right spot: _next/static/* requests never need middleware processing, and the check uses the raw pathname (before basePath is stripped) which is correct since isNextStaticPath handles basePath stripping internally.
Parity check: Verified the same pattern exists in:
server/app-router-entry.ts:89-96— App Router worker entry ✓server/prod-server.ts:1166-1178— App Router prod server (viaresolveAppRouterAssetPath) ✓server/prod-server.ts:1514-1527— Pages Router prod server (viaresolveAppRouterAssetPath) ✓
The Pages Router worker template in deploy.ts was indeed the only remaining gap.
Generated entry stays thin: The new code delegates entirely to existing typed helpers (isNextStaticPath, notFoundStaticAssetResponse, assetPrefixPathname) — no inline logic added. Consistent with the AGENTS.md guidance.
Tests: The positional assertion (staticPos < renderPagePos) is a good pattern already used by other tests in this file (e.g., the requestContextFromRequest → runMiddleware ordering test at line 920). Import presence checks are reasonable for generated code tests.
|
Approved PR #1630. The fix is correct and well-implemented:
|
Summary
vinext deploywas forwarding asset-shaped misses (e.g./_next/static/nonexistent.js) torenderPage, which renders the full HTML 404 page with bootstrap scripts + CSS instead of the plain-text"Not Found"body Next.js emits.isNextStaticPath+notFoundStaticAssetResponseshort-circuit (already used byapp-router-entry,prod-serverApp Router branch, andprod-serverPages Router branch) togeneratePagesRouterWorkerEntry()so invalid_next/static/*requests — including those underbasePathorassetPrefix— returntext/plain; charset=utf-8"Not Found"before the renderer runs.packages/next/src/server/lib/router-server.ts.Fixes #1337
Test plan
pnpm test tests/deploy.test.ts— new regression test asserts the generated Pages Router worker contains the short-circuit and that it precedes therenderPagecall.pnpm test tests/invalid-static-asset-404.test.ts— existing end-to-end assertions for the App Router worker entry + prod server (Node) still pass.pnpm test tests/after-deploy.test.ts— generator metadata tests still pass.pnpm run lint,pnpm run fmt:check.