Skip to content

Fix whitespace-only implicit and explicit slots during folding - #209

Merged
ganyicz merged 5 commits into
livewire:mainfrom
ghabriel25:fix/empty-slot
Sep 12, 2026
Merged

Fix whitespace-only implicit and explicit slots during folding#209
ganyicz merged 5 commits into
livewire:mainfrom
ghabriel25:fix/empty-slot

Conversation

@ghabriel25

@ghabriel25 ghabriel25 commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

Problem

When Blaze folds a component with whitespace-only content:

<x-button> </x-button>

the whitespace was incorrectly treated as actual slot content. Blaze would create a default slot placeholder, causing the component to receive a non-empty ComponentSlot during rendering.

This could cause components to behave differently when Blaze was enabled.

Changes

Foldable::setupSlots() now checks the actual rendered loose content before creating an implicit default slot.

Whitespace-only content no longer creates a slot placeholder, while actual content continues to behave as before.

Result

  • Whitespace-only implicit and explicit slots are treated as empty during folding.
  • Components no longer see a synthetic non-empty slot for whitespace-only content.
  • Actual slot content and explicit slots remain unchanged.
  • No changes to Laravel's ComponentSlot semantics or normal non-Blaze rendering.

Related PR: livewire/flux#2821
Fixes: livewire/flux#2816

@github-actions

github-actions Bot commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

Benchmark Result: Default

Attempt Blade Blaze Change
#1 364.10ms 14.67ms 96%
#2 * 368.34ms 15.12ms 95.9%
#3 356.57ms 14.94ms 95.8%
#4 358.73ms 14.92ms 95.8%
#5 * 364.39ms 15.19ms 95.8%
#6 357.17ms 14.78ms 95.9%
#7 356.50ms 14.82ms 95.8%
#8 356.55ms 14.86ms 95.8%
#9 359.67ms 14.90ms 95.9%
#10 358.74ms 14.89ms 95.8%
Snapshot 360.77ms 14.82ms 95.9%
Result 357.95ms (~) 14.88ms (~) 95.8% (~)

Median of 10 attempts (* = outlier, excluded from result), 5000 iterations x 10 rounds, 47.23s total

To run a specific benchmark, comment /benchmark <name>
attributes, aware, class, default, forwarding, merge, named-slots, no-attributes, slot, compilation

@ganyicz

ganyicz commented Sep 10, 2026

Copy link
Copy Markdown
Collaborator

Thanks @ghabriel25!

This looks good, however the same issue applies to any slot, not just the one created from loose content.

Can we check for empty whitespace whenever we're creating a placeholder for a slot?

@ghabriel25

Copy link
Copy Markdown
Contributor Author

@ganyicz Sure but its already 2AM here so I'll push it later.

@ghabriel25

Copy link
Copy Markdown
Contributor Author

@ganyicz Let me know if it needs additional test 👌

@ghabriel25 ghabriel25 changed the title Fix whitespace-only implicit slots during folding Fix whitespace-only implicit and explicit slots during folding Sep 11, 2026
@ghabriel25

Copy link
Copy Markdown
Contributor Author

/benchmark slot

@github-actions

Copy link
Copy Markdown
Contributor

Benchmark Result: Slot

Attempt Blade Blaze Change
#1 97.27ms 6.90ms 92.9%
#2 94.01ms 6.74ms 92.8%
#3 97.12ms 6.75ms 93%
#4 93.82ms 6.87ms 92.7%
#5 95.75ms 6.71ms 93%
#6 98.49ms 6.72ms 93.2%
#7 * 96.84ms 7.61ms 92.1%
#8 96.40ms 6.86ms 92.9%
#9 96.80ms 6.72ms 93.1%
#10 95.76ms 6.71ms 93%
Snapshot 95.22ms 6.75ms 92.9%
Result 96.40ms (~) 6.74ms (~) 93% (~)

Median of 10 attempts (* = outlier, excluded from result), 5000 iterations x 10 rounds, 14.04s total

To run a specific benchmark, comment /benchmark <name>
attributes, aware, class, default, forwarding, merge, named-slots, no-attributes, slot, compilation

Remove comment about skipping whitespace-only explicit slots.
@ganyicz

ganyicz commented Sep 12, 2026

Copy link
Copy Markdown
Collaborator

Thanks!

@ganyicz
ganyicz merged commit 5b7adc1 into livewire:main Sep 12, 2026
4 checks passed
@ghabriel25
ghabriel25 deleted the fix/empty-slot branch September 12, 2026 12:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Button with icon + icon:trailing and no text renders as square when Blaze is enabled

2 participants