fix: make RequestContext required on matchHeaders/matchRedirect/matchRewrite#213
Merged
southpolesteve merged 1 commit intomainfrom Mar 1, 2026
Merged
Conversation
…Rewrite Next.js always has request context when evaluating has/missing conditions on headers, redirects, and rewrites. There is no code path where these are evaluated without a request. Making ctx required eliminates ambiguity about what happens when context is missing, and surfaces any future call sites that forget to pass it as compile-time errors instead of silent behavioral bugs. Also fixes deploy.ts matchHeaders call that was missing reqCtx.
commit: |
|
Collaborator
Author
|
/bonk review please |
Contributor
There was a problem hiding this comment.
Clean, well-scoped change. All call sites already had reqCtx available — the only one missing it (deploy.ts line 601) is now fixed. Test updates correctly reflect the new semantics (the backward-compat test is rightly replaced with a test that verifies conditions are actually checked).
Verified:
- All callers in
index.ts(applyHeaders,applyRedirects,applyRewrites) already constructedreqCtxand passed it through — the wrapper signatures just now enforce what was already the practice. - All callers in
prod-server.tsalready passreqCtx(lines 828, 836, 854, 887, 906) — no changes needed there. - All callers in
deploy.ts(the generated Pages Router worker entry) already passreqCtxat lines 609, 623, 643, 660 — the one omission at line 601 (matchHeaders) is the bug this PR fixes. - Test coverage is good: the old backward-compat test ("keeps backward-compatible behavior when ctx is omitted") that asserted conditional rules were silently applied is replaced with a test that verifies they are properly skipped when the condition isn't met.
LGTM.
Contributor
|
PR #213 reviewed and approved. Summary: This is a clean, well-scoped fix. The change makes Key findings:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ctx: RequestContexta required parameter onmatchHeaders,matchRedirect, andmatchRewriteinconfig-matchers.ts(and their wrapper functions inindex.ts)deploy.tswherematchHeaderswas called withoutreqCtx(the only call site missing it)RequestContextinstead of relying on the previously optional parameterWhy
Next.js always has request context when evaluating
has/missingconditions. There is no code path where these matchers run without a request. Makingctxrequired:matchHas()takesreqas a required parameterExtracted from #134 by @erayack.