Skip to content

Commit

Permalink
fix: add null checks for appRecord and appRecord.instanceMap, fix #1892
Browse files Browse the repository at this point in the history
… (#2122)
  • Loading branch information
claylevering authored Dec 15, 2023
1 parent 6ccd508 commit aac74c0
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 21 deletions.
55 changes: 34 additions & 21 deletions packages/app-backend-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,14 @@ async function connect () {
if (component.__VUE_DEVTOOLS_UID__ == null) {
component.__VUE_DEVTOOLS_UID__ = id
}
if (!appRecord.instanceMap.has(id)) {
appRecord.instanceMap.set(id, component)
if (appRecord?.instanceMap) {
if (!appRecord.instanceMap.has(id)) {
appRecord.instanceMap.set(id, component)
}
}
}

if (parentUid != null) {
if (parentUid != null && appRecord?.instanceMap) {
const parentInstances = await appRecord.backend.api.walkComponentParents(component)
if (parentInstances.length) {
// Check two parents level to update `hasChildren
Expand Down Expand Up @@ -222,14 +224,18 @@ async function connect () {
try {
if (!app || (typeof uid !== 'number' && !uid) || !component) return
const appRecord = await getAppRecord(app, ctx)
if (parentUid != null) {
if (parentUid != null && appRecord) {
const parentInstances = await appRecord.backend.api.walkComponentParents(component)
if (parentInstances.length) {
const parentId = await getComponentId(app, parentUid, parentInstances[0], ctx)
if (isSubscribed(BridgeSubscriptions.COMPONENT_TREE, sub => sub.payload.instanceId === parentId)) {
raf(async () => {
try {
sendComponentTreeData(await getAppRecord(app, ctx), parentId, appRecord.componentFilter, null, false, ctx)
const appRecord = await getAppRecord(app, ctx)

if (appRecord) {
sendComponentTreeData(appRecord, parentId, appRecord.componentFilter, null, false, ctx)
}
} catch (e) {
if (SharedData.debugInfo) {
console.error(e)
Expand All @@ -244,7 +250,10 @@ async function connect () {
if (isSubscribed(BridgeSubscriptions.SELECTED_COMPONENT_DATA, sub => sub.payload.instanceId === id)) {
await sendEmptyComponentData(id, ctx)
}
appRecord.instanceMap.delete(id)

if (appRecord) {
appRecord.instanceMap.delete(id)
}

await refreshComponentTreeSearch(ctx)
} catch (e) {
Expand Down Expand Up @@ -288,13 +297,15 @@ async function connect () {

hook.on(HookEvents.TIMELINE_LAYER_ADDED, async (options: TimelineLayerOptions, plugin: Plugin) => {
const appRecord = await getAppRecord(plugin.descriptor.app, ctx)
ctx.timelineLayers.push({
...options,
appRecord,
plugin,
events: [],
})
ctx.bridge.send(BridgeEvents.TO_FRONT_TIMELINE_LAYER_ADD, {})
if (appRecord) {
ctx.timelineLayers.push({
...options,
appRecord,
plugin,
events: [],
})
ctx.bridge.send(BridgeEvents.TO_FRONT_TIMELINE_LAYER_ADD, {})
}
})

hook.on(HookEvents.TIMELINE_EVENT_ADDED, async (options: TimelineEventOptions, plugin: Plugin) => {
Expand All @@ -305,14 +316,16 @@ async function connect () {

hook.on(HookEvents.CUSTOM_INSPECTOR_ADD, async (options: CustomInspectorOptions, plugin: Plugin) => {
const appRecord = await getAppRecord(plugin.descriptor.app, ctx)
ctx.customInspectors.push({
...options,
appRecord,
plugin,
treeFilter: '',
selectedNodeId: null,
})
ctx.bridge.send(BridgeEvents.TO_FRONT_CUSTOM_INSPECTOR_ADD, {})
if (appRecord) {
ctx.customInspectors.push({
...options,
appRecord,
plugin,
treeFilter: '',
selectedNodeId: null,
})
ctx.bridge.send(BridgeEvents.TO_FRONT_CUSTOM_INSPECTOR_ADD, {})
}
})

hook.on(HookEvents.CUSTOM_INSPECTOR_SEND_TREE, async (inspectorId: string, plugin: Plugin) => {
Expand Down
2 changes: 2 additions & 0 deletions packages/app-backend-core/src/perf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export async function performanceMarkStart (
try {
if (!SharedData.performanceMonitoringEnabled) return
const appRecord = await getAppRecord(app, ctx)
if (!appRecord) return
const componentName = await appRecord.backend.api.getComponentName(instance)
const groupId = ctx.perfUniqueGroupId++
const groupKey = `${uid}-${type}`
Expand Down Expand Up @@ -80,6 +81,7 @@ export async function performanceMarkEnd (
try {
if (!SharedData.performanceMonitoringEnabled) return
const appRecord = await getAppRecord(app, ctx)
if (!appRecord) return
const componentName = await appRecord.backend.api.getComponentName(instance)
const groupKey = `${uid}-${type}`
const groupInfo = appRecord.perfGroupIds.get(groupKey)
Expand Down
1 change: 1 addition & 0 deletions packages/app-backend-core/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export async function addPlugin (pluginQueueItem: PluginQueueItem, ctx: BackendC
ctx.currentPlugin = plugin
try {
const appRecord = await getAppRecord(plugin.descriptor.app, ctx)
if (!appRecord) return
const api = new DevtoolsPluginApiInstance(plugin, appRecord, ctx)
if (pluginQueueItem.proxy) {
await pluginQueueItem.proxy.setRealTarget(api)
Expand Down
1 change: 1 addition & 0 deletions packages/app-backend-core/src/timeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ function setupBuiltinLayers (ctx: BackendContext) {
if (!SharedData.componentEventsEnabled) return

const appRecord = await getAppRecord(app, ctx)
if (!appRecord) return
const componentId = `${appRecord.id}:${instance.uid}`
const componentDisplay = (await appRecord.backend.api.getComponentName(instance)) || '<i>Unknown Component</i>'

Expand Down

0 comments on commit aac74c0

Please sign in to comment.