From acd0ae8a5093317d2903180e573843d8188152e4 Mon Sep 17 00:00:00 2001 From: Alex Date: Tue, 30 Apr 2024 17:13:34 +0800 Subject: [PATCH] fix: disconnect when all apps are unmount --- packages/devtools-kit/src/core/index.ts | 7 ++++++- packages/playground/multi-app/src/main.ts | 8 +++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/packages/devtools-kit/src/core/index.ts b/packages/devtools-kit/src/core/index.ts index c85af3b1..05d81645 100644 --- a/packages/devtools-kit/src/core/index.ts +++ b/packages/devtools-kit/src/core/index.ts @@ -56,7 +56,7 @@ export function initDevTools() { }, ] - if (devtoolsAppRecords.value.length === 1) { + if (devtoolsAppRecords.value.length >= 1) { await setActiveAppRecord(devtoolsAppRecords.value[0]) devtoolsState.connected = true devtoolsHooks.callHook(DevToolsHooks.APP_CONNECTED) @@ -65,6 +65,11 @@ export function initDevTools() { hook.on.vueAppUnmount(async (app) => { const activeRecords = devtoolsAppRecords.value.filter(appRecord => appRecord.app !== app) + // #356 should disconnect when all apps are unmounted + if (activeRecords.length === 0) { + devtoolsState.connected = false + return + } devtoolsAppRecords.value = activeRecords if (devtoolsAppRecords.active.app === app) await setActiveAppRecord(activeRecords[0]) diff --git a/packages/playground/multi-app/src/main.ts b/packages/playground/multi-app/src/main.ts index 61ab5943..65ea9acb 100644 --- a/packages/playground/multi-app/src/main.ts +++ b/packages/playground/multi-app/src/main.ts @@ -8,8 +8,10 @@ import 'uno.css' const app = createApp(App) -const app2 = createApp(App2) - app.mount('#app') -app2.mount('#app2') +setTimeout(() => { + app.unmount() + app.mount('#app') + createApp(App2).mount('#app2') +}, 500)