Skip to content

Commit b928d3a

Browse files
committed
fix: send missing components data asa they are registered, fix #2152
1 parent 52442fe commit b928d3a

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

packages/app-backend-api/src/app-record.ts

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export interface AppRecord {
2020
perfGroupIds: Map<string, { groupId: number, time: number }>
2121
iframe: string
2222
meta: any
23+
missingInstanceQueue: Set<string>
2324
}
2425

2526
/**

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

+24-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { scan } from './legacy/scan'
1313
import { addBuiltinLayers, removeLayersForApp } from './timeline'
1414
import { availableBackends, getBackend } from './backend'
1515
import { hook } from './global-hook.js'
16+
import { sendComponentTreeData, sendSelectedComponentData } from './component.js'
1617

1718
const jobs = new JobQueue()
1819

@@ -64,17 +65,39 @@ async function createAppRecord(options: AppRecordOptions, backend: DevtoolsBacke
6465

6566
const [el]: HTMLElement[] = await backend.api.getComponentRootElements(rootInstance)
6667

68+
const instanceMapRaw = new Map<string, any>()
69+
6770
const record: AppRecord = {
6871
id,
6972
name,
7073
options,
7174
backend,
7275
lastInspectedComponentId: null,
73-
instanceMap: new Map(),
76+
instanceMap: new Proxy(instanceMapRaw, {
77+
get(target, key: string) {
78+
if (key === 'set') {
79+
return (instanceId: string, instance: any) => {
80+
target.set(instanceId, instance)
81+
// The component was requested by the frontend before it was registered
82+
if (record.missingInstanceQueue.has(instanceId)) {
83+
record.missingInstanceQueue.delete(instanceId)
84+
if (ctx.currentAppRecord === record) {
85+
sendComponentTreeData(record, instanceId, record.componentFilter, null, false, ctx)
86+
if (record.lastInspectedComponentId === instanceId) {
87+
sendSelectedComponentData(record, instanceId, ctx)
88+
}
89+
}
90+
}
91+
}
92+
}
93+
return target[key].bind(target)
94+
},
95+
}),
7496
rootInstance,
7597
perfGroupIds: new Map(),
7698
iframe: isBrowser && document !== el?.ownerDocument ? el?.ownerDocument?.location?.pathname : null,
7799
meta: options.meta ?? {},
100+
missingInstanceQueue: new Set(),
78101
}
79102

80103
options.app.__VUE_DEVTOOLS_APP_RECORD__ = record

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

+5-2
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,11 @@ export function getComponentInstance(appRecord: AppRecord, instanceId: string, _
136136
instanceId = `${appRecord.id}:root`
137137
}
138138
const instance = appRecord.instanceMap.get(instanceId)
139-
if (!instance && SharedData.debugInfo) {
140-
console.warn(`Instance uid=${instanceId} not found`)
139+
if (!instance) {
140+
appRecord.missingInstanceQueue.add(instanceId)
141+
if (SharedData.debugInfo) {
142+
console.warn(`Instance uid=${instanceId} not found`)
143+
}
141144
}
142145
return instance
143146
}

0 commit comments

Comments
 (0)