The open source coding agent.
TypeScript
more timeout race guards
Sebastian Herrlinger41ea4694db76
diff --git a/packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx b/packages/opencode/src/cli/cmd/tui/component/prompt/index.tsxindex e19c8b70982..caa13032292 100644--- a/packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx+++ b/packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx@@ -93,8 +93,11 @@ export function Prompt(props: PromptProps) {let promptPartTypeId = 0sdk.event.on(TuiEvent.PromptAppend.type, (evt) => {+ if (!input || input.isDestroyed) returninput.insertText(evt.properties.text)setTimeout(() => {+ // setTimeout is a workaround and needs to be addressed properly+ if (!input || input.isDestroyed) returninput.getLayoutNode().markDirty()input.gotoBufferEnd()renderer.requestRender()@@ -924,6 +927,8 @@ export function Prompt(props: PromptProps) {// Force layout update and render for the pasted contentsetTimeout(() => {+ // setTimeout is a workaround and needs to be addressed properly+ if (!input || input.isDestroyed) returninput.getLayoutNode().markDirty()renderer.requestRender()}, 0)@@ -935,6 +940,8 @@ export function Prompt(props: PromptProps) {}props.ref?.(ref)setTimeout(() => {+ // setTimeout is a workaround and needs to be addressed properly+ if (!input || input.isDestroyed) returninput.cursorColor = theme.text}, 0)}}diff --git a/packages/opencode/src/cli/cmd/tui/context/keybind.tsx b/packages/opencode/src/cli/cmd/tui/context/keybind.tsxindex 4c82e594c3e..0dbbbc6f9ee 100644--- a/packages/opencode/src/cli/cmd/tui/context/keybind.tsx+++ b/packages/opencode/src/cli/cmd/tui/context/keybind.tsx@@ -34,9 +34,8 @@ export const { use: useKeybind, provider: KeybindProvider } = createSimpleContextimeout = setTimeout(() => {if (!store.leader) returnleader(false)- if (focus) {- focus.focus()- }+ if (!focus || focus.isDestroyed) return+ focus.focus()}, 2000)return}diff --git a/packages/opencode/src/cli/cmd/tui/routes/session/index.tsx b/packages/opencode/src/cli/cmd/tui/routes/session/index.tsxindex 66dac85ecaa..d36a7d20994 100644--- a/packages/opencode/src/cli/cmd/tui/routes/session/index.tsx+++ b/packages/opencode/src/cli/cmd/tui/routes/session/index.tsx@@ -275,7 +275,8 @@ export function Session() {function toBottom() {setTimeout(() => {- if (scroll) scroll.scrollTo(scroll.scrollHeight)+ if (!scroll || scroll.isDestroyed) return+ scroll.scrollTo(scroll.scrollHeight)}, 50)}diff --git a/packages/opencode/src/cli/cmd/tui/ui/dialog-export-options.tsx b/packages/opencode/src/cli/cmd/tui/ui/dialog-export-options.tsxindex 90699e1f0ba..867ed681002 100644--- a/packages/opencode/src/cli/cmd/tui/ui/dialog-export-options.tsx+++ b/packages/opencode/src/cli/cmd/tui/ui/dialog-export-options.tsx@@ -68,6 +68,7 @@ export function DialogExportOptions(props: DialogExportOptionsProps) {onMount(() => {dialog.setSize("medium")setTimeout(() => {+ if (!textarea || textarea.isDestroyed) returntextarea.focus()}, 1)textarea.gotoLineEnd()diff --git a/packages/opencode/src/cli/cmd/tui/ui/dialog-prompt.tsx b/packages/opencode/src/cli/cmd/tui/ui/dialog-prompt.tsxindex 1b9acb5898e..b2965241243 100644--- a/packages/opencode/src/cli/cmd/tui/ui/dialog-prompt.tsx+++ b/packages/opencode/src/cli/cmd/tui/ui/dialog-prompt.tsx@@ -27,6 +27,7 @@ export function DialogPrompt(props: DialogPromptProps) {onMount(() => {dialog.setSize("medium")setTimeout(() => {+ if (!textarea || textarea.isDestroyed) returntextarea.focus()}, 1)textarea.gotoLineEnd()