Skip to content

Svelte 5: flip reordering causes duplication and glitches #9805

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

Closed
brunnerh opened this issue Dec 6, 2023 · 5 comments · Fixed by #9839 or #9842
Closed

Svelte 5: flip reordering causes duplication and glitches #9805

brunnerh opened this issue Dec 6, 2023 · 5 comments · Fixed by #9839 or #9842
Assignees

Comments

@brunnerh
Copy link
Member

brunnerh commented Dec 6, 2023

Describe the bug

Using animate:flip in an #each and completely reordering the list causes duplicated items and a broken animation (elements leaving the bounds of the list and such).

When moving one item to the other end of the list at a time, the animation disappears after having moved all of them. Also, only one item is animated even though all items have to move and thus should be animated.

Not sure how this relates to #9655, which also uses transitions. If this is just a special case, feel free to close this as duplicate.

Reproduction

Svelte 4
Svelte 5


Tried a more simple example where one item gets moved from start of list to the end:

<script>
	import { flip } from 'svelte/animate';

	let items = Array.from({ length: 5 }, (_, i) => ({ id: i, text: `Item ${i+1}` }))

	function update() {
		const [first, ...rest] = items;
		items = [...rest, first];
	}
</script>

<button on:click={update}>Shift</button>
<div class="list">
	{#each items as item (item.id)}
		<div animate:flip>{item.text}</div>
	{/each}
</div>

REPL

Here the animation disappears after cycling through the list once.

Logs

No response

System Info

REPL - Svelte v5.0.0-next.19

Severity

annoyance

@brunnerh brunnerh changed the title Svelte 5: Flip reordering is causes duplication and glitches Svelte 5: flip reordering is causes duplication and glitches Dec 6, 2023
@trueadm trueadm self-assigned this Dec 7, 2023
@brunnerh
Copy link
Member Author

brunnerh commented Dec 7, 2023

@trueadm The duplications are gone, but the animation seems to still be off.
Compare:
Svelte 5 (preview of PR)
Svelte 4

(Or is there another fix for that which is not included here?)

@trueadm
Copy link
Contributor

trueadm commented Dec 7, 2023

I'm working on another PR for the animation bug. I was more addressing the duplicated content.

@brunnerh
Copy link
Member Author

brunnerh commented Dec 14, 2023

@trueadm #9917 seems to mostly clean up the issue, but there can still be oddities when animations overlap.

Recorded a clip where I use Enter and its re-fire rate to provoke the issue (which does not happen in v4):

each-flip-glitches.webm

@trueadm
Copy link
Contributor

trueadm commented Dec 14, 2023

@brunnerh Unfortunately, the current system for reconciling each blocks doesn't try to reverse previous transitions. I couldn't make it work this way with signals and how various parts of the reconciliation system work. So you'll see slightly glitchy behavior right now doing what you do. I'm unsure if this will ever be something we can solve.

@brunnerh brunnerh changed the title Svelte 5: flip reordering is causes duplication and glitches Svelte 5: flip reordering causes duplication and glitches Dec 14, 2023
@hakoomen
Copy link

I want to reopen this issue, the animation glitch is still there (see the REPLs in the issue).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants