Skip to content

Commit 8bb2654

Browse files
committed
fix: improved hidden app handling
1 parent 9cb596c commit 8bb2654

File tree

1 file changed

+24
-18
lines changed
  • packages/app-backend-core/src

1 file changed

+24
-18
lines changed

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

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ async function registerAppJob (options: AppRecordOptions, ctx: BackendContext) {
4848
async function createAppRecord (options: AppRecordOptions, backend: DevtoolsBackend, ctx: BackendContext) {
4949
const rootInstance = await backend.api.getAppRootInstance(options.app)
5050
if (rootInstance) {
51+
if ((await backend.api.getComponentDevtoolsOptions(rootInstance)).hide) {
52+
return
53+
}
54+
5155
recordId++
5256
const name = await backend.api.getAppRecordName(options.app, recordId.toString())
5357
const id = getAppRecordId(options.app, slug(name))
@@ -66,6 +70,7 @@ async function createAppRecord (options: AppRecordOptions, backend: DevtoolsBack
6670
iframe: document !== el.ownerDocument ? el.ownerDocument.location.pathname : null,
6771
meta: options.meta ?? {},
6872
}
73+
6974
options.app.__VUE_DEVTOOLS_APP_RECORD__ = record
7075
const rootId = `${record.id}:root`
7176
record.instanceMap.set(rootId, record.rootInstance)
@@ -82,13 +87,9 @@ async function createAppRecord (options: AppRecordOptions, backend: DevtoolsBack
8287

8388
await backend.api.registerApplication(options.app)
8489

85-
const isAppHidden = !!(await record.backend.api.getComponentDevtoolsOptions(record.rootInstance)).hide
86-
87-
if (!isAppHidden) {
88-
ctx.bridge.send(BridgeEvents.TO_FRONT_APP_ADD, {
89-
appRecord: mapAppRecord(record),
90-
})
91-
}
90+
ctx.bridge.send(BridgeEvents.TO_FRONT_APP_ADD, {
91+
appRecord: mapAppRecord(record),
92+
})
9293

9394
if (appRecordPromises.has(options.app)) {
9495
for (const r of appRecordPromises.get(options.app)) {
@@ -97,7 +98,7 @@ async function createAppRecord (options: AppRecordOptions, backend: DevtoolsBack
9798
}
9899

99100
// Auto select first app
100-
if (ctx.currentAppRecord == null && !isAppHidden) {
101+
if (ctx.currentAppRecord == null) {
101102
await selectApp(record, ctx)
102103
}
103104
} else {
@@ -151,22 +152,29 @@ export async function getAppRecord (app: any, ctx: BackendContext): Promise<AppR
151152
return record
152153
}
153154
return new Promise((resolve, reject) => {
154-
let timedOut = false
155-
const timer = setTimeout(() => {
156-
timedOut = true
157-
reject(new Error(`Timed out getting app record for app ${app}`))
158-
}, 2000)
159155
let resolvers = appRecordPromises.get(app)
156+
let timedOut = false
160157
if (!resolvers) {
161158
resolvers = []
162159
appRecordPromises.set(app, resolvers)
163160
}
164-
resolvers.push((record) => {
161+
const fn = (record) => {
165162
if (!timedOut) {
166163
clearTimeout(timer)
167164
resolve(record)
168165
}
169-
})
166+
}
167+
resolvers.push(fn)
168+
const timer = setTimeout(() => {
169+
timedOut = true
170+
const index = resolvers.indexOf(fn)
171+
if (index !== -1) resolvers.splice(index, 1)
172+
if (SharedData.debugInfo) {
173+
// eslint-disable-next-line no-console
174+
console.log('Timed out waiting for app record', app)
175+
}
176+
reject(new Error(`Timed out getting app record for app`))
177+
}, 2000)
170178
})
171179
}
172180

@@ -178,9 +186,7 @@ export async function sendApps (ctx: BackendContext) {
178186
const appRecords = []
179187

180188
for (const appRecord of ctx.appRecords) {
181-
if (!(await appRecord.backend.api.getComponentDevtoolsOptions(appRecord.rootInstance)).hide) {
182-
appRecords.push(appRecord)
183-
}
189+
appRecords.push(appRecord)
184190
}
185191

186192
ctx.bridge.send(BridgeEvents.TO_FRONT_APP_LIST, {

0 commit comments

Comments
 (0)