[GH-ISSUE #197] Conditional components not rendered and causing layout issues #812

Closed
opened 2026-03-14 08:39:47 +03:00 by kerem · 3 comments
Owner

Originally created by @magnuswahlstrand on GitHub (Oct 2, 2025).
Original GitHub issue: https://github.com/anomalyco/opentui/issues/197

Hi! Feel free to close this ticket if you are not open for this type of bug reports 🙂

How to reproduce:

  • Use a conditional component {foo && <box><text content={foo} /></box>}
  • foo is updated (alternated between falsy and truthy

Issues:

  • Component is never shown, even though foo becomes truthy
  • When foo becomes truthy, horizontal height is added, but when it is falsy, it is not removed

Image

Full snippet:

import { render } from "@opentui/react";
import { useState } from "react";

function App() {
  const [foo, setFoo] = useState("");

  const handleInput = (value: string) => {
    setFoo(value);
  }

  return (
    <box style={{ flexDirection: "column", flexGrow: 1, padding: 2 }}>
      <box title="Search Programming Languages" style={{ border: true, height: 3 }}>
        <input placeholder="Type to search..." focused onInput={handleInput} />
      </box>

      {foo && <box><text content={foo} /></box>}

      <box style={{ marginTop: 1 }}>
        <text content="↑↓ to navigate • Enter to select • ESC to exit" />
      </box>
    </box >
  );
}

render(<App />);
Originally created by @magnuswahlstrand on GitHub (Oct 2, 2025). Original GitHub issue: https://github.com/anomalyco/opentui/issues/197 Hi! Feel free to close this ticket if you are not open for this type of bug reports 🙂 ### How to reproduce: * Use a conditional component `{foo && <box><text content={foo} /></box>}` * `foo` is updated (alternated between falsy and truthy ### Issues: * Component is never shown, even though `foo` becomes truthy * When `foo` becomes truthy, horizontal height is added, but when it is falsy, it is not removed ![Image](https://github.com/user-attachments/assets/539fed53-c9c6-42a2-8572-bd7e292f6d45) ### Full snippet: ```tsx import { render } from "@opentui/react"; import { useState } from "react"; function App() { const [foo, setFoo] = useState(""); const handleInput = (value: string) => { setFoo(value); } return ( <box style={{ flexDirection: "column", flexGrow: 1, padding: 2 }}> <box title="Search Programming Languages" style={{ border: true, height: 3 }}> <input placeholder="Type to search..." focused onInput={handleInput} /> </box> {foo && <box><text content={foo} /></box>} <box style={{ marginTop: 1 }}> <text content="↑↓ to navigate • Enter to select • ESC to exit" /> </box> </box > ); } render(<App />); ```
kerem 2026-03-14 08:39:47 +03:00
  • closed this issue
  • added the
    react
    label
Author
Owner

@remorses commented on GitHub (Oct 2, 2025):

Try passing the text as children instead of content prop

<!-- gh-comment-id:3362375168 --> @remorses commented on GitHub (Oct 2, 2025): Try passing the text as children instead of content prop
Author
Owner

@magnuswahlstrand commented on GitHub (Oct 2, 2025):

Same problem with

{foo && <box><text>{foo}</text></box>}
<!-- gh-comment-id:3362690666 --> @magnuswahlstrand commented on GitHub (Oct 2, 2025): Same problem with ```tsx {foo && <box><text>{foo}</text></box>} ```
Author
Owner

@eli0shin commented on GitHub (Oct 6, 2025):

I'm testing this and it seems to be another insertBefore issue but it doesn't really make sense because box does seem to track children and handle insertBefore properly.
This example works if it is modified to either remove the box after the conditional box or to make the conditional box constant and make just its contents conditional.

<!-- gh-comment-id:3369680716 --> @eli0shin commented on GitHub (Oct 6, 2025): I'm testing this and it seems to be another insertBefore issue but it doesn't really make sense because box does seem to track children and handle insertBefore properly. This example works if it is modified to either remove the box after the conditional box or to make the conditional box constant and make just its contents conditional.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/opentui#812
No description provided.