Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/build/vite/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,11 @@ export async function configureViteDevServer(ctx: NitroPluginContext, server: Vi
if (nodeRes.writableEnded || nodeRes.headersSent) {
return;
}
if (envRes.status === 404) {
// Allow Vite to try
nodeReq._nitroHandled = false;
return next();
}
Comment on lines +225 to +229
Copy link

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()).

return await sendNodeResponse(nodeRes, envRes);
} catch (error) {
return next(error);
Expand All @@ -236,8 +241,6 @@ export async function configureViteDevServer(ctx: NitroPluginContext, server: Vi
if (
// Originating from browser tab or no fetch dest (curl, fetch, etc) and (not script, style, image, etc)
(!fetchDest || /^(document|iframe|frame|empty)$/.test(fetchDest)) &&
// No file extension (not /src/index.ts)
!req.url!.match(/\.([a-z0-9]+)(?:[?#]|$)/i)?.[1] &&
// Special prefixes (/__vue-router/auto-routes, /@vite-plugin-layouts/, etc)
!/^\/(?:__|@)/.test(req.url!)
) {
Expand Down
Loading