opencode icon indicating copy to clipboard operation
opencode copied to clipboard

fix: prevent undefined values in TextNodeRenderable components

Open MatGros opened this issue 1 week ago • 1 comments

Summary

  • Fix fatal crash: TextNodeRenderable only accepts strings, TextNodeRenderable instances, or StyledText instances

Changes

  • Line 1817 (Patch component): Remove optional chaining ?. on props.output since the <Match when={props.output !== undefined}> guard already ensures it's defined. Use non-null assertion ! instead.
  • Line 1232 (error message display): Add nullish coalescing ?? "" for error.data?.message to provide empty string fallback when data is undefined.

Root Cause

The <text> component from @opentui/core only accepts strings, TextNodeRenderable instances, or StyledText instances. Optional chaining (?.) can return undefined even inside guarded blocks, causing the runtime error.

Testing

The fix ensures all <text> children are guaranteed to be strings:

  • props.output!.trim() - Safe because Match guard checks props.output !== undefined
  • props.message.error?.data?.message ?? "" - Falls back to empty string

MatGros avatar Jan 08 '26 13:01 MatGros