From 5122a4da229e1e483837e9a4a11f41ffcccc5487 Mon Sep 17 00:00:00 2001 From: ghabriel Date: Fri, 11 Sep 2026 00:08:56 +0700 Subject: [PATCH 1/5] Fix whitespace-only implicit slots during folding --- src/Folder/Foldable.php | 11 ++++++++++- tests/Folder/FoldableTest.php | 17 +++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/Folder/Foldable.php b/src/Folder/Foldable.php index 533cfbb..23b90db 100644 --- a/src/Folder/Foldable.php +++ b/src/Folder/Foldable.php @@ -120,8 +120,17 @@ protected function setupSlots(): void } } + $hasActualLooseContent = false; + foreach ($looseContent as $child) { + if (! $child instanceof TextNode || trim($child->content) !== '') { + $hasActualLooseContent = true; + + break; + } + } + // Synthesize a default slot from loose content when there's not an explicit one - if ($looseContent && ! isset($slots['slot'])) { + if ($hasActualLooseContent && ! isset($slots['slot'])) { $placeholder = 'BLAZE_PLACEHOLDER_' . $this->placeholderIndex++ . '_'; $defaultSlot = new SlotNode( diff --git a/tests/Folder/FoldableTest.php b/tests/Folder/FoldableTest.php index 7def932..12fdcb3 100644 --- a/tests/Folder/FoldableTest.php +++ b/tests/Folder/FoldableTest.php @@ -402,3 +402,20 @@ expect((new Foldable($node, '', app(BladeRenderer::class), app(BladeService::class)))->fold()) ->toBe('
'); }); + +test('does not synthesize a default slot for whitespace-only loose content', function () { + $node = app(Parser::class)->parse(' ')[0]; + + mock(BladeRenderer::class) + ->expects('render') + ->once()->withArgs(function (ComponentNode $node) { + expect($node->render())->toBe(''); + + return true; + }) + ->andReturn('
'); + + $output = (new Foldable($node, '', app(BladeRenderer::class), app(BladeService::class)))->fold(); + + expect($output)->toBe('
'); +}); From 2969070c30d99a0b48ecf62ea1eeb38bad268bf0 Mon Sep 17 00:00:00 2001 From: Rihulfa Akbar <151924216+ghabriel25@users.noreply.github.com> Date: Fri, 11 Sep 2026 07:58:36 +0700 Subject: [PATCH 2/5] Guard explicit and implicit slots from whitespace-only content --- src/Folder/Foldable.php | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/src/Folder/Foldable.php b/src/Folder/Foldable.php index 23b90db..1f4ce7d 100644 --- a/src/Folder/Foldable.php +++ b/src/Folder/Foldable.php @@ -102,6 +102,11 @@ protected function setupSlots(): void foreach ($this->node->children as $child) { if ($child instanceof SlotNode) { + // Skip whitespace-only explicit slots. + if (! $this->hasActualContent($child->children)) { + continue; + } + $placeholder = 'BLAZE_PLACEHOLDER_' . $this->placeholderIndex++ . '_'; $this->slotByPlaceholder[$placeholder] = $child; @@ -120,17 +125,8 @@ protected function setupSlots(): void } } - $hasActualLooseContent = false; - foreach ($looseContent as $child) { - if (! $child instanceof TextNode || trim($child->content) !== '') { - $hasActualLooseContent = true; - - break; - } - } - // Synthesize a default slot from loose content when there's not an explicit one - if ($hasActualLooseContent && ! isset($slots['slot'])) { + if ($this->hasActualContent($looseContent) && ! isset($slots['slot'])) { $placeholder = 'BLAZE_PLACEHOLDER_' . $this->placeholderIndex++ . '_'; $defaultSlot = new SlotNode( @@ -155,6 +151,20 @@ protected function setupSlots(): void $this->renderable->children = $slots; } + /** + * Determine whether a list of nodes contains anything besides whitespace-only text. + */ + protected function hasActualContent(array $nodes): bool + { + foreach ($nodes as $node) { + if (! $node instanceof TextNode || trim($node->content) !== '') { + return true; + } + } + + return false; + } + /** * Convert [BLAZE_ATTR:...] markers into conditional PHP for dynamic attributes. */ From 578fd2146eb35bd354e71bdd02f9a08a7991e8a1 Mon Sep 17 00:00:00 2001 From: Rihulfa Akbar <151924216+ghabriel25@users.noreply.github.com> Date: Fri, 11 Sep 2026 07:59:28 +0700 Subject: [PATCH 3/5] Add test for whitespace-only explicit slot handling --- tests/Folder/FoldableTest.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/Folder/FoldableTest.php b/tests/Folder/FoldableTest.php index 12fdcb3..374a608 100644 --- a/tests/Folder/FoldableTest.php +++ b/tests/Folder/FoldableTest.php @@ -419,3 +419,20 @@ expect($output)->toBe('
'); }); + +test('does not synthesize a placeholder for a whitespace-only explicit slot', function () { + $node = app(Parser::class)->parse(' Save')[0]; + + mock(BladeRenderer::class) + ->expects('render') + ->once()->withArgs(function (ComponentNode $node) { + expect($node->render())->toBe('Save'); + + return true; + }) + ->andReturn(''); + + $output = (new Foldable($node, '', app(BladeRenderer::class), app(BladeService::class)))->fold(); + + expect($output)->toBe(''); +}); From a8558cd3b05f65d811a1fdafb68522cff4f43815 Mon Sep 17 00:00:00 2001 From: Rihulfa Akbar <151924216+ghabriel25@users.noreply.github.com> Date: Fri, 11 Sep 2026 08:16:43 +0700 Subject: [PATCH 4/5] Fix wrong fixture --- tests/Folder/FoldableTest.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/Folder/FoldableTest.php b/tests/Folder/FoldableTest.php index 374a608..6ff77c7 100644 --- a/tests/Folder/FoldableTest.php +++ b/tests/Folder/FoldableTest.php @@ -421,18 +421,18 @@ }); test('does not synthesize a placeholder for a whitespace-only explicit slot', function () { - $node = app(Parser::class)->parse(' Save')[0]; + $node = app(Parser::class)->parse(' ')[0]; mock(BladeRenderer::class) ->expects('render') ->once()->withArgs(function (ComponentNode $node) { - expect($node->render())->toBe('Save'); + expect($node->render())->toBe(''); return true; }) - ->andReturn(''); + ->andReturn('
'); $output = (new Foldable($node, '', app(BladeRenderer::class), app(BladeService::class)))->fold(); - expect($output)->toBe(''); + expect($output)->toBe('
'); }); From 81882d2d01fc5aed15f698206c346df76e9a8283 Mon Sep 17 00:00:00 2001 From: Filip Ganyicz Date: Sat, 12 Sep 2026 14:39:24 +0200 Subject: [PATCH 5/5] Formatting Remove comment about skipping whitespace-only explicit slots. --- src/Folder/Foldable.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Folder/Foldable.php b/src/Folder/Foldable.php index 1f4ce7d..2b2dfa8 100644 --- a/src/Folder/Foldable.php +++ b/src/Folder/Foldable.php @@ -102,7 +102,6 @@ protected function setupSlots(): void foreach ($this->node->children as $child) { if ($child instanceof SlotNode) { - // Skip whitespace-only explicit slots. if (! $this->hasActualContent($child->children)) { continue; }