ZL
About Articles Contact
Published on Sep 24, 2024
Filed under:
#javascript,
#svelte

Conditional Slot Forwarding is not a thing in Svelte 4

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!

Previous Clarifying the Relationship Between Popovers and Dialogs Next Killing and Restarting pm2

Join My Newsletter

I share what I’m learning on this newsletter: code, building businesses, and living well.

Sometimes I write about technical deep-dives, product updates, musings on how to live, and sometimes my struggles and how I’m breaking through.

Regardless of the type of content, I do my best to send you an update every week.

If you’re into making things and growing as a person, you’ll probably feel at home here.

“

Zell is the rare sort of developer who both knows his stuff and can explain even the most technical jargon in approachable — and even fun — ways!

I’ve taken his courses and always look forward to his writing because I know I’ll walk away with something that makes me a better front-ender.

Geoff Graham
Geoff Graham — Chief Editor @ CSS Tricks
The Footer

General

Home About Contact Testimonials Tools I Use

Projects

Magical Dev School Splendid Labz

Socials

Youtube Instagram Tiktok Github Bluesky X

Follow Along

Email RSS
© 2013 - 2025 Zell Liew / All rights reserved / Terms