Skip to content

Commit

Permalink
fix: disconnect when all apps are unmount
Browse files Browse the repository at this point in the history
  • Loading branch information
alexzhang1030 committed Apr 30, 2024
1 parent cdd7a29 commit acd0ae8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
7 changes: 6 additions & 1 deletion packages/devtools-kit/src/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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])
Expand Down
8 changes: 5 additions & 3 deletions packages/playground/multi-app/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit acd0ae8

Please sign in to comment.