Skip to content

Commit b028126

Browse files
kommanderColin4k1024
authored andcommitted
more timeout race guards
1 parent 0066614 commit b028126

5 files changed

Lines changed: 13 additions & 4 deletions

File tree

packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,11 @@ export function Prompt(props: PromptProps) {
9393
let promptPartTypeId = 0
9494

9595
sdk.event.on(TuiEvent.PromptAppend.type, (evt) => {
96+
if (!input || input.isDestroyed) return
9697
input.insertText(evt.properties.text)
9798
setTimeout(() => {
99+
// setTimeout is a workaround and needs to be addressed properly
100+
if (!input || input.isDestroyed) return
98101
input.getLayoutNode().markDirty()
99102
input.gotoBufferEnd()
100103
renderer.requestRender()
@@ -924,6 +927,8 @@ export function Prompt(props: PromptProps) {
924927

925928
// Force layout update and render for the pasted content
926929
setTimeout(() => {
930+
// setTimeout is a workaround and needs to be addressed properly
931+
if (!input || input.isDestroyed) return
927932
input.getLayoutNode().markDirty()
928933
renderer.requestRender()
929934
}, 0)
@@ -935,6 +940,8 @@ export function Prompt(props: PromptProps) {
935940
}
936941
props.ref?.(ref)
937942
setTimeout(() => {
943+
// setTimeout is a workaround and needs to be addressed properly
944+
if (!input || input.isDestroyed) return
938945
input.cursorColor = theme.text
939946
}, 0)
940947
}}

packages/opencode/src/cli/cmd/tui/context/keybind.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,8 @@ export const { use: useKeybind, provider: KeybindProvider } = createSimpleContex
3434
timeout = setTimeout(() => {
3535
if (!store.leader) return
3636
leader(false)
37-
if (focus) {
38-
focus.focus()
39-
}
37+
if (!focus || focus.isDestroyed) return
38+
focus.focus()
4039
}, 2000)
4140
return
4241
}

packages/opencode/src/cli/cmd/tui/routes/session/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,8 @@ export function Session() {
276276

277277
function toBottom() {
278278
setTimeout(() => {
279-
if (scroll) scroll.scrollTo(scroll.scrollHeight)
279+
if (!scroll || scroll.isDestroyed) return
280+
scroll.scrollTo(scroll.scrollHeight)
280281
}, 50)
281282
}
282283

packages/opencode/src/cli/cmd/tui/ui/dialog-export-options.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ export function DialogExportOptions(props: DialogExportOptionsProps) {
6868
onMount(() => {
6969
dialog.setSize("medium")
7070
setTimeout(() => {
71+
if (!textarea || textarea.isDestroyed) return
7172
textarea.focus()
7273
}, 1)
7374
textarea.gotoLineEnd()

packages/opencode/src/cli/cmd/tui/ui/dialog-prompt.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export function DialogPrompt(props: DialogPromptProps) {
2727
onMount(() => {
2828
dialog.setSize("medium")
2929
setTimeout(() => {
30+
if (!textarea || textarea.isDestroyed) return
3031
textarea.focus()
3132
}, 1)
3233
textarea.gotoLineEnd()

0 commit comments

Comments
 (0)