fix(vite): handle dotted Nitro routes under baseURL in dev#4108
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughNormalizes incoming dev request URLs with the configured baseURL and detects Nitro routes (including splat routes with dotted params) before treating requests as static assets; restores the original request URL after handling. Adds a fixture and integration test for dotted splat params under a subdirectory base. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related issues
Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
commit: |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
test/vite/baseurl-dotted-param.test.ts (1)
15-29: Consider restoring the original working directory inafterAll.
process.chdir(rootDir)modifies global process state. While the test is markedsequential, restoring the cwd in the teardown would improve isolation and prevent potential side effects on subsequent test files.♻️ Suggested improvement
+ let originalCwd: string; + beforeAll(async () => { + originalCwd = process.cwd(); process.chdir(rootDir); server = await createServer({ root: rootDir }); await server.listen("0" as unknown as number); const addr = server.httpServer?.address() as { port: number; address: string; family: string; }; serverURL = `http://${addr.family === "IPv6" ? `[${addr.address}]` : addr.address}:${addr.port}`; }, 30_000); afterAll(async () => { await server?.close(); + if (originalCwd) { + process.chdir(originalCwd); + } });🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@test/vite/baseurl-dotted-param.test.ts` around lines 15 - 29, The test changes the process cwd in beforeAll via process.chdir(rootDir) but never restores it; capture the original working directory (e.g., const originalCwd = process.cwd()) before calling process.chdir in the beforeAll block and then restore it in afterAll (call process.chdir(originalCwd)) alongside closing the server in the existing afterAll to avoid leaking global state; update the beforeAll/afterAll in this test file (the hooks named beforeAll and afterAll in test/vite/baseurl-dotted-param.test.ts) accordingly.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@test/vite/baseurl-dotted-param.test.ts`:
- Around line 15-29: The test changes the process cwd in beforeAll via
process.chdir(rootDir) but never restores it; capture the original working
directory (e.g., const originalCwd = process.cwd()) before calling process.chdir
in the beforeAll block and then restore it in afterAll (call
process.chdir(originalCwd)) alongside closing the server in the existing
afterAll to avoid leaking global state; update the beforeAll/afterAll in this
test file (the hooks named beforeAll and afterAll in
test/vite/baseurl-dotted-param.test.ts) accordingly.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 6033fe32-8363-4d31-9607-44c65e872049
📒 Files selected for processing (6)
src/build/vite/dev.tstest/vite/baseurl-dotted-param-fixture/api/proxy/[...param].tstest/vite/baseurl-dotted-param-fixture/index.htmltest/vite/baseurl-dotted-param-fixture/tsconfig.jsontest/vite/baseurl-dotted-param-fixture/vite.config.tstest/vite/baseurl-dotted-param.test.ts
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/build/vite/dev.ts`:
- Around line 203-207: The dev server applies withBase(nodeReq.url, baseURL) too
early which lets unbased requests like /api/proxy/... match routes that should
require the base (e.g., /subdir/api/proxy/...), causing dev/production
divergence; update the pre-check in src/build/vite/dev.ts to use the raw request
pathname (nodeReq.url or req.url) when testing route matches (i.e., do not call
withBase(...) for the initial match) so unbased URLs are rejected when
nitro.options.baseURL is set, and add a regression test (e.g., extend
test/vite/baseurl-dotted-param.test.ts) asserting that an unbased URL fails or
behaves identically to production when baseURL="/subdir".
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: bac1297a-d13a-4fe2-a9ce-452c0af4e2bf
📒 Files selected for processing (1)
src/build/vite/dev.ts
test document/empty/undefined fetch destinations to ensure the nitroDevMiddlewarePre fix is exercised (not just the catch-all)
fixes TanStack/router#6903