Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add null checks for appRecord and appRecord.instanceMap, fix #1892 #2122

Merged
merged 2 commits into from
Dec 15, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 30 additions & 20 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 Down Expand Up @@ -288,13 +294,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 +313,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