Skip to content

[Svelte 5] Optinal snippets in pair tags does not work with {#if}{/if} #13391

@gyzerok

Description

@gyzerok

Describe the bug

Given component (notice how footer is optional)

<script lang="ts">
	type Props = {
		children: Snippet
		footer?: Snippet
	}
	const { children, footer } = $props()
</script>

<div>
	{@render children()}
	{#if footer}
		{@render footer()}
	{/if}
</div>

This is allowed

<script lang="ts">
	import Bug from './Bug.svelte'
</script>

<Bug>
	{#snippet children()}
		children
	{/snippet}

	{#snippet footer()}
		footer
	{/snippet}
</Bug>
<script lang="ts">
	import Bug from './Bug.svelte'
</script>

<Bug>
	{#snippet children()}
		children
	{/snippet}
</Bug>

While this gives an error Cannot use explicit children snippet at the same time as implicit children content. Remove either the non-whitespace content or the children snippet block

<script lang="ts">
	import Bug from './Bug.svelte'
</script>

<Bug>
	{#snippet children()}
		children
	{/snippet}

	{#if true}
		{#snippet footer()}
			footer
		{/snippet}
	{/if}
</Bug>

Not sure if this is a limitation or bug. If latter in my opinion this should just work.

Reproduction

Link to the playgound

Logs

No response

System Info

irrelevant

Severity

annoyance

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions