fix(app): properly wrap produce calls in setProjects (#23638)
This commit is contained in:
@@ -10,7 +10,7 @@ import type {
|
|||||||
import { showToast } from "@opencode-ai/ui/toast"
|
import { showToast } from "@opencode-ai/ui/toast"
|
||||||
import { getFilename } from "@opencode-ai/shared/util/path"
|
import { getFilename } from "@opencode-ai/shared/util/path"
|
||||||
import { batch, createContext, getOwner, onCleanup, onMount, type ParentProps, untrack, useContext } from "solid-js"
|
import { batch, createContext, getOwner, onCleanup, onMount, type ParentProps, untrack, useContext } from "solid-js"
|
||||||
import { createStore, produce, reconcile } from "solid-js/store"
|
import { createStore, produce, reconcile, unwrap } from "solid-js/store"
|
||||||
import { useLanguage } from "@/context/language"
|
import { useLanguage } from "@/context/language"
|
||||||
import { Persist, persisted } from "@/utils/persist"
|
import { Persist, persisted } from "@/utils/persist"
|
||||||
import type { InitError } from "../pages/error"
|
import type { InitError } from "../pages/error"
|
||||||
@@ -95,13 +95,8 @@ function createGlobalSync() {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
const setProjects = (next: Project[] | ((draft: Project[]) => void)) => {
|
const setProjects = (next: Project[] | ((draft: Project[]) => Project[])) => {
|
||||||
projectWritten = true
|
projectWritten = true
|
||||||
if (typeof next === "function") {
|
|
||||||
setGlobalStore("project", produce(next))
|
|
||||||
cacheProjects()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
setGlobalStore("project", next)
|
setGlobalStore("project", next)
|
||||||
cacheProjects()
|
cacheProjects()
|
||||||
}
|
}
|
||||||
@@ -116,7 +111,7 @@ function createGlobalSync() {
|
|||||||
|
|
||||||
const set = ((...input: unknown[]) => {
|
const set = ((...input: unknown[]) => {
|
||||||
if (input[0] === "project" && (Array.isArray(input[1]) || typeof input[1] === "function")) {
|
if (input[0] === "project" && (Array.isArray(input[1]) || typeof input[1] === "function")) {
|
||||||
setProjects(input[1] as Project[] | ((draft: Project[]) => void))
|
setProjects(input[1] as Project[] | ((draft: Project[]) => Project[]))
|
||||||
return input[1]
|
return input[1]
|
||||||
}
|
}
|
||||||
return (setGlobalStore as (...args: unknown[]) => unknown)(...input)
|
return (setGlobalStore as (...args: unknown[]) => unknown)(...input)
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ const SKIP_PARTS = new Set(["patch", "step-start", "step-finish"])
|
|||||||
export function applyGlobalEvent(input: {
|
export function applyGlobalEvent(input: {
|
||||||
event: { type: string; properties?: unknown }
|
event: { type: string; properties?: unknown }
|
||||||
project: Project[]
|
project: Project[]
|
||||||
setGlobalProject: (next: Project[] | ((draft: Project[]) => void)) => void
|
setGlobalProject: (next: Project[] | ((draft: Project[]) => Project[])) => void
|
||||||
refresh: () => void
|
refresh: () => void
|
||||||
}) {
|
}) {
|
||||||
if (input.event.type === "global.disposed" || input.event.type === "server.connected") {
|
if (input.event.type === "global.disposed" || input.event.type === "server.connected") {
|
||||||
@@ -33,14 +33,18 @@ export function applyGlobalEvent(input: {
|
|||||||
const properties = input.event.properties as Project
|
const properties = input.event.properties as Project
|
||||||
const result = Binary.search(input.project, properties.id, (s) => s.id)
|
const result = Binary.search(input.project, properties.id, (s) => s.id)
|
||||||
if (result.found) {
|
if (result.found) {
|
||||||
input.setGlobalProject((draft) => {
|
input.setGlobalProject(
|
||||||
draft[result.index] = { ...draft[result.index], ...properties }
|
produce((draft) => {
|
||||||
})
|
draft[result.index] = { ...draft[result.index], ...properties }
|
||||||
|
}),
|
||||||
|
)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
input.setGlobalProject((draft) => {
|
input.setGlobalProject(
|
||||||
draft.splice(result.index, 0, properties)
|
produce((draft) => {
|
||||||
})
|
draft.splice(result.index, 0, properties)
|
||||||
|
}),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
function cleanupSessionCaches(
|
function cleanupSessionCaches(
|
||||||
|
|||||||
Reference in New Issue
Block a user