Skip to content

Commit 4d91c35

Browse files
committed
fix(components): update hasChildren for components that is not subscribed
1 parent a999cc4 commit 4d91c35

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,10 @@ export async function sendComponentTreeData (appRecord: AppRecord, instanceId: s
3030
if (maxDepth == null) {
3131
maxDepth = instance === ctx.currentAppRecord.rootInstance ? 2 : 1
3232
}
33+
const data = await appRecord.backend.api.walkComponentTree(instance, maxDepth, filter)
3334
const payload = {
3435
instanceId,
35-
treeData: stringify(await appRecord.backend.api.walkComponentTree(instance, maxDepth, filter)),
36+
treeData: stringify(data),
3637
}
3738
ctx.bridge.send(BridgeEvents.TO_FRONT_COMPONENT_TREE, payload)
3839
}
@@ -101,6 +102,7 @@ export async function editComponentState (instanceId: string, dotPath: string, t
101102

102103
export async function getComponentId (app: App, uid: number, instance: ComponentInstance, ctx: BackendContext) {
103104
try {
105+
if (instance.__VUE_DEVTOOLS_UID__) return instance.__VUE_DEVTOOLS_UID__
104106
const appRecord = await getAppRecord(app, ctx)
105107
if (!appRecord) return null
106108
const isRoot = appRecord.rootInstance === instance

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,11 +152,14 @@ async function connect () {
152152
if (parentUid != null) {
153153
const parentInstances = await appRecord.backend.api.walkComponentParents(component)
154154
if (parentInstances.length) {
155-
const parentId = await getComponentId(app, parentUid, parentInstances[0], ctx)
156-
if (isSubscribed(BridgeSubscriptions.COMPONENT_TREE, sub => sub.payload.instanceId === parentId)) {
157-
requestAnimationFrame(() => {
158-
sendComponentTreeData(appRecord, parentId, appRecord.componentFilter, null, ctx)
159-
})
155+
// Check two parents level to update `hasChildren
156+
for (let i = 0; i < 2 && i < parentInstances.length; i++) {
157+
const parentId = await getComponentId(app, parentUid, parentInstances[i], ctx)
158+
if (isSubscribed(BridgeSubscriptions.COMPONENT_TREE, sub => sub.payload.instanceId === parentId)) {
159+
requestAnimationFrame(() => {
160+
sendComponentTreeData(appRecord, parentId, appRecord.componentFilter, null, ctx)
161+
})
162+
}
160163
}
161164
}
162165
}
@@ -359,6 +362,7 @@ function connectBridge () {
359362
ctx.bridge.on(BridgeEvents.TO_BACK_COMPONENT_TREE, ({ instanceId, filter }) => {
360363
ctx.currentAppRecord.componentFilter = filter
361364
sendComponentTreeData(ctx.currentAppRecord, instanceId, filter, null, ctx)
365+
subscribe(BridgeSubscriptions.COMPONENT_TREE, { instanceId })
362366
})
363367

364368
ctx.bridge.on(BridgeEvents.TO_BACK_COMPONENT_SELECTED_DATA, (instanceId) => {

0 commit comments

Comments
 (0)