diff --git a/packages/astro/src/vite-plugin-astro-server/plugin.ts b/packages/astro/src/vite-plugin-astro-server/plugin.ts index 89ff91b5a53e..706e8924500e 100644 --- a/packages/astro/src/vite-plugin-astro-server/plugin.ts +++ b/packages/astro/src/vite-plugin-astro-server/plugin.ts @@ -61,11 +61,6 @@ export default function createVitePluginAstroServer({ ? (prerenderEnvironment as RunnableDevEnvironment) : undefined; - // TODO: let this handle non-runnable environments that don't intercept requests - if (!runnableSsrEnvironment && !runnablePrerenderEnvironment) { - return; - } - async function createHandler(environment: RunnableDevEnvironment) { const loader = createViteLoader(viteServer, environment); const { default: createAstroServerApp } = @@ -117,20 +112,18 @@ export default function createVitePluginAstroServer({ } } - process.on('unhandledRejection', handleUnhandledRejection); - viteServer.httpServer?.on('close', () => { - process.off('unhandledRejection', handleUnhandledRejection); - }); + if (ssrHandler || prerenderHandler) { + process.on('unhandledRejection', handleUnhandledRejection); + viteServer.httpServer?.on('close', () => { + process.off('unhandledRejection', handleUnhandledRejection); + }); + } return () => { const shouldHandlePrerenderInCore = Boolean( (viteServer as any)[devPrerenderMiddlewareSymbol], ); - if (!ssrHandler && !(prerenderHandler && shouldHandlePrerenderInCore)) { - return; - } - // Push this middleware to the front of the stack so that it can intercept responses. // fix(#6067): always inject this to ensure zombie base handling is killed after restarts viteServer.middlewares.stack.unshift({