The open source coding agent.
TypeScript
fix(app): preserve question dock state across session switches (#16173)
ismeth07348d14a201
diff --git a/packages/app/src/pages/session/composer/session-question-dock.tsx b/packages/app/src/pages/session/composer/session-question-dock.tsxindex fd2ced3dc81..b22a92eb0af 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<string, { tab: number; answers: QuestionAnswer[]; custom: string[]; customOn: boolean[] }>()+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; onSubmitconst 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 = falseconst 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; onSubmitsetStore("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; onSubmitsetStore("sending", true)try {await sdk.client.question.reject({ requestID: props.request.id })+ replied = true+ cache.delete(props.request.id)} catch (err) {fail(err)} finally {