[PR #201] [MERGED] Fix(core): insertBefore not rendering conditional children with siblings after them #369

Closed
opened 2026-03-02 23:46:10 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/anomalyco/opentui/pull/201
Author: @eli0shin
Created: 10/6/2025
Status: Merged
Merged: 10/6/2025
Merged by: @kommander

Base: mainHead: fix-conditional-children-in-insertBefore


📝 Commits (1)

  • 14dee5b Fix(core): insertBefore not rendering conditional children with siblings after them

📊 Changes

2 files changed (+15 additions, -1 deletions)

View changed files

📝 packages/core/src/Renderable.ts (+2 -1)
📝 packages/core/src/tests/renderable.test.ts (+13 -0)

📄 Description

Resolves https://github.com/sst/opentui/issues/197

Issue

Conditional React elements with sibling elements after them were not rendering. For example:

{foo ? <box>content</box> : null}
<box>sibling after conditional</box>  // This caused the bug

Root Cause

insertBefore() had else if (renderable.parent) that only handled children transferring from different parents. New children (where renderable.parent is null) had no initialization code at all - they weren't added to either tracking array or registered in the parent's map.

Children need to be in both:

  • _childrenInLayoutOrder (for layout)
  • _childrenInZIndexOrder (for rendering)

New children were missing both, making them invisible and inaccessible.

Fix

Changed else if (renderable.parent) to else to handle both transferred children AND new children. Added missing _childrenInZIndexOrder.push(renderable) to ensure children are properly tracked for rendering.

Test

Added test verifying insertBefore() makes new children accessible via getRenderable().


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/anomalyco/opentui/pull/201 **Author:** [@eli0shin](https://github.com/eli0shin) **Created:** 10/6/2025 **Status:** ✅ Merged **Merged:** 10/6/2025 **Merged by:** [@kommander](https://github.com/kommander) **Base:** `main` ← **Head:** `fix-conditional-children-in-insertBefore` --- ### 📝 Commits (1) - [`14dee5b`](https://github.com/anomalyco/opentui/commit/14dee5bfc4be474445a45fbb09874b07ff5060ff) Fix(core): insertBefore not rendering conditional children with siblings after them ### 📊 Changes **2 files changed** (+15 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `packages/core/src/Renderable.ts` (+2 -1) 📝 `packages/core/src/tests/renderable.test.ts` (+13 -0) </details> ### 📄 Description Resolves https://github.com/sst/opentui/issues/197 ## Issue Conditional React elements with sibling elements after them were not rendering. For example: ```tsx {foo ? <box>content</box> : null} <box>sibling after conditional</box> // This caused the bug ``` ## Root Cause `insertBefore()` had `else if (renderable.parent)` that only handled children transferring from different parents. New children (where `renderable.parent` is null) had **no initialization code at all** - they weren't added to either tracking array or registered in the parent's map. Children need to be in both: - `_childrenInLayoutOrder` (for layout) - `_childrenInZIndexOrder` (for rendering) New children were missing both, making them invisible and inaccessible. ## Fix Changed `else if (renderable.parent)` to `else` to handle both transferred children AND new children. Added missing `_childrenInZIndexOrder.push(renderable)` to ensure children are properly tracked for rendering. ## Test Added test verifying `insertBefore()` makes new children accessible via `getRenderable()`. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-03-02 23:46:10 +03:00
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#369
No description provided.