-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Svelte 4/5: Children/slot rerenders DOM when moved #12895
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
Comments
Since this would be considered a breaking change, I think Svelte 5 is where this could potentially be fixed |
In {@render children() as "key"} This syntax could open a lot of possibilities and would avoid making a breaking change. |
Unfortunately, we have to do this as Svelte doesn't use a virtual DOM, so it doesn't know that the DOM structures for both are the same/similar. Making this change would be a huge amount of work and we don't want to block the Svelte 5 launch any longer than we can afford to with these sorts of changes. |
Couldn't we tell that by comparing the snippet reference Anyway, could this be considered for 5.x then? The keyed approach is opt in, so that wouldn't be a breaking change. This feature opens quite a lot of optimization possibilities and behaviors that weren't possible before. Btw, do you like the proposed API? Maybe there is a better keyword than |
Describe the bug
When doing a conditional wrapping like so:
When the
wrap
variable changes, all the children are rerendered. Meaning all the DOM nodes inside are recreated, even though they themselves have not changed. This could cause performance issues and inconsistency. For example, it triggers all the transitions again. It would be really nice if when children/slot moves in markup, Svelte would also move the corresponding DOM node instead of creating a new one (which is exactly the same).I would like to know if there is currently any workaround to achieve the conditional wrapping without rerendering. It would be nice if there is any way to prevent transitions from triggering at least. This is what broke my app and made me discover this behavior.
#7528 related
Reproduction
Svelte 5 REPL
In the REPL it is clear that
Math.random()
reruns every timewrap
is changed. Thein:fly
transition is triggered every time as well. Also you can check the console to verify thatdiv
with idnode
is different on every instantiation.Logs
No response
System Info
Severity
annoyance
The text was updated successfully, but these errors were encountered: