Skip to content

Commit 22d33c5

Browse files
authored
fix(app): properly wrap produce calls in setProjects (#23638)
1 parent 1e0137f commit 22d33c5

File tree

2 files changed

+14
-15
lines changed

2 files changed

+14
-15
lines changed

packages/app/src/context/global-sync.tsx

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import type {
1010
import { showToast } from "@opencode-ai/ui/toast"
1111
import { getFilename } from "@opencode-ai/shared/util/path"
1212
import { batch, createContext, getOwner, onCleanup, onMount, type ParentProps, untrack, useContext } from "solid-js"
13-
import { createStore, produce, reconcile } from "solid-js/store"
13+
import { createStore, produce, reconcile, unwrap } from "solid-js/store"
1414
import { useLanguage } from "@/context/language"
1515
import { Persist, persisted } from "@/utils/persist"
1616
import type { InitError } from "../pages/error"
@@ -95,13 +95,8 @@ function createGlobalSync() {
9595
)
9696
}
9797

98-
const setProjects = (next: Project[] | ((draft: Project[]) => void)) => {
98+
const setProjects = (next: Project[] | ((draft: Project[]) => Project[])) => {
9999
projectWritten = true
100-
if (typeof next === "function") {
101-
setGlobalStore("project", produce(next))
102-
cacheProjects()
103-
return
104-
}
105100
setGlobalStore("project", next)
106101
cacheProjects()
107102
}
@@ -116,7 +111,7 @@ function createGlobalSync() {
116111

117112
const set = ((...input: unknown[]) => {
118113
if (input[0] === "project" && (Array.isArray(input[1]) || typeof input[1] === "function")) {
119-
setProjects(input[1] as Project[] | ((draft: Project[]) => void))
114+
setProjects(input[1] as Project[] | ((draft: Project[]) => Project[]))
120115
return input[1]
121116
}
122117
return (setGlobalStore as (...args: unknown[]) => unknown)(...input)

packages/app/src/context/global-sync/event-reducer.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const SKIP_PARTS = new Set(["patch", "step-start", "step-finish"])
2121
export function applyGlobalEvent(input: {
2222
event: { type: string; properties?: unknown }
2323
project: Project[]
24-
setGlobalProject: (next: Project[] | ((draft: Project[]) => void)) => void
24+
setGlobalProject: (next: Project[] | ((draft: Project[]) => Project[])) => void
2525
refresh: () => void
2626
}) {
2727
if (input.event.type === "global.disposed" || input.event.type === "server.connected") {
@@ -33,14 +33,18 @@ export function applyGlobalEvent(input: {
3333
const properties = input.event.properties as Project
3434
const result = Binary.search(input.project, properties.id, (s) => s.id)
3535
if (result.found) {
36-
input.setGlobalProject((draft) => {
37-
draft[result.index] = { ...draft[result.index], ...properties }
38-
})
36+
input.setGlobalProject(
37+
produce((draft) => {
38+
draft[result.index] = { ...draft[result.index], ...properties }
39+
}),
40+
)
3941
return
4042
}
41-
input.setGlobalProject((draft) => {
42-
draft.splice(result.index, 0, properties)
43-
})
43+
input.setGlobalProject(
44+
produce((draft) => {
45+
draft.splice(result.index, 0, properties)
46+
}),
47+
)
4448
}
4549

4650
function cleanupSessionCaches(

0 commit comments

Comments
 (0)