Skip to content

Preserve proxy rewrite status when serving cached pages - #101703

Open
jamiboym wants to merge 3 commits into
canaryfrom
adopt/101628
Open

jamiboym wants to merge 3 commits into
canaryfrom
adopt/101628

Conversation

@jamiboym

Copy link
Copy Markdown
Contributor

Adopts #101628. Closes #101628.

Fixes #101590

What?

  • packages/next/src/build/templates/app-page-runtime.ts: the cached entry's status is now applied only when res.statusCode === 200, so a status set by a proxy rewrite is no longer overwritten.
  • test/e2e/app-dir/proxy-rewrite-status: new e2e coverage for proxy rewrites that return 410 and 503 with retry-after.

Why?

With Cache Components enabled, a rewrite to a prerendered page with status 410/503 returned 200 because the cached entry's 200 status replaced the proxy status.

How?

  • The guard in app-page-runtime.ts keeps a non-200 status that was set before the cached entry is served.
  • The test covers both 410 and 503 + retry-after. In the Cache Components variant (__NEXT_CACHE_COMPONENTS=true) it fails without the fix and passes with it; it also passes with Cache Components disabled.
  • The suite is separate from not-found-non-document-dynamic because that suite covers 404 not-found semantics, while this one covers arbitrary proxy rewrite statuses.

Verification

  • New suite, Turbopack and webpack production start, with and without __NEXT_CACHE_COMPONENTS=true
  • New suite, Turbopack dev, with and without __NEXT_CACHE_COMPONENTS=true
  • not-found-non-document-dynamic, Turbopack start with and without __NEXT_CACHE_COMPONENTS=true, and webpack start with __NEXT_CACHE_COMPONENTS=true
  • pnpm test-types, pnpm lint-typescript, pnpm lint-ast-grep, pnpm lint-language
  • Focused Prettier and ESLint on the changed files
  • Full pnpm lint is currently blocked only by pre-existing check-unused-turbo-tasks findings in Rust/Turbopack (no Rust/Turbopack changes in this PR); full-repo Prettier/ESLint are blocked only by pre-existing symlink fixtures on Windows.

@vercel

vercel Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Vercel Agent finished reviewing your changes.
87cb7c6 • Tue, 17 Nov 2026 15:09:25 GMT

Vercel Agent's latest review does not approve this pull request under the repository's review policy.

Explanation

Please have @unstubbable or @lubieowoce review: the merge-base REVIEW.md requires human escalation for public HTTP-status behavior changes, here at packages/next/src/build/templates/app-page-runtime.ts:2310–2315. No confirmed defects found after checking the rebased guard, surrounding status handling, regression fixtures, and dev expected-failure gates; isolated status-selection checks passed. Full e2e and deployment verification were unavailable because dependencies and framework build outputs are absent.

Review steps (1m 3s)

Preparing the workspace 14.6s
Analyzing the changes 46.3s
Finalizing the review 2.5s

@github-actions

github-actions Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Tests Passed

Commit: 87cb7c6
View workflow run

@jamiboym

Copy link
Copy Markdown
Contributor Author

Added 1402651382 on top of the adopted commit. It covers a rewrite with { status: 410 } to a page stored with 404 (notFound()) and to one stored with a redirect (redirect()), both expecting 410, plus a direct request to the rewrite target expecting 200. The first two fail on canary with Cache Components off and on, and they're gated !dev because next dev renders the target on demand. The related fix for client navigations to a stored redirect is in #101705, stacked on this PR.

@jamiboym
jamiboym removed this pull request from stack #101715 November 13, 2026 03:39
@jamiboym
jamiboym added this pull request to stack #101716 November 13, 2026 03:39
@jamiboym
jamiboym marked this pull request as ready for review November 16, 2026 21:30
# Conflicts:
#	packages/next/src/build/templates/app-page-runtime.ts

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Status from NextResponse.rewrite() in proxy is replaced by 200 when cacheComponents is enabled

2 participants