Skip to content

fix(rsc): skip unparseable request URLs in dev middleware - #1525

Open
nbozidarevic wants to merge 1 commit into
vitejs:mainfrom
nbozidarevic:fix-rsc-unparseable-url-middleware
Open

nbozidarevic wants to merge 1 commit into
vitejs:mainfrom
nbozidarevic:fix-rsc-unparseable-url-middleware

Conversation

@nbozidarevic

@nbozidarevic nbozidarevic commented Oct 21, 2026 •

Copy link
Copy Markdown

Problem

The rsc:findSourceMapURL and vite-rsc-load-module-dev-proxy dev middlewares parse every incoming request URL with new 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 starter example with pnpm dev), then in another shell:

curl --path-as-is http://localhost:<port>//

On the unpatched build this throws TypeError [ERR_INVALID_URL]: Invalid URL from dist/plugin-*.js (the findSourceMapURL middleware).

Fix

Parse through a shared helper (parseRequestUrl in plugins/vite-utils) that returns undefined when the URL does not parse; both middlewares pass the request down the chain with next() instead of throwing. Unparseable requests fall through to Vite's own handling rather than crashing the server.

Testing

  • New unit tests in plugins/vite-utils.test.ts cover normal URLs (/, the findSourceMapURL endpoint, undefined) and the // / //[ cases.
  • Verified end to end against the starter example dev server: with the fix, curl --path-as-is // returns 200 and the server keeps serving subsequent requests, with no errors in the log.
  • Full plugin-rsc unit suite (src/transforms + src/plugins, 527 tests) green. Package typecheck shows only the pre-existing example errors that also occur on clean main (missing built sibling types before pnpm build).

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

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant