-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
use-directives are called multiple times when elements inside a keyed block are reordered #4693
Comments
This came up before in #2735, which was recently closed by its author who said it was now fixed - but perhaps it wasn't completely? I haven't looked closely at either repro or looked again at the PR that was said to resolve the other issue. |
Thanks. I did not see that one before (I had only searched for open issues...). This also explains where the (partial) solution came from. Just had a look at the issue as well as the previous example. The previous issue actually seems to be fixed because in that example, the keyed each block directly contains a div with the actions attached to it. Works: {#each ids as id (id)}
<div use:directive={{id}}>{id}</div>
{/each} Does not work: {#each ids as id (id)}
<ListItem {id}/>
{/each} I am not yet familiar with the Svelte compiler, but I believe it might be sufficient to change 3-4 areas:
Today evening I already attempted to change 1-3 and it worked in my small example (destroy was called for each action), but a whole lot of tests did not pass any more after the change and I have not yet figured out why. @tanhauhau : Looks like you are (much) more familiar with the compiler internals. Maybe you can have a look if my hunch is going in the right direction or not. |
… block are reordered (sveltejs#4693)
I had a second attempt at this today morning and got it working: All (non-JS) tests were passing and the issue was fixed in a test environment. So I continued to also update the JS tests (which compare the source code 1:1). Now all tests are passing again. Also tried this on a rather large & complex app (70K+ LOC) and it worked exactly as expected (remark: I don't use SSR, but I assume the tests should cover this). I guess it would be prudent to also write a test for this specific case (which I have not yet done), but before I take a shot at that and create a PR, it would be great if someone more experienced with the compiler internals could have a quick look at my changes: |
… block are reordered (sveltejs#4693)
After additional testing, I realized that there were still cases when Anyways, I added changes for these cases now as well (mainly By the way: since #4569 seemed very related to this one, I also tried the test case which is provided in there. It seems like that would be fixed as well. @rohanrichards: This is the link to the fork, in case you also want to give this a spin. As before: Any feedback from someone with more experience on the compiler on how they feel about the changes would be highly appreciated. Many thanks in advance! In the meantime I will also continue use my fork for active development to see if anything else might be missing. |
yeah component fragments do not receive the the real problem is that while local state in components is updating surgically, state in fragments is poorly managed and in most cases svelte simply pulls the old react on you & remounts everything as if the block was only just created I'll try to address this problem & #4699 this week this issue is unique to keyed each blocks as it is the only way in svelte to reorder nodes dynamically eventually I believe that actions should not be recalled on mere order change |
Ran into this issue today. Thanks for working on the fix! |
Co-authored-by: Christian Heine <[email protected]>
This has been fixed in 3.23.0 - https://svelte.dev/repl/4b0807cd0596423b94e31a24bde9497a?version=3.23.0 |
Description of the bug
To Reproduce
Expected behavior
Information about the Svelte project:
Severity
Additional context
Previous analysis
It seems that remounting was considered, but the information (that the current operation is indeed a remount) gets lost due to an additional block in between. It's a bit hard to describe verbally. So here are the relevant parts of a debugger session (from the same app as in the example REPL):
The text was updated successfully, but these errors were encountered: