Skip to content

Commit a6f5d33

Browse files
committed
fix(tui): use unwrap() for KV store serialization and add ready guard
- Import unwrap from solid-js/store to properly serialize reactive stores - Add ready() check to prevent writes before initialization completes - Fixes issue where JSON.stringify on Solid stores could serialize incorrectly Closes anomalyco#227
1 parent d6d1326 commit a6f5d33

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

  • packages/opencode/src/cli/cmd/tui/context

‎packages/opencode/src/cli/cmd/tui/context/kv.tsx‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Global } from "@/global"
22
import { createSignal, type Setter } from "solid-js"
3-
import { createStore } from "solid-js/store"
3+
import { createStore, unwrap } from "solid-js/store"
44
import { createSimpleContext } from "./helper"
55
import path from "path"
66

@@ -40,8 +40,12 @@ export const { use: useKV, provider: KVProvider } = createSimpleContext({
4040
return kvStore[key] ?? defaultValue
4141
},
4242
set(key: string, value: any) {
43+
if (!ready()) {
44+
console.warn("KV store not ready, write deferred")
45+
return
46+
}
4347
setKvStore(key, value)
44-
Bun.write(file, JSON.stringify(kvStore, null, 2))
48+
Bun.write(file, JSON.stringify(unwrap(kvStore), null, 2))
4549
},
4650
}
4751
return result

0 commit comments

Comments
 (0)