New Sep 24, 2024

Conditional Slot Forwarding is not a thing in Svelte 4

More Front-end Bloggers All from Zell Liew View Conditional Slot Forwarding is not a thing in Svelte 4 on zellwk.com

(Hey, we're having problems showing images in RSS right now, so if you want a better reading experience, consider viewing this article online [here](https://zellwk.com//blog/svelte-4-conditional-forwarding. We hope to fix this soon!).

If you ever wanted to forward conditional slots up two component levels, you're out of luck.

<!-- Grandchild -->
<slot name="label" />
<!-- Child -->
{#if $$slots.label}
  <slot name="label" slot="label" />
{/if}

Conditional Slot Forwarding is probably never gonna be a thing in Svelte 4.

Tan Li Hau has created a PR to make this possible, but Rich Harris closed the PR, stating that snippets (a Svelte 5 feature that replaces slots) will resolve this use case.

We can only hope that Svelte 5 indeed solves this issue — and that porting over Svelte 4 code will not be too much of a pain!

Scroll to top