Repository navigation
fix(rsc): skip unparseable request URLs in dev middleware - #1525
Open
nbozidarevic wants to merge 1 commit into
Open
nbozidarevic wants to merge 1 commit into
nbozidarevic wants to merge 1 commit into
Conversation
The rsc:findSourceMapURL and vite-rsc-load-module-dev-proxy dev middlewares parse every request URL with new URL(). Requests like // or //[ are valid HTTP but do not parse, and the throw inside an async Connect middleware becomes an unhandled rejection that kills the whole dev server. Parse through a shared helper that returns undefined on failure; both middlewares pass the request down the chain instead.
This branch has not been deployed
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.
Problem
The
rsc:findSourceMapURLandvite-rsc-load-module-dev-proxydev middlewares parse every incoming request URL withnew URL(). Some request targets are valid HTTP but do not parse as URLs — for example//or//[(a client probing the server root, or a mangled proxy path). The throw happens inside an async Connect middleware with no catch, so it surfaces as an unhandled rejection and kills the whole dev server process.Repro: start any plugin-rsc dev server (e.g. the
starterexample withpnpm dev), then in another shell:On the unpatched build this throws
TypeError [ERR_INVALID_URL]: Invalid URLfromdist/plugin-*.js(thefindSourceMapURLmiddleware).Fix
Parse through a shared helper (
parseRequestUrlinplugins/vite-utils) that returnsundefinedwhen the URL does not parse; both middlewares pass the request down the chain withnext()instead of throwing. Unparseable requests fall through to Vite's own handling rather than crashing the server.Testing
plugins/vite-utils.test.tscover normal URLs (/, the findSourceMapURL endpoint,undefined) and the/////[cases.starterexample dev server: with the fix,curl --path-as-is //returns 200 and the server keeps serving subsequent requests, with no errors in the log.src/transforms+src/plugins, 527 tests) green. Package typecheck shows only the pre-existing example errors that also occur on cleanmain(missing built sibling types beforepnpm build).