-
-
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
Discussion: Allow <svelte:self> as slot without if/each block? #2798
Comments
That is true, but at the same time it tightly couples the implementation of the other component to one with |
I don't know, that feels a little like a rationalization of the current behavior. Is the limitation there to enforce a certain architecture, or to help someone along when they create an obvious infinite loop? |
I think it's more about preventing accidental infinite loop. When you build an app and integrate an infinite loop you can pretty much see that something broke when you open your browser and it gets stuck. However, when you are refactoring a greater codebase you don't want to be constantly thinking about where the children are used throughout the app and removing that inside |
In 3.20.0, you can now use |
The API docs say the following about
<svelte:self>
:However, there is at least one case where unbounded recursion can be prevented, outside of
#if
/#each
, which is when<svelte:self>
is used as a slot in another component. That component may expose the slot conditionally in a way that restricts recursion depth.See REPL for a silly example that would run if the compiler allowed it: https://svelte.dev/repl/6df2eaa40872455d9ab9487351687281?version=3.4.1
Here I've wrapped it in a pointless
if
just to appease the compiler:https://svelte.dev/repl/bca90979b8e444cdb05b13969cb6e601?version=3.4.1
If the purpose is to prevent guaranteed infinite loops, rather than risk of infinite loops, the compiler should arguably allow a pattern like this too.
The text was updated successfully, but these errors were encountered: