Repository navigation
Description
Environment
- Nitro:
3.0.260610-beta - Vite:
8.2.2 - Node.js:
v24.20.0 - macOS:
26.6.2, arm64 - Official
nitrojs/starterVite template, usingnitro/vitewith the default development runner. No Nuxt or other framework. - Also inspected Nitro main at
c5177e9218cdd113c6c6a6a74b2924b2354af120; the Vite worker's shutdown handler is still empty there. The runtime reproduction below was executed with the published beta listed above.
Reproduction
Ready-to-run repository: https://github.com/cprecioso/nitro-vite-close-repro
Based on the official Nitro Vite starter, with a runtime lifecycle plugin, pinned dependencies, and automated checks added.
git clone https://github.com/cprecioso/nitro-vite-close-repro.git
cd nitro-vite-close-repro
npm ci
npm run reproThe check initializes the plugin and makes successful requests to the starter API before testing two independent shutdown paths:
- Sending SIGINT to the Vite CLI process (equivalent to Ctrl+C).
- Explicitly awaiting Vite's
server.close()API.
Expected: each shutdown invokes the runtime plugin's close hook once.
Actual: both checks record only initialization. npm run repro exits with code 1. The hook writes synchronously to a file, so this does not depend on async cleanup finishing or console output being flushed. The API check also waits 500 ms after server.close() resolves before checking. Child processes are cleaned up after the assertions.
For a manual check, run npm run dev, visit /api/hello, press Ctrl+C, and inspect lifecycle.log. It contains init, but no close.
Describe the bug
Runtime plugin cleanup is skipped when stopping the Vite development server. The same omission occurs when starting Vite through createServer(), making a successful request, and explicitly awaiting server.close(): that promise resolves without the Nitro runtime close callback running.
This prevents plugins from relying on the documented runtime hook to release resources during Vite development shutdown.
Additional context
- In the Vite worker,
ipc.onClose()is empty. - The separate non-Vite development entry explicitly calls
nitroHooks.callHook("close")on worker shutdown. - Related: Nitro close hook is not called on shutdown with the Vite integration and Bun preset #4479 and
node_serverpreset does not call theclosehook on shutdown (regression from v2) #4502 concern production preset shutdown. This report concerns the Vite development runner. - Prepared with AI assistance; the reproduction was executed locally.
Logs
FAIL SIGINT: expected ["init","close"], got ["init"]
FAIL server.close(): expected ["init","close"], got ["init"]
Activity
benpsnyder commentedon Sep 7, 2026
Confirmed a related build-time lifecycle omission with Nitro
3.0.260903-betaon Node24.15.0: awaiting Viteserver.close()does not invoke the Nitro configurationhooks.closecallback. This is separate from the runtime hook reported above.Minimal check inside a project with
viteandnitroinstalled:In an isolated fixture, explicitly closing the retained Nitro instance invokes the callback. analogjs/analog#2535 passes all Windows HTTP/rendering assertions but retains filesystem resources after shutdown. This lifecycle omission is a candidate cause; the Windows causal link is not yet verified.
Use case: programmatic Vite servers in integration tests need shutdown to release Nitro watchers and resources.
Suggested AI prompt: “Reproduce the missing build-time Nitro close hook with programmatic Vite startup/shutdown. Trace ownership separately from runtime worker hooks, implement awaited cleanup exactly once, and test restart plus Windows process exit without forcing a successful exit.”