From 296328554956b14922728ddf1faf1ff10dd524f2 Mon Sep 17 00:00:00 2001 From: ghabriel Date: Sat, 12 Sep 2026 20:52:06 +0700 Subject: [PATCH 1/2] Fix explicit named slots ommited during component folding --- src/Folder/Foldable.php | 14 ++++++++------ tests/Folder/FoldableTest.php | 20 +++++++++++++++++++- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/src/Folder/Foldable.php b/src/Folder/Foldable.php index 2b2dfa8..4c2f072 100644 --- a/src/Folder/Foldable.php +++ b/src/Folder/Foldable.php @@ -102,19 +102,21 @@ protected function setupSlots(): void foreach ($this->node->children as $child) { if ($child instanceof SlotNode) { - if (! $this->hasActualContent($child->children)) { - continue; - } + $children = []; - $placeholder = 'BLAZE_PLACEHOLDER_' . $this->placeholderIndex++ . '_'; + if ($this->hasActualContent($child->children)) { + $placeholder = 'BLAZE_PLACEHOLDER_' . $this->placeholderIndex++ . '_'; + + $this->slotByPlaceholder[$placeholder] = $child; - $this->slotByPlaceholder[$placeholder] = $child; + $children = [new TextNode($placeholder)]; + } $slots[$child->name] = new SlotNode( name: $child->name, attributeString: $child->attributeString, slotStyle: $child->slotStyle, - children: [new TextNode($placeholder)], + children: $children, prefix: $child->prefix, closeHasName: $child->closeHasName, attributes: $child->attributes, diff --git a/tests/Folder/FoldableTest.php b/tests/Folder/FoldableTest.php index 6ff77c7..95bd03a 100644 --- a/tests/Folder/FoldableTest.php +++ b/tests/Folder/FoldableTest.php @@ -426,7 +426,25 @@ mock(BladeRenderer::class) ->expects('render') ->once()->withArgs(function (ComponentNode $node) { - expect($node->render())->toBe(''); + expect($node->render())->toBe(''); + + return true; + }) + ->andReturn('
'); + + $output = (new Foldable($node, '', app(BladeRenderer::class), app(BladeService::class)))->fold(); + + expect($output)->toBe('
'); +}); + +test('registers whitespace-only explicit slots as empty without placeholders', function () { + $node = app(Parser::class)->parse(' ')[0]; + + mock(BladeRenderer::class) + ->expects('render') + ->once()->withArgs(function (ComponentNode $node) { + expect($node->children)->toHaveKey('footer'); + expect($node->children['footer']->content())->toBe(''); return true; }) From 519a8832aced4f03df547fe0f8446bcf3007f66f Mon Sep 17 00:00:00 2001 From: Filip Ganyicz Date: Sat, 12 Sep 2026 18:33:44 +0200 Subject: [PATCH 2/2] Formatting --- tests/Folder/FoldableTest.php | 24 +++--------------------- 1 file changed, 3 insertions(+), 21 deletions(-) diff --git a/tests/Folder/FoldableTest.php b/tests/Folder/FoldableTest.php index 95bd03a..fb0549a 100644 --- a/tests/Folder/FoldableTest.php +++ b/tests/Folder/FoldableTest.php @@ -420,31 +420,13 @@ expect($output)->toBe('
'); }); -test('does not synthesize a placeholder for a whitespace-only explicit slot', function () { - $node = app(Parser::class)->parse(' ')[0]; +test('does not add a placeholder for a whitespace-only slot', 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('
'); -}); - -test('registers whitespace-only explicit slots as empty without placeholders', function () { - $node = app(Parser::class)->parse(' ')[0]; - - mock(BladeRenderer::class) - ->expects('render') - ->once()->withArgs(function (ComponentNode $node) { - expect($node->children)->toHaveKey('footer'); - expect($node->children['footer']->content())->toBe(''); + expect($node->render())->toBe(''); return true; })