Skip to content

Invalid _next/static paths should return plain text 404, not rendered HTML #1337

Description

@james-elicx

This issue was created by an agent analysing CI failures from the Next.js Deploy Suite (vinext main vs Next.js v16.2.6, 2026-05-20).

Problem

When a request is made to an invalid _next/static/* path (e.g., /_next/static/invalid-path), Next.js returns a 404 response with plain text body "Not Found". vinext instead passes these requests through to the App Router / Pages Router rendering pipeline, producing a full HTML not-found page with RSC bootstrap scripts, CSS, etc.

Additionally, valid _next/static assets under basePath or assetPrefix configurations return 404 because the static asset layer does not account for these prefixes.

Expected: "Not Found"  (plain text)
Received: "<!DOCTYPE html><html>...<p>Custom Not Found</p>...</html>"

Expected: 200  (valid build manifest)
Received: 404

Estimated Impact

~21 test failures across the deploy suite.

Affected Test Suites

  • test/e2e/invalid-static-asset-404-pages/invalid-static-asset-404-pages.test.ts (3 failures)
  • test/e2e/invalid-static-asset-404-pages/invalid-static-asset-404-pages-base-path.test.ts (3 failures)
  • test/e2e/invalid-static-asset-404-pages/invalid-static-asset-404-pages-asset-prefix.test.ts (3 failures)
  • test/e2e/invalid-static-asset-404-app/invalid-static-asset-404-app.test.ts (2 failures)
  • test/e2e/invalid-static-asset-404-app/invalid-static-asset-404-app-base-path.test.ts (2 failures)
  • test/e2e/invalid-static-asset-404-app/invalid-static-asset-404-app-asset-prefix.test.ts (2 failures)
  • test/e2e/app-dir/global-not-found/*.test.ts (3 failures)
  • test/e2e/error-handler-not-found-req-url/error-handler-not-found-req-url.test.ts (1 failure)

Recommendation

  1. Reproduce first in vinext's own test suite. Add a test that requests /_next/static/nonexistent and asserts it returns 404 with plain text body "Not Found". Confirm it fails.

  2. Add a short-circuit for _next/static paths. Early in the request handling pipeline, check if the path starts with _next/static. If it matches a real asset file, serve it. If not, return new Response("Not Found", { status: 404 }) immediately without going through the page rendering pipeline.

  3. Handle basePath and assetPrefix. When these configs are set, strip the prefix before looking up the static asset. E.g., a request to /docs/_next/static/chunks/main.js should resolve to the asset at _next/static/chunks/main.js.

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions