-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Cannot use exported functions from a named slot in another slot #7485
Comments
I did some search and test with the compiler, I think there is a problem (or an undocumented behavior) for named-slot props and default slot props. If I change the <!-- Outer.svelte -->
<Inner let:innerCall>
<svelte:fragment slot="inner_slot">
<slot outerCall={() => innerCall()} />
</svelte:fragment>
</Inner> then there is no error. My expectation is:
The current behavior:
This is something already reported in #7245. In fact, all props in named-slots are exposed to the component root. My example: So you can (and maybe should) ignore what official doc said:
Just always use let: at the component root.
The fact that this test case passes kind of proved this: |
The bug is here is not about named slot or default slot, as both will cause error:
or
As @legnaleurc said, the bug here could be solved by
After debugging, I think the culprit is this line, which has not put node type "SlotTemplate" into consideration. Maybe you'd wonder why pass innerCall as-is works but arrow function does not work.
The reason is that it is evaluated as "literal" type and not entering "function_expression" if block. |
This is fixed in 3.50.0 - https://svelte.dev/repl/f3777f8560d74cb9a6bdc1f6e1eb334e?version=3.50.0 |
Describe the bug
This will throw an exception like:
while compiling.
I haven't test all cases, but I think this only happens for named slots.
If
Inner
only provides default slot then this will work.And if I don't use arrow function, just pass
innerCall
as-is, then it can pass.e.g.
<slot outerCall={innerCall} />
Also use
innerCall
in normal HTML tags works.e.g.
<button on:click={() => innerCall()}
Reproduction
https://svelte.dev/repl/f3777f8560d74cb9a6bdc1f6e1eb334e?version=3.47.0
Logs
Severity
annoyance
The text was updated successfully, but these errors were encountered: