[PR #7872] fix: race condition causing prompt.set undefined error #12546

Closed
opened 2026-02-16 18:17:27 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/7872

State: closed
Merged: No


Summary

Fixes a race condition where onMount() was called before the prompt ref was initialized, causing a "undefined is not an object (evaluating 'prompt.set')" error when starting a new session from inside an existing session.

Root Cause

In packages/opencode/src/cli/cmd/tui/routes/home.tsx:79-90, the onMount() hook attempted to call prompt.set() before the ref had been assigned by the <Prompt ref={(r) => { prompt = r }} /> component. This resulted in prompt being undefined during execution.

Fix

  • Changed from onMount() to createEffect() which re-evaluates when reactive dependencies change
  • Added a guard if (once || !prompt) return to check if the prompt ref exists

Fixes #7870

**Original Pull Request:** https://github.com/anomalyco/opencode/pull/7872 **State:** closed **Merged:** No --- ## Summary Fixes a race condition where `onMount()` was called before the `prompt` ref was initialized, causing a "undefined is not an object (evaluating 'prompt.set')" error when starting a new session from inside an existing session. ## Root Cause In `packages/opencode/src/cli/cmd/tui/routes/home.tsx:79-90`, the `onMount()` hook attempted to call `prompt.set()` before the ref had been assigned by the `<Prompt ref={(r) => { prompt = r }} />` component. This resulted in `prompt` being undefined during execution. ## Fix - Changed from `onMount()` to `createEffect()` which re-evaluates when reactive dependencies change - Added a guard `if (once || !prompt) return` to check if the prompt ref exists Fixes #7870
yindo added the pull-request label 2026-02-16 18:17:27 -05:00
yindo closed this issue 2026-02-16 18:17:27 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#12546