Skip to content

Commit a009c50

Browse files
committed
fix: check for root instance, fixes #1464
1 parent 82d4683 commit a009c50

File tree

1 file changed

+38
-33
lines changed
  • packages/app-backend-core/src

1 file changed

+38
-33
lines changed

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

Lines changed: 38 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -50,42 +50,47 @@ async function registerAppJob (options: AppRecordOptions, ctx: BackendContext) {
5050
}
5151

5252
// Create app record
53-
const id = getAppRecordId(options.app)
54-
const name = await ctx.api.getAppRecordName(options.app, id)
55-
record = {
56-
id,
57-
name,
58-
options,
59-
backend,
60-
lastInspectedComponentId: null,
61-
instanceMap: new Map(),
62-
rootInstance: await ctx.api.getAppRootInstance(options.app),
63-
perfGroupIds: new Map(),
64-
meta: options.meta ?? {}
65-
}
66-
options.app.__VUE_DEVTOOLS_APP_RECORD__ = record
67-
const rootId = `${record.id}:root`
68-
record.instanceMap.set(rootId, record.rootInstance)
69-
record.rootInstance.__VUE_DEVTOOLS_UID__ = rootId
70-
await ctx.api.registerApplication(record)
71-
ctx.appRecords.push(record)
72-
ctx.bridge.send(BridgeEvents.TO_FRONT_APP_ADD, {
73-
appRecord: mapAppRecord(record)
74-
})
75-
76-
if (backend.setupApp) {
77-
backend.setupApp(ctx.api, record)
78-
}
53+
const rootInstance = await ctx.api.getAppRootInstance(options.app)
54+
if (rootInstance) {
55+
const id = getAppRecordId(options.app)
56+
const name = await ctx.api.getAppRecordName(options.app, id)
57+
record = {
58+
id,
59+
name,
60+
options,
61+
backend,
62+
lastInspectedComponentId: null,
63+
instanceMap: new Map(),
64+
rootInstance,
65+
perfGroupIds: new Map(),
66+
meta: options.meta ?? {}
67+
}
68+
options.app.__VUE_DEVTOOLS_APP_RECORD__ = record
69+
const rootId = `${record.id}:root`
70+
record.instanceMap.set(rootId, record.rootInstance)
71+
record.rootInstance.__VUE_DEVTOOLS_UID__ = rootId
72+
await ctx.api.registerApplication(record)
73+
ctx.appRecords.push(record)
74+
ctx.bridge.send(BridgeEvents.TO_FRONT_APP_ADD, {
75+
appRecord: mapAppRecord(record)
76+
})
77+
78+
if (backend.setupApp) {
79+
backend.setupApp(ctx.api, record)
80+
}
7981

80-
if (appRecordPromises.has(options.app)) {
81-
for (const r of appRecordPromises.get(options.app)) {
82-
await r(record)
82+
if (appRecordPromises.has(options.app)) {
83+
for (const r of appRecordPromises.get(options.app)) {
84+
await r(record)
85+
}
8386
}
84-
}
8587

86-
// Auto select first app
87-
if (ctx.currentAppRecord == null) {
88-
await selectApp(record, ctx)
88+
// Auto select first app
89+
if (ctx.currentAppRecord == null) {
90+
await selectApp(record, ctx)
91+
}
92+
} else {
93+
console.warn('[Vue devtools] No root instance found for app, it might have been unmounted', options.app)
8994
}
9095

9196
break

0 commit comments

Comments
 (0)