Skip to content
This repository was archived by the owner on Jan 6, 2024. It is now read-only.

Commit dfe3c2a

Browse files
fix(components): keep-alive components repeated collection (#88)
1 parent 0fef7d9 commit dfe3c2a

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
"editor.codeActionsOnSave": {
44
"source.fixAll.eslint": true
55
},
6-
"editor.formatOnSave": false
6+
"editor.formatOnSave": false,
7+
"typescript.tsdk": "node_modules/typescript/lib"
78
}

src/client/logic/components/tree.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,19 +159,23 @@ export class ComponentWalker {
159159
instance: null,
160160
}
161161

162+
const uids: number[] = []
163+
162164
// capture children
163165
if (depth < this.maxDepth || (instance.type as any).__isKeepAlive || parents.some(parent => (parent.type as any).__isKeepAlive)) {
164166
treeNode.children = await Promise.all(children
165167
.map((child, index, list) => this.capture(child, list, depth + 1))
166168
.filter(Boolean))
169+
uids.push(...treeNode.children.map((child: any) => child.uid))
167170
}
168171

169172
// keep-alive
170173
if (this.isKeepAlive(instance)) {
171174
const cachedComponents = this.getKeepAliveCachedInstances(instance)
172175
for (const cachedChild of cachedComponents) {
173176
const node = await this.capture({ ...cachedChild, isDeactivated: true }, [], depth + 1)
174-
if (node)
177+
const uid = node.uid
178+
if (node && !uids.includes(uid))
175179
treeNode.children.push(node)
176180
}
177181
}

0 commit comments

Comments
 (0)