Skip to content
Merged
Show file tree
Hide file tree
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
6 changes: 4 additions & 2 deletions packages/nuxi/src/commands/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,10 @@ const command = defineCommand({
// ... then fall back to pre-warmed fork if a hard restart is required
const fork = startSubprocess(cwd, ctx.args, ctx.rawArgs, listenOptions)
onRestart(async (devServer) => {
await devServer.close()
const subprocess = await fork
const [subprocess] = await Promise.all([
fork,
devServer.close().catch(() => {}),
])
await subprocess.initialize(devProxy, useSocket)
})

Expand Down
22 changes: 17 additions & 5 deletions packages/nuxi/src/dev/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,13 @@ interface InitializeOptions {
class IPC {
enabled = !!process.send && !process.title?.includes('vitest') && process.env.__NUXT__FORK
constructor() {
process.once('unhandledRejection', (reason) => {
this.send({ type: 'nuxt:internal:dev:rejection', message: reason instanceof Error ? reason.toString() : 'Unhandled Rejection' })
process.exit()
})
// only kill process if it is a fork
if (this.enabled) {
process.once('unhandledRejection', (reason) => {
this.send({ type: 'nuxt:internal:dev:rejection', message: reason instanceof Error ? reason.toString() : 'Unhandled Rejection' })
process.exit()
})
}
process.on('message', (message: NuxtParentIPCMessage) => {
if (message.type === 'nuxt:internal:dev:context') {
initialize(message.context, {}, message.socket ? undefined : true)
Expand Down Expand Up @@ -150,7 +153,16 @@ export async function initialize(devContext: NuxtDevContext, ctx: InitializeOpti
}
},
onRestart: (callback: (devServer: NuxtDevServer) => void) => {
devServer.once('restart', () => callback(devServer))
let restarted = false
function restart() {
if (!restarted) {
restarted = true
callback(devServer)
}
}
devServer.once('restart', restart)
process.once('uncaughtException', restart)
process.once('unhandledRejection', restart)
},
}
}
Loading