Repository navigation
Description
Describe the feature
Some integrations requires write/build some assets after copying public assets and/or prerender process. My example is PWA integration at tanstack start where we're using nitro v3 vite plugin.
Right now, nitro prerender process can be skipped even being triggered, missing hook about cancelling, for context: since any nitro module can remove all the prerender routes (without crawling), the prerender process is silently removed from the pipeline, but some prerender hooks triggered.
My integration at tanstack start uses nitro compiled hook, but nitro has been closed, and so I have no idea if we can have some side effects.
I guess we should add a new hook before:close to be triggered after prerender:done but before closing nitro here https://github.com/nitrojs/nitro/blob/main/src/build/vite/prod.ts#L110
For more context: at nuxt integration (nuxt <5), we use this logic in the nuxt module:
Nuxt PWA module and nitro hooks to build the service worker
if (!nuxt.options.dev) {
if (semver.gte(ctx.nuxt.nuxtVersion, '3.8.0')) {
nuxt.hook('nitro:build:public-assets', async () => {
await buildPwaAssets(ctx as unknown as any)
})
}
else {
nuxt.hook('nitro:init', (nitro) => {
nitro.hooks.hook('rollup:before', async () => {
await buildPwaAssets(ctx as unknown as any)
})
})
if (nuxt.options.nitro.static || (nuxt.options as any)._generate /* TODO: remove in future */) {
nuxt.hook('close', async () => {
await buildPwaAssets(ctx as unknown as any)
})
}
}
}
You can see nuxt nitro:build:public-assets hook here (not sure yet how nuxt integrates nitro v3): https://github.com/nuxt/nuxt/blob/c8d7662e549177da82d6b50501b24bf5c08a9155/packages/nitro-server/src/legacy.ts#L17
Additional information
- Would you be willing to help implement this feature?
Activity
userquin commentedon Jul 16, 2026
We also need to:
compressPublicAssetsat prerender module after the newbefore:closehook: any assets written after prerender but before closing nitro won't be compressedpi0x commentedon Sep 7, 2026
Confirmed, and it looks like a plain ordering bug rather than a missing hook. In the Vite production build Nitro is closed before the
compiledhook runs (src/build/vite/prod.ts:await nitro.close()thencallHook("compiled")). The CLI/rollup/rolldown path does the opposite —compiledfires insidebuild(), andnitro.close()comes after. So yourcompiledhandler only sees a closed instance under Vite.Posted by an AI triage agent on behalf of a maintainer.