Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Undefined values when using a let binding from the default slot inside a named slot. #7497

Closed
dimfeld opened this issue Apr 29, 2022 · 2 comments

Comments

@dimfeld
Copy link
Contributor

dimfeld commented Apr 29, 2022

Describe the bug

When using a value from a let:binding on the default slot inside a named slot, the bound value is sometimes undefined if the named slot is instantiated more than once in the child component.

<!-- App.svelte -->
<AThing let:showA>
	<div slot="a">
		{showA}
	</div>
</AThing>
<!-- AThing.svelte -->
<script>
	export let showA = true;
</script>

<slot name="a" />
<slot name="a" />

<slot {showA} />

I'm actually not sure if this is even valid to do. My intuition is that using a let binding from the default slot inside a named slot is sort of a scope violation and so the compiler should throw an error (or at least a warning to avoid breaking behavior).

If Svelte intentionally allows this, then the bug is just that showA is undefined in the first instantiation of the named slot.

Also related, the second half of this comment

Reproduction

https://svelte.dev/repl/a9bb52762959444da8da018ab04f6c7b?version=3.47.0

Logs

No response

System Info

Svelte REPL, 3.47.0. Also reproduced on 3.46.6 and this has presumably been around for a while.

Severity

annoyance

@dimfeld dimfeld changed the title Buggy behavior when using a let binding from the default slot inside a named slot. Undefined values when using a let binding from the default slot inside a named slot. Apr 29, 2022
@dimfeld
Copy link
Contributor Author

dimfeld commented Apr 30, 2022

Related: #7485 and #7245

@gtm-nayan
Copy link
Contributor

I'm actually not sure if this is even valid to do. My intuition is that using a let binding from the default slot inside a named slot is sort of a scope violation and so the compiler should throw an error (or at least a warning to avoid breaking behavior).

This is now disallowed from v4.0 onwards

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

No branches or pull requests

2 participants