summaryrefslogtreecommitdiffhomepage
path: root/packages/app/src/pages
diff options
context:
space:
mode:
authoradamelmore <[email protected]>2026-01-24 00:35:02 -0600
committerAdam <[email protected]>2026-01-24 07:00:41 -0600
commit962ab3bc8cf0b051e9858db0c6c3e4b96a42bf1b (patch)
tree3d147aebe8bb7e7c615e5fe96b49f90eb841393e /packages/app/src/pages
parentda8f3e92a7bbc3b288f89f6b535b72b94c1d1c19 (diff)
downloadopencode-962ab3bc8cf0b051e9858db0c6c3e4b96a42bf1b.tar.gz
opencode-962ab3bc8cf0b051e9858db0c6c3e4b96a42bf1b.zip
fix(app): reactive loops
Diffstat (limited to 'packages/app/src/pages')
-rw-r--r--packages/app/src/pages/layout.tsx35
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))
}),
)