Guard View surface tree traversal
This commit is contained in:
@@ -1054,10 +1054,12 @@ function SurfaceSelector({
|
|||||||
|
|
||||||
function descendants(surfaceId: string): string[] {
|
function descendants(surfaceId: string): string[] {
|
||||||
const result: string[] = [];
|
const result: string[] = [];
|
||||||
|
const visited = new Set([surfaceId]);
|
||||||
const pending = [...(childrenByParent.get(surfaceId) ?? [])];
|
const pending = [...(childrenByParent.get(surfaceId) ?? [])];
|
||||||
while (pending.length) {
|
while (pending.length) {
|
||||||
const child = pending.shift();
|
const child = pending.shift();
|
||||||
if (!child) continue;
|
if (!child || visited.has(child.id)) continue;
|
||||||
|
visited.add(child.id);
|
||||||
result.push(child.id);
|
result.push(child.id);
|
||||||
pending.push(...(childrenByParent.get(child.id) ?? []));
|
pending.push(...(childrenByParent.get(child.id) ?? []));
|
||||||
}
|
}
|
||||||
@@ -1065,8 +1067,11 @@ function SurfaceSelector({
|
|||||||
}
|
}
|
||||||
|
|
||||||
function withAncestors(next: Set<string>, surfaceId: string) {
|
function withAncestors(next: Set<string>, surfaceId: string) {
|
||||||
|
const visited = new Set([surfaceId]);
|
||||||
let current = byId.get(surfaceId);
|
let current = byId.get(surfaceId);
|
||||||
while (current?.parentId) {
|
while (current?.parentId) {
|
||||||
|
if (visited.has(current.parentId)) break;
|
||||||
|
visited.add(current.parentId);
|
||||||
next.add(current.parentId);
|
next.add(current.parentId);
|
||||||
current = byId.get(current.parentId);
|
current = byId.get(current.parentId);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user