Skip to content

Commit 3d5fb53

Browse files
committed
fix: remove app on unmount, fixes #1455
1 parent 57d3e7b commit 3d5fb53

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

packages/app-backend-core/src/app.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,15 @@ export async function sendApps (ctx: BackendContext) {
131131
})
132132
}
133133

134+
export function removeApp (app: any, ctx: BackendContext) {
135+
const appRecord = getAppRecord(app, ctx)
136+
if (appRecord) {
137+
const index = ctx.appRecords.indexOf(appRecord)
138+
if (index !== -1) ctx.appRecords.splice(index, 1)
139+
ctx.bridge.send(BridgeEvents.TO_FRONT_APP_REMOVE, { id: appRecord.id })
140+
}
141+
}
142+
134143
// eslint-disable-next-line camelcase
135144
export async function _legacy_getAndRegisterApps (Vue: any, ctx: BackendContext) {
136145
const apps = scan()

packages/app-backend-core/src/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import {
3030
} from './component'
3131
import { addQueuedPlugins, addPlugin, sendPluginList, addPreviouslyRegisteredPlugins } from './plugin'
3232
import { PluginDescriptor, SetupFunction, TimelineLayerOptions, TimelineEventOptions, CustomInspectorOptions } from '@vue/devtools-api'
33-
import { registerApp, selectApp, waitForAppsRegistration, sendApps, _legacy_getAndRegisterApps, getAppRecord } from './app'
33+
import { registerApp, selectApp, waitForAppsRegistration, sendApps, _legacy_getAndRegisterApps, getAppRecord, removeApp } from './app'
3434
import { sendInspectorTree, getInspector, getInspectorWithAppId, sendInspectorState, editInspectorState, sendCustomInspectors } from './inspector'
3535
import { showScreenshot } from './timeline-screenshot'
3636
import { handleAddPerformanceTag, performanceMarkEnd, performanceMarkStart } from './perf'
@@ -121,6 +121,10 @@ async function connect () {
121121
}
122122
})
123123

124+
hook.on(HookEvents.APP_UNMOUNT, app => {
125+
removeApp(app, ctx)
126+
})
127+
124128
// Components
125129

126130
ctx.bridge.on(BridgeEvents.TO_BACK_COMPONENT_TREE, ({ instanceId, filter }) => {

packages/shell-dev-vue3/src/main.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,17 @@ app.use(store)
3232
app.use(TestPlugin)
3333
app.mount('#app')
3434

35-
createApp({
35+
const app2 = createApp({
3636
render: () => h('h1', 'App 2')
37-
}).mount('#app2')
37+
})
38+
app2.mount('#app2')
3839

3940
createApp(App3).mount('#app3')
4041

4142
createApp({
42-
render: () => h('h1', 'Ghost app'),
43+
render: () => h('button', {
44+
onClick: () => app2.unmount()
45+
}, 'Remove app 2'),
4346
devtools: {
4447
hide: true
4548
}

0 commit comments

Comments
 (0)