Skip to content

Commit 5bf31c8

Browse files
committed
fix(components): use correct app record in hooks
1 parent 7aca315 commit 5bf31c8

File tree

1 file changed

+27
-21
lines changed

1 file changed

+27
-21
lines changed

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

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ async function connect () {
155155

156156
// Update tree (tags)
157157
if (isSubscribed(BridgeSubscriptions.COMPONENT_TREE, sub => sub.payload.instanceId === id)) {
158-
sendComponentTreeData(appRecord, id, ctx.currentAppRecord.componentFilter, 0, ctx)
158+
sendComponentTreeData(appRecord, id, appRecord.componentFilter, 0, ctx)
159159
}
160160
} catch (e) {
161161
if (process.env.NODE_ENV !== 'production') {
@@ -167,21 +167,20 @@ async function connect () {
167167
hook.on(HookEvents.COMPONENT_ADDED, async (app, uid, parentUid, component) => {
168168
try {
169169
const id = await getComponentId(app, uid, ctx)
170+
const appRecord = await getAppRecord(app, ctx)
170171
if (component) {
171172
if (component.__VUE_DEVTOOLS_UID__ == null) {
172173
component.__VUE_DEVTOOLS_UID__ = id
173174
}
174-
if (!ctx.currentAppRecord.instanceMap.has(id)) {
175-
ctx.currentAppRecord.instanceMap.set(id, component)
175+
if (!appRecord.instanceMap.has(id)) {
176+
appRecord.instanceMap.set(id, component)
176177
}
177178
}
178179

179-
const appRecord = await getAppRecord(app, ctx)
180-
181180
const parentId = await getComponentId(app, parentUid, ctx)
182181
if (isSubscribed(BridgeSubscriptions.COMPONENT_TREE, sub => sub.payload.instanceId === parentId)) {
183182
requestAnimationFrame(() => {
184-
sendComponentTreeData(appRecord, parentId, ctx.currentAppRecord.componentFilter, null, ctx)
183+
sendComponentTreeData(appRecord, parentId, appRecord.componentFilter, null, ctx)
185184
})
186185
}
187186

@@ -196,24 +195,31 @@ async function connect () {
196195
})
197196

198197
hook.on(HookEvents.COMPONENT_REMOVED, async (app, uid, parentUid, component) => {
199-
const parentId = await getComponentId(app, parentUid, ctx)
200-
if (isSubscribed(BridgeSubscriptions.COMPONENT_TREE, sub => sub.payload.instanceId === parentId)) {
201-
requestAnimationFrame(async () => {
202-
try {
203-
sendComponentTreeData(await getAppRecord(app, ctx), parentId, ctx.currentAppRecord.componentFilter, null, ctx)
204-
} catch (e) {
205-
if (process.env.NODE_ENV !== 'production') {
206-
console.error(e)
198+
try {
199+
const appRecord = await getAppRecord(app, ctx)
200+
const parentId = await getComponentId(app, parentUid, ctx)
201+
if (isSubscribed(BridgeSubscriptions.COMPONENT_TREE, sub => sub.payload.instanceId === parentId)) {
202+
requestAnimationFrame(async () => {
203+
try {
204+
sendComponentTreeData(await getAppRecord(app, ctx), parentId, appRecord.componentFilter, null, ctx)
205+
} catch (e) {
206+
if (process.env.NODE_ENV !== 'production') {
207+
console.error(e)
208+
}
207209
}
208-
}
209-
})
210-
}
210+
})
211+
}
211212

212-
const id = await getComponentId(app, uid, ctx)
213-
if (isSubscribed(BridgeSubscriptions.SELECTED_COMPONENT_DATA, sub => sub.payload.instanceId === id)) {
214-
sendEmptyComponentData(id, ctx)
213+
const id = await getComponentId(app, uid, ctx)
214+
if (isSubscribed(BridgeSubscriptions.SELECTED_COMPONENT_DATA, sub => sub.payload.instanceId === id)) {
215+
sendEmptyComponentData(id, ctx)
216+
}
217+
appRecord.instanceMap.delete(id)
218+
} catch (e) {
219+
if (process.env.NODE_ENV !== 'production') {
220+
console.error(e)
221+
}
215222
}
216-
ctx.currentAppRecord.instanceMap.delete(id)
217223
})
218224

219225
ctx.bridge.on(BridgeEvents.TO_BACK_COMPONENT_EDIT_STATE, ({ instanceId, dotPath, type, value, newKey, remove }) => {

0 commit comments

Comments
 (0)