From 5a47ffaf59d266a14e61b5e53cf20ef4d53437ca Mon Sep 17 00:00:00 2001 From: Marvin Hagemeister Date: Tue, 26 Sep 2023 08:48:26 +0200 Subject: [PATCH] fix: conditional island children not rendered (#1822) --- src/runtime/entrypoints/main.ts | 109 +++++++++++++----- tests/fixture_island_nesting/fresh.gen.ts | 104 +++++++++-------- .../islands/Dropdown.tsx | 50 ++++++++ .../routes/dropdown.tsx | 18 +++ tests/islands_test.ts | 29 +++-- 5 files changed, 219 insertions(+), 91 deletions(-) create mode 100644 tests/fixture_island_nesting/islands/Dropdown.tsx create mode 100644 tests/fixture_island_nesting/routes/dropdown.tsx diff --git a/src/runtime/entrypoints/main.ts b/src/runtime/entrypoints/main.ts index 6802e48e..4b8d05d3 100644 --- a/src/runtime/entrypoints/main.ts +++ b/src/runtime/entrypoints/main.ts @@ -90,7 +90,7 @@ ServerComponent.displayName = "PreactServerComponent"; function addPropsChild(parent: VNode, vnode: ComponentChildren) { const props = parent.props; - if (props.children === null) { + if (props.children == null) { props.children = vnode; } else { if (!Array.isArray(props.children)) { @@ -118,7 +118,7 @@ interface Marker { endNode: Text | Comment | null; } -const HIDE_MARKERS = true; +const SHOW_MARKERS = false; /** * Replace comment markers with empty text nodes to hide them @@ -129,7 +129,7 @@ function hideMarker(marker: Marker) { const parent = endNode!.parentNode!; if ( - !HIDE_MARKERS && startNode !== null && + SHOW_MARKERS && startNode !== null && startNode.nodeType === Node.COMMENT_NODE ) { const text = new Text(""); @@ -139,7 +139,7 @@ function hideMarker(marker: Marker) { } if ( - !HIDE_MARKERS && endNode !== null && endNode.nodeType === Node.COMMENT_NODE + SHOW_MARKERS && endNode !== null && endNode.nodeType === Node.COMMENT_NODE ) { const text = new Text(""); marker.endNode = text; @@ -148,6 +148,50 @@ function hideMarker(marker: Marker) { } } +/** + * If an islands children are `null` then it might be a conditionally + * rendered one which was initially not visible. In these cases we + * send a `