Skip to content

Svelte 5: Can't set default snippet props #9878

@Not-Jayden

Description

@Not-Jayden

Describe the bug

A method that was working previously to ensure a snippet prop function will always be defined was by setting the snippet prop with a default snippet defined inside the current component.

i.e.

<script>
	let {children = fallback} = $props();
</script>

{#snippet fallback()}
	Fallback
{/snippet}

<button>
	{@render children()}
</button>

This seems to have stopped working though, potentially with the changes in #9759

Can still conditionally check the children prop is defined as a workaround for setting a fallback, but I do personally prefer being able to default it, given fallback and children should exist in the same scope anyway.

Reproduction

REPL

Logs

Error: `Cannot access 'fallback' before initialization`

System Info

Svelte REPL

Severity

annoyance

Metadata

Metadata

Assignees

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