From 07348d14a2013b25434b91aecb30a82546bed1c5 Mon Sep 17 00:00:00 2001 From: ismeth Date: Thu, 5 Mar 2026 14:35:16 +0100 Subject: [PATCH] fix(app): preserve question dock state across session switches (#16173) --- .../composer/session-question-dock.tsx | 26 ++++++++++++++++--- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/packages/app/src/pages/session/composer/session-question-dock.tsx b/packages/app/src/pages/session/composer/session-question-dock.tsx index fd2ced3dc..b22a92eb0 100644 --- a/packages/app/src/pages/session/composer/session-question-dock.tsx +++ b/packages/app/src/pages/session/composer/session-question-dock.tsx @@ -8,6 +8,8 @@ import type { QuestionAnswer, QuestionRequest } from "@opencode-ai/sdk/v2" import { useLanguage } from "@/context/language" import { useSDK } from "@/context/sdk" +const cache = new Map() + export const SessionQuestionDock: Component<{ request: QuestionRequest; onSubmit: () => void }> = (props) => { const sdk = useSDK() const language = useLanguage() @@ -15,16 +17,18 @@ export const SessionQuestionDock: Component<{ request: QuestionRequest; onSubmit const questions = createMemo(() => props.request.questions) const total = createMemo(() => questions().length) + const cached = cache.get(props.request.id) const [store, setStore] = createStore({ - tab: 0, - answers: [] as QuestionAnswer[], - custom: [] as string[], - customOn: [] as boolean[], + tab: cached?.tab ?? 0, + answers: cached?.answers ?? ([] as QuestionAnswer[]), + custom: cached?.custom ?? ([] as string[]), + customOn: cached?.customOn ?? ([] as boolean[]), editing: false, sending: false, }) let root: HTMLDivElement | undefined + let replied = false const question = createMemo(() => questions()[store.tab]) const options = createMemo(() => question()?.options ?? []) @@ -107,6 +111,16 @@ export const SessionQuestionDock: Component<{ request: QuestionRequest; onSubmit }) }) + onCleanup(() => { + if (replied) return + cache.set(props.request.id, { + tab: store.tab, + answers: store.answers.map((a) => (a ? [...a] : [])), + custom: store.custom.map((s) => s ?? ""), + customOn: store.customOn.map((b) => b ?? false), + }) + }) + const fail = (err: unknown) => { const message = err instanceof Error ? err.message : String(err) showToast({ title: language.t("common.requestFailed"), description: message }) @@ -119,6 +133,8 @@ export const SessionQuestionDock: Component<{ request: QuestionRequest; onSubmit setStore("sending", true) try { await sdk.client.question.reply({ requestID: props.request.id, answers }) + replied = true + cache.delete(props.request.id) } catch (err) { fail(err) } finally { @@ -133,6 +149,8 @@ export const SessionQuestionDock: Component<{ request: QuestionRequest; onSubmit setStore("sending", true) try { await sdk.client.question.reject({ requestID: props.request.id }) + replied = true + cache.delete(props.request.id) } catch (err) { fail(err) } finally {