Skip to content

The agent that grows with you

fix(desktop): evict inactive tool disclosure atoms

Yuan Lib8c844b99a28
diff --git a/apps/desktop/src/store/tool-view.ts b/apps/desktop/src/store/tool-view.ts
index bf9c3dc09b6..3ba27d7e6c6 100644
--- a/apps/desktop/src/store/tool-view.ts
+++ b/apps/desktop/src/store/tool-view.ts
@@ -1,4 +1,4 @@
-import { atom, computed, type ReadableAtom } from 'nanostores'
+import { atom, computed, onStop, type ReadableAtom } from 'nanostores'
import { persistBoolean, storedBoolean } from '@/lib/storage'
import { modeBound } from '@/store/interface-mode'
@@ -43,6 +43,11 @@ export function $toolDisclosureOpen(id: string): ReadableAtom<boolean | undefine
if (!cached) {
cached = computed($toolDisclosureStates, states => states[id])
+ onStop(cached, () => {
+ if (disclosureOpenCache.get(id) === cached) {
+ disclosureOpenCache.delete(id)
+ }
+ })
disclosureOpenCache.set(id, cached)
}
@@ -61,6 +66,11 @@ export function $anyToolDisclosureOpen(ids: readonly string[]): ReadableAtom<boo
if (!cached) {
cached = computed($toolDisclosureStates, states => ids.some(id => Boolean(states[id])))
+ onStop(cached, () => {
+ if (anyDisclosureOpenCache.get(key) === cached) {
+ anyDisclosureOpenCache.delete(key)
+ }
+ })
anyDisclosureOpenCache.set(key, cached)
}