From fda6cf7838b6027a294b0c9cb1a15d3e9a21d46e Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Sat, 15 Jun 2024 22:52:04 +0100 Subject: [PATCH] fix(nuxt): unregister hooks the moment `close` is called (#27637) --- packages/nuxt/src/core/builder.ts | 8 +++++--- packages/nuxt/src/core/nuxt.ts | 7 +++---- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/packages/nuxt/src/core/builder.ts b/packages/nuxt/src/core/builder.ts index ca1b41dfd7..354829a28f 100644 --- a/packages/nuxt/src/core/builder.ts +++ b/packages/nuxt/src/core/builder.ts @@ -46,10 +46,12 @@ export async function build (nuxt: Nuxt) { if (!nuxt.options._prepare) { await Promise.all([checkForExternalConfigurationFiles(), bundle(nuxt)]) await nuxt.callHook('build:done') - } - if (!nuxt.options.dev) { - await nuxt.callHook('close', nuxt) + if (!nuxt.options.dev) { + await nuxt.callHook('close', nuxt) + } + } else { + nuxt.hook('prepare:types', () => nuxt.close()) } } diff --git a/packages/nuxt/src/core/nuxt.ts b/packages/nuxt/src/core/nuxt.ts index f70106a4f1..319324935c 100644 --- a/packages/nuxt/src/core/nuxt.ts +++ b/packages/nuxt/src/core/nuxt.ts @@ -49,14 +49,13 @@ export function createNuxt (options: NuxtOptions): Nuxt { addHooks: hooks.addHooks, hook: hooks.hook, ready: () => initNuxt(nuxt), - close: async () => { - await hooks.callHook('close', nuxt) - hooks.removeAllHooks() - }, + close: () => hooks.callHook('close', nuxt), vfs: {}, apps: {}, } + hooks.hookOnce('close', () => { hooks.removeAllHooks() }) + return nuxt }