Skip to content

Commit 1670d22

Browse files
joachim-isakssonJoachim Isaksson
andauthored
fix: prevent model list corruption from SolidJS reactivity (#6359)
Co-authored-by: Joachim Isaksson <[email protected]>
1 parent ddc4e34 commit 1670d22

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

packages/opencode/src/cli/cmd/tui/component/dialog-model.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ export function DialogModel(props: { providerID?: string }) {
150150
(item) => item.providerID === value.providerID && item.modelID === value.modelID,
151151
)
152152
if (inFavorites) return false
153-
const inRecents = recents.some(
153+
const inRecents = recentList.some(
154154
(item) => item.providerID === value.providerID && item.modelID === value.modelID,
155155
)
156156
if (inRecents) return false

packages/opencode/src/cli/cmd/tui/context/local.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,10 @@ export const { use: useLocal, provider: LocalProvider } = createSimpleContext({
255255
setModelStore("model", agent.current().name, { ...next })
256256
const uniq = uniqueBy([next, ...modelStore.recent], (x) => x.providerID + x.modelID)
257257
if (uniq.length > 10) uniq.pop()
258-
setModelStore("recent", uniq)
258+
setModelStore(
259+
"recent",
260+
uniq.map((x) => ({ providerID: x.providerID, modelID: x.modelID })),
261+
)
259262
save()
260263
},
261264
set(model: { providerID: string; modelID: string }, options?: { recent?: boolean }) {
@@ -272,7 +275,10 @@ export const { use: useLocal, provider: LocalProvider } = createSimpleContext({
272275
if (options?.recent) {
273276
const uniq = uniqueBy([model, ...modelStore.recent], (x) => x.providerID + x.modelID)
274277
if (uniq.length > 10) uniq.pop()
275-
setModelStore("recent", uniq)
278+
setModelStore(
279+
"recent",
280+
uniq.map((x) => ({ providerID: x.providerID, modelID: x.modelID })),
281+
)
276282
save()
277283
}
278284
})
@@ -293,7 +299,10 @@ export const { use: useLocal, provider: LocalProvider } = createSimpleContext({
293299
const next = exists
294300
? modelStore.favorite.filter((x) => x.providerID !== model.providerID || x.modelID !== model.modelID)
295301
: [model, ...modelStore.favorite]
296-
setModelStore("favorite", next)
302+
setModelStore(
303+
"favorite",
304+
next.map((x) => ({ providerID: x.providerID, modelID: x.modelID })),
305+
)
297306
save()
298307
})
299308
},

0 commit comments

Comments
 (0)