Skip to content

Svelte 5: error with a slot prop directly referenced #9797

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

Closed
mquandalle opened this issue Dec 5, 2023 · 1 comment · Fixed by #10395
Closed

Svelte 5: error with a slot prop directly referenced #9797

mquandalle opened this issue Dec 5, 2023 · 1 comment · Fixed by #10395

Comments

@mquandalle
Copy link

Describe the bug

I have 2 components:

  • a <BikeItem bike="" /> that accept a bike prop
  • a <FancyList items=[]> that accept an items prop and a slot slot="item"

The following code works with Svelte 4 but not with Svelte 5:

<script>
	import FancyList from "./FancyList.svelte"
	import BikeItem from "./BikeItem.svelte"

	const bikes = ['brompton', 'canyon']
</script>

<FancyList items={bikes}>
	<BikeItem slot="item" let:item={bike} {bike} />
</FancyList>

Svelte 4 REPL

Reproduction

https://svelte-5-preview.vercel.app/#H4sIAAAAAAAAE51QQWrDMBD8itgefDHx3bUN7aEQ6A-iHBxlTUVtSUibUiP090pyY4cGSulJq93ZmdnxMMgRHdQHD6qfEGp4MgZKoNmkj_vAkTD-nb5YkTqNE1Ya6rjiJCejLbGXXon5VTpig9UT47Cr1tZuYeBwg3-W77gnnDb4tXOLjnihVSQ9xaFjLTsUp4g3pFVRskL0ao7Vkaum2iypZjMjI6FrfV4P2W-zKrtRU8shQTiwEalO5QIO7PupukS-EnYxhkmf5SDxDDXZC4ZyTW1F_TU7_MxZROnF6OOPQ_wD9uJtmbHe5SLkI5J3lmS3A3yeZsO-SnvhN6_XFP5hNQVz5zSndS94DF8HX7LpXgIAAA==

Logs

No response

System Info

Svelte 5

Severity

annoyance

@dimfeld
Copy link
Contributor

dimfeld commented Feb 5, 2024

Starting to look into this... it appears that this is only a problem when it's a Svelte component on the slot, not a regular HTML element.

I wrote a test for this based on the component-slot-let-named test, where the template looks like this:

<Nested {things}>
	<SlotInner slot="foo" let:thing {thing} />
</Nested>

The above fails with the same error in the original issue description. If I change it to this:

<Nested {things}>
	<div slot="foo" let:thing>{thing}</div>
</Nested>

Then it works. In the working version, the generated server code contains the line const thing = $$slotProps.thing;, which is absent in the first version. Similar for the client code.

It should just be a matter of rendering that line in the first case as well. Seems a bit tricky so far though that may just be my lack of familiarity with the Svelte 5 parser overall.

dummdidumm added a commit that referenced this issue Feb 6, 2024
Fixes #9797
Also added missing validation error around duplicate slots

---------

Co-authored-by: Simon Holthausen <[email protected]>
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

Successfully merging a pull request may close this issue.

2 participants