diff options
Diffstat (limited to 'packages/app/src/pages')
| -rw-r--r-- | packages/app/src/pages/layout.tsx | 35 |
1 files changed, 28 insertions, 7 deletions
diff --git a/packages/app/src/pages/layout.tsx b/packages/app/src/pages/layout.tsx index 714e23b23..202996eea 100644 --- a/packages/app/src/pages/layout.tsx +++ b/packages/app/src/pages/layout.tsx @@ -724,7 +724,8 @@ export default function Layout(props: ParentProps) { if (!directory) return const [store] = globalSync.child(directory) - if (store.message[session.id] !== undefined) return + const cached = untrack(() => store.message[session.id] !== undefined) + if (cached) return const q = queueFor(directory) if (q.inflight.has(session.id)) return @@ -855,14 +856,34 @@ export default function Layout(props: ParentProps) { setStore( produce((draft) => { const removed = new Set<string>([session.id]) - const collect = (parentID: string) => { - for (const item of draft.session) { - if (item.parentID !== parentID) continue - removed.add(item.id) - collect(item.id) + + const byParent = new Map<string, string[]>() + for (const item of draft.session) { + const parentID = item.parentID + if (!parentID) continue + const existing = byParent.get(parentID) + if (existing) { + existing.push(item.id) + continue } + byParent.set(parentID, [item.id]) } - collect(session.id) + + const stack = [session.id] + while (stack.length) { + const parentID = stack.pop() + if (!parentID) continue + + const children = byParent.get(parentID) + if (!children) continue + + for (const child of children) { + if (removed.has(child)) continue + removed.add(child) + stack.push(child) + } + } + draft.session = draft.session.filter((s) => !removed.has(s.id)) }), ) |
