Skip to content

Bug: conditional sibling causes insertBefore crash in <box> #432

@IsraelAraujo70

Description

@IsraelAraujo70

Summary

When rendering a <textarea> and then conditionally rendering a sibling <line-number> before it (after the textarea ref becomes available), OpenTUI crashes with:
Error: Anchor does not exist
at insertBefore (Renderable.ts:1161:17)
This looks like React trying to insertBefore() into a <box> container, but the anchor resolution fails.

Environment

  • Runtime: Bun
  • @opentui/core: 0.1.62
  • @opentui/react: 0.1.62
  • react: 19.2.3
  • OS: (fill in)

Steps to Reproduce

  1. Render a <textarea> and store its instance via a callback ref.
  2. Conditionally render <line-number target={textareaInstance} /> before the textarea once the ref is set.
    Minimal repro:
const [target, setTarget] = useState<any>(null)
return (
  <box flexDirection="row">
    {target && <line-number target={target} />}
    <textarea ref={setTarget} />
  </box>
)

Expected

mounts and attaches to the textarea without crashing.
Actual
Crash with Error: Anchor does not exist coming from insertBefore.

Notes / Suspected Cause

  • On initial render, only <textarea> exists.
  • After the ref sets state, React re-renders and attempts to insert before an existing child.
  • The host implementation (or its internal children tracking) appears to mishandle insertBefore anchor resolution in this scenario.
    Workarounds
  • Render <textarea> first (so gets appended when it becomes available), and use flexDirection="row-reverse" to keep line numbers on the left.
  • Alternatively, render unconditionally and hide it until target exists (avoid insertion entirely).

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions