Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions src/Folder/Foldable.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions tests/Folder/FoldableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -420,13 +420,13 @@
expect($output)->toBe('<div></div>');
});

test('does not synthesize a placeholder for a whitespace-only explicit slot', function () {
$node = app(Parser::class)->parse('<x-card><x-slot:footer> </x-slot></x-card>')[0];
test('does not add a placeholder for a whitespace-only slot', function () {
$node = app(Parser::class)->parse('<x-card><x-slot:footer> </x-slot:footer></x-card>')[0];

mock(BladeRenderer::class)
->expects('render')
->once()->withArgs(function (ComponentNode $node) {
expect($node->render())->toBe('<x-card></x-card>');
expect($node->render())->toBe('<x-card><x-slot:footer></x-slot:footer></x-card>');

return true;
})
Expand Down
Loading