refactor(server): dedupe forbidden response construction - #1071
Merged
Conversation
Extract the repeated `new Response("Forbidden", { status: 403, ... })`
pattern from dev-origin-check.ts and request-pipeline.ts into a single
shared helper. Follow-up to #1049.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
commit: |
Contributor
|
Member
Author
|
/bigbonk review |
Contributor
There was a problem hiding this comment.
Clean dedupe. The split between an exported forbiddenResponse() for importable TS code and an inline __forbidden() inside the codegen template is the right call — the generated JS can't import .ts modules, so a local helper is the only option there.
Verified: all 7 original new Response("Forbidden", …) literals are accounted for (3 in request-pipeline.ts, 4 in dev-origin-check.ts), and the replacement is byte-equivalent.
No notes.
Contributor
|
Approved PR #1071. The refactor is straightforward and correct:
All 7 call sites accounted for, no behavior change. |
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
new Response("Forbidden", { status: 403, headers: { "Content-Type": "text/plain" } })was repeated 7 times across two server files.forbiddenResponse()helper inrequest-pipeline.tsand replaces the 3 byte-identical call sites invalidateCsrfOrigin.generateDevOriginCheckCode()— which emits inline JS that runs in the RSC Vite environment and cannot import TS modules — introduces a local__forbidden()helper inside the generated code so the duplication is eliminated there too.Touched files
packages/vinext/src/server/request-pipeline.ts— adds exportedforbiddenResponse(); replaces 3 inline literals.packages/vinext/src/server/dev-origin-check.ts— emits a local__forbidden()helper inside the codegen template; replaces 4 inline literals in the generated JS.Test plan
pnpm vp test run tests/app-router.test.ts tests/pages-router.test.ts— 508 tests pass. (One unrelatedafterAllcleanup-hook timeout under heavy concurrent load; reruns of the touched suite, includingPages Router allowedDevOrigins config, all pass.)pnpm fmt:check— clean.🤖 Generated with Claude Code