Skip to content

fix(vite): route dev handlers + proxies before vite base rewrite - #4734

Merged
pi0 merged 2 commits into
mainfrom
fix/vite-base-dev-handlers
Oct 6, 2026
Merged

pi0 merged 2 commits into
mainfrom
fix/vite-base-dev-handlers

Conversation

@danielroe

Copy link
Copy Markdown
Member

🔗 Linked issue

❓ Type of change

  • 📖 Documentation (updates to the documentation, readme, or JSdoc annotations)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • 👌 Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

📚 Description

noticed this when updating Nuxt 5 support in nuxt/fonts, where we register a dev handler under /_nuxt/ (which is the vite base).

with a dev handler at /_nuxt/probe/**, GET /_nuxt/probe/a reaches the handler but GET /_nuxt/probe/a.woff2 (or /_nuxt/probe/a with sec-fetch-dest: font) ends in connect's 404 page, and the handler is never called. devProxy routes under the base behave the same way.

I think this is because nitroDevMiddlewarePre only treats nitro.routing matches as explicit routes, and dev handlers and proxies aren't in there. so the request is classed as an asset and handed to vite - and vite strips base from req.url, so the route no longer matches...

this PR treats dev handler and devProxy routes (excluding middleware and root catch-alls) as explicit, the same way explicit nitro.routing routes are, so they reach Nitro before vite rewrites the URL.

... but you may also have another better approach! 🙏

📝 Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@danielroe
danielroe requested a review from pi0 as a code owner October 6, 2026 13:37
@vercel

vercel Bot commented Oct 6, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
nitro.build Ready Ready Preview Oct 6, 2026 2:41pm UTC

Request Review

@danielroe
danielroe force-pushed the fix/vite-base-dev-handlers branch from c66e896 to d537974 Compare October 6, 2026 13:37
@danielroe danielroe changed the title fix(vite): route dev handlers before vite base rewrite fix(vite): route dev handlers + proxies before vite base rewrite Oct 6, 2026
@coderabbitai

coderabbitai Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: f283a593-ae91-4b42-9f42-eaf0c78c0f05
📥 Commits

Reviewing files that changed from the base of the PR and between d537974 and 154a4dc.

📒 Files selected for processing (3)
  • src/build/vite/dev.ts
  • test/vite/base-dev-handlers-fixture/vite.config.ts
  • test/vite/base-dev-handlers.test.ts
 _____________________________
< My other GPU is a Blackwell >
 -----------------------------
  \
   \   (\__/)
       (•ㅅ•)
       /   づ

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 0f56c4f2-3172-4b69-8f7a-2acd46806bbc
📥 Commits

Reviewing files that changed from the base of the PR and between 6bb682e and d537974.

📒 Files selected for processing (5)
  • src/build/vite/dev.ts
  • test/vite/base-dev-handlers-fixture/client.ts
  • test/vite/base-dev-handlers-fixture/index.html
  • test/vite/base-dev-handlers-fixture/vite.config.ts
  • test/vite/base-dev-handlers.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

The Vite development server now considers matching development-handler and proxy routes during explicit-route detection. New fixture tests cover asset-like requests handled by development routes, a proxy, and a Vite client asset.

Changes

Vite dev-handler routing

Layer / File(s) Summary
Register and match development routes
src/build/vite/dev.ts
The dev server registers routed, non-middleware handlers and development proxy routes, excluding root catch-alls. Explicit-route detection now includes matches from this router.
Exercise routes in the Vite fixture
test/vite/base-dev-handlers-fixture/*, test/vite/base-dev-handlers.test.ts
The fixture configures probe, catch-all, and proxy routes, plus HTML and client assets. Tests check development-handler and upstream responses for asset-like requests and JavaScript content for a script request.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Merge Risk: ⚪ Minimal · up to d5379

The change is ready to merge after normal checks; no actionable routing regression was identified.

Security Architecture Review

Security architecture risk: 🔵 Low · up to d5379

The change is confined to development routing and configured proxy destinations. No introduced vulnerability was established, but protection by Vite host or origin checks cannot be assumed for requests handled earlier in the middleware chain.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — A caller able to reach the development server can now route additional asset-like requests to application-configured development handlers or proxy destinations. Effective authority depends on those handlers and upstream services; the fixture exposes only probe responses and a loopback upstream, not production tenant or datastore authority.

Trust Boundaries and Controls

  • inferred — Successful early development-handler or proxy responses do not traverse downstream Vite asset processing or Nitro environment dispatch. Controls attached exclusively to those downstream paths therefore cannot protect those responses. Actual Vite host/origin enforcement order remains unverified, so this is not a verified host-policy bypass.
  • observed — Early Nitro dispatch already existed for explicit runtime routes and qualifying non-asset requests. Nitro's Vite configuration also already disabled Vite CORS. Those conditions predate this PR; the introduced change is the larger set of requests receiving early dispatch.

Hardening Proposals

  • proposed — Verify hostile Host and Origin handling for directly intercepted development routes across supported Vite versions before relying on inherited Vite protections. If such restrictions are intended, enforce them at a boundary reached before both early Nitro responses and Vite processing.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title follows the Conventional Commits format with the fix(vite) type and scope. It accurately summarizes the routing change.
Description check ✅ Passed The description explains the Vite base-path issue and how the change routes development handlers and proxies before Vite rewrites the URL.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 4 files. (1 skipped: 1 …
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@pkg-pr-new

pkg-pr-new Bot commented Oct 6, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/nitro@4734

commit: 154a4dc

…eURL`

A dev handler 404 for an asset-like request no longer falls through to the SSR renderer, and a dev handler catch-all under a non-root `baseURL` (e.g. `/app/**`) no longer swallows Vite modules.
@pi0
pi0 merged commit 8523bac into main Oct 6, 2026
14 of 15 checks passed
@pi0
pi0 deleted the fix/vite-base-dev-handlers branch October 6, 2026 14:46
@pi0x pi0x removed the v3 label Nov 10, 2026

This branch was successfully deployed

1 active deployment
Preview — 154a4dcf Deployed Oct 6, 2026 by vercel[bot]
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.

3 participants