Skip to content

Commit 6e5a978

Browse files
committed
fix(vue3): remove duplicate children and inherit 'inactive' state
1 parent 9bbb725 commit 6e5a978

File tree

1 file changed

+11
-8
lines changed
  • packages/app-backend-vue3/src/components

1 file changed

+11
-8
lines changed

packages/app-backend-vue3/src/components/tree.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,9 @@ export class ComponentWalker {
8080
const list = []
8181
if (subTree.component) {
8282
list.push(subTree.component)
83-
}
84-
if (subTree.suspense) {
83+
} else if (subTree.suspense) {
8584
list.push(...this.getInternalInstanceChildren(subTree.suspense.activeBranch))
86-
}
87-
if (Array.isArray(subTree.children)) {
85+
} else if (Array.isArray(subTree.children)) {
8886
subTree.children.forEach(childSubTree => {
8987
if (childSubTree.component) {
9088
list.push(childSubTree.component)
@@ -129,20 +127,26 @@ export class ComponentWalker {
129127
const children = this.getInternalInstanceChildren(instance.subTree)
130128
.filter(child => !isBeingDestroyed(child))
131129

130+
const parents = this.getComponentParents(instance) || []
131+
132+
const inactive = !!instance.isDeactivated || parents.some(parent => parent.isDeactivated)
133+
132134
const treeNode: ComponentTreeNode = {
133135
uid: instance.uid,
134136
id,
135137
name,
136138
renderKey: getRenderKey(instance.vnode ? instance.vnode.key : null),
137-
inactive: !!instance.isDeactivated,
139+
inactive,
138140
hasChildren: !!children.length,
139141
children: [],
140142
isFragment: isFragment(instance),
141143
tags: []
142144
}
143145

146+
const isKeepAliveChildren = parents.some(parent => parent.type.__isKeepAlive)
147+
144148
// capture children
145-
if (depth < this.maxDepth) {
149+
if (isKeepAliveChildren || depth < this.maxDepth) {
146150
treeNode.children = await Promise.all(children
147151
.map((child, index, list) => this.capture(child, list, depth + 1))
148152
.filter(Boolean))
@@ -153,9 +157,8 @@ export class ComponentWalker {
153157
const cachedComponents = Array.from(instance.__v_cache.values()).map((vnode: any) => vnode.component).filter(Boolean)
154158
for (const child of cachedComponents) {
155159
if (!children.includes(child)) {
156-
const node = await this.capture(child, null, depth + 1)
160+
const node = await this.capture({ ...child, isDeactivated: true }, null, depth + 1)
157161
if (node) {
158-
node.inactive = true
159162
treeNode.children.push(node)
160163
}
161164
}

0 commit comments

Comments
 (0)