From 335fc9f64b858682af37424b92c1a15de9efadeb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E5=92=B2=E6=99=BA=E5=AD=90?= Date: Thu, 1 Dec 2022 21:52:40 +0800 Subject: [PATCH] fix: cleanup command when hot reload --- composables/command.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/composables/command.ts b/composables/command.ts index 65c254f9..e8025f87 100644 --- a/composables/command.ts +++ b/composables/command.ts @@ -175,9 +175,10 @@ export const useCommand = (cmd: CommandProvider) => { registry.register(cmd) - onDeactivated(() => { - registry.remove(cmd) - }) + const cleanup = () => registry.remove(cmd) + + onDeactivated(cleanup) + tryOnScopeDispose(cleanup) } export const useCommands = (cmds: () => CommandProvider[]) => { @@ -192,9 +193,12 @@ export const useCommands = (cmds: () => CommandProvider[]) => { registry.register(cmd) }, { deep: true, immediate: true }) - onDeactivated(() => { + const cleanup = () => { commands.value.forEach(cmd => registry.remove(cmd)) - }) + } + + onDeactivated(cleanup) + tryOnScopeDispose(cleanup) } export const provideGlobalCommands = () => {