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

passing props to unnamed slot when there are more than 1 slots passes the variable to the wrong slot #7084

Closed
odama626 opened this issue Dec 30, 2021 · 7 comments

Comments

@odama626
Copy link

Describe the bug

when having a named slot and an unnamed slot, passing a variable to the unnamed slot provides it to the first slot and not necessarily the unnamed one

Reproduction

https://svelte.dev/repl/cb94e73b99dc4847b739e370e9eddbb2?version=3.44.3

Logs

No response

System Info

was able to reproduce in repl

Severity

annoyance

@Prinzhorn
Copy link
Contributor

Prinzhorn commented Dec 31, 2021

https://svelte.dev/repl/46a62731088a48b6844793d4a8230cea?version=3.44.3
https://svelte.dev/repl/970f84aea61e487883967984cec6c7f3?version=3.44.3
https://svelte.dev/repl/eccf3dc346a3404b91ff15a0118cdf51?version=3.44.3
https://svelte.dev/repl/44ab7935bfe4444d80d769162ae164fc?version=3.44.3

I think you need to explicitly have a "slot" attribute, because you need a top level element that receives the prop (you could have any number of divs that would all go into the default slot, you wouldn't expect each of them to get the prop).

Docs:

Named slots can also expose values. The let: directive goes on the element with the slot attribute.

https://svelte.dev/docs#template-syntax-slot-slot-key-value

But I think the compiler shouldn't compile let:value without slot, so I think this is a valid issue.

The fact that all slots receive the value is a limitation and I think there is already an open issue about that.

nvm, the docs say "Named slots can also expose values". You are exposing a value from the default slot and all slots receive it (#6049). If you have a value on a named slot, only the named slot receives it. So everything looks correct to me, with the exception that let:value without slot shouldn't compile so you would not have opened this issue.

@iacore
Copy link

iacore commented Jan 5, 2022

FYI, svelte:fragment can be used as a pseudo-element if you don't want any DOM element.

@odama626
Copy link
Author

odama626 commented Jan 5, 2022

Sorry, I didn't see your reply until now,

I think you need to explicitly have a "slot" attribute, because you need a top level element that receives the prop (you could have any number of divs that would all go into the default slot, you wouldn't expect each of them to get the prop).

I was mixing the use of a named slot with a default slot, which doesn't require a slot prop. Actually, looking at the last of your examples above it looks like you did the same thing just with a fragment instead of a div and it works... that seems like an inconsistency, it should also work with a div

using a slot without the slot prop is documented here https://svelte.dev/docs#template-syntax-slot

If this works:
https://svelte.dev/repl/44ab7935bfe4444d80d769162ae164fc?version=3.44.3

then you would expect it to work if you use a div instead of a svelte:fragment
https://svelte.dev/repl/6c6e7cc549d643e3aa83a182e3ea9d7a?version=3.44.3

furthermore, if I'm passing a value to the default slot, I don't expect it to be passed to named slots also, is that by design?

I was expecting

undefined
test value

but in the case of using a svelte:fragment you get

test value
test value

and in the case of using a div you get

test value
undefined

@iacore
Copy link

iacore commented Jan 6, 2022

I think your use of let: is wrong, yet the compiler did not complain about it. let: directive need to be on the "component element" for the default slot.

Example:
https://svelte.dev/repl/4cc5f18f8ab44d8cb61b38ec351c4ee7?version=3.44.3

@odama626
Copy link
Author

odama626 commented Jan 6, 2022

oh ok, so, should it not work with the svelte:fragment as well?

@saravanabalagi
Copy link

When both slots are named, each value mentioned against that slot is available inside the corresponding slot, REPL

@gtm-nayan
Copy link
Contributor

Fixed by #6049

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

5 participants