Skip to content

fix(vite): remove extension check to support dotted API routes - #3994

Closed
kricsleo wants to merge 1 commit into
nitrojs:mainfrom
kricsleo:fix/url-extension
Closed

kricsleo wants to merge 1 commit into
nitrojs:mainfrom
kricsleo:fix/url-extension

Conversation

@kricsleo

@kricsleo kricsleo commented Feb 1, 2026

Copy link
Copy Markdown
Member

🔗 Linked issue

resolves #3990

❓ 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

Removed overly broad extension check that broke routes like /api/foo.get. Added 404 fallback to Vite instead.

📝 Checklist

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

@kricsleo
kricsleo requested a review from pi0 as a code owner February 1, 2026 12:22
@vercel

vercel Bot commented Feb 1, 2026

Copy link
Copy Markdown

@kricsleo is attempting to deploy a commit to the Nitro Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Feb 1, 2026 •

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

Modified the Vite dev middleware to add a 404 fallback mechanism that delegates unhandled requests to the next middleware (allowing Vite to process them) and removed extension-based filtering that previously blocked extension-less URLs from reaching the Nitro/dev pipeline.

Changes

Cohort / File(s) Summary
Vite Dev Middleware
src/build/vite/dev.ts
Added 404 fallback logic that resets nodeReq._nitroHandled and delegates to next middleware; removed extension-based request filtering in both pre-middleware and main middleware paths.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description check ✅ Passed The description is related to the changeset, explaining the removal of the extension check and the 404 fallback mechanism to address dotted API route issues.
Linked Issues check ✅ Passed The PR addresses the core objective from issue #3990: removing the extension check that incorrectly treats dotted API routes as static assets, enabling proper routing for nested tRPC procedures.
Out of Scope Changes check ✅ Passed All changes in src/build/vite/dev.ts are directly related to fixing the dotted API route issue by removing the extension check and adding 404 fallback to Vite.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Title check ✅ Passed The title uses the Conventional Commits format with the valid type fix, scope vite, and a description that accurately summarizes the extension-check removal and dotted API route support.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@src/build/vite/dev.ts`:
- Around line 225-229: The handler that checks envRes.status === 404 should not
reset nodeReq._nitroHandled because that lets the request be processed again by
nitroDevMiddleware; instead, remove the line that sets nodeReq._nitroHandled =
false and simply call next() so Vite can handle the fallback while leaving the
Nitro-handled flag intact (change the branch in the envRes.status === 404 block
that references nodeReq._nitroHandled and next()).

Comment thread src/build/vite/dev.ts
Comment on lines +225 to +229
if (envRes.status === 404) {
// Allow Vite to try
nodeReq._nitroHandled = false;
return next();
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Avoid re-running Nitro middleware after 404 fallback.

Resetting nodeReq._nitroHandled allows the same request to hit the later nitroDevMiddleware (registered at the end), duplicating Nitro dispatch for 404s. Keeping the flag set still lets Vite handle via next().

🔧 Suggested change
       if (envRes.status === 404) {
         // Allow Vite to try
-        nodeReq._nitroHandled = false;
         return next();
       }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (envRes.status === 404) {
// Allow Vite to try
nodeReq._nitroHandled = false;
return next();
}
if (envRes.status === 404) {
// Allow Vite to try
return next();
}
🤖 Prompt for AI Agents
In `@src/build/vite/dev.ts` around lines 225 - 229, The handler that checks
envRes.status === 404 should not reset nodeReq._nitroHandled because that lets
the request be processed again by nitroDevMiddleware; instead, remove the line
that sets nodeReq._nitroHandled = false and simply call next() so Vite can
handle the fallback while leaving the Nitro-handled flag intact (change the
branch in the envRes.status === 404 block that references nodeReq._nitroHandled
and next()).

@pkg-pr-new

pkg-pr-new Bot commented Feb 1, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/nitrojs/nitro@3994

commit: 31c89bf

@pi0x pi0x added the bug Something isn't working (PRs; issues use the Bug type) label Sep 2, 2026
@pi0x pi0x changed the title fix(vite): remove extension check to support dotted API routes fix(vite): remove extension check to support dotted API routes Sep 2, 2026
@pi0x pi0x added the v3 label Sep 2, 2026
@pi0

pi0 commented Sep 3, 2026

Copy link
Copy Markdown
Member

Appreciate the PR. It should be fixed on main (#4108)

@pi0 pi0 closed this Sep 3, 2026
@pi0x pi0x removed the v3 label Nov 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working (PRs; issues use the Bug type)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

infinite redirect with baseUrl + nested tRPC procedure

3 participants