mirror of https://github.com/sveltejs/svelte
fix: do not dispatch transition event with animation (#18122)
closes #18056 related: #17567 and #14009 # Changes move `dispatch_event()` calls in `transitions.js` out of `animate()` function using an additional `on_begin()` callback parameter. Doing so makes it possible to dispatch the `introstart` and `outrostart` events only from `transition()`. # Testing add a test checking that svelte dispatches no event when it runs an animationpull/18125/head
parent
48dc9b40c0
commit
51736e576d
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'svelte': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix: do not dispatch introstart event with animation of animate directive
|
||||||
@ -0,0 +1,31 @@
|
|||||||
|
import { flushSync } from 'svelte';
|
||||||
|
import { test } from '../../test';
|
||||||
|
|
||||||
|
export default test({
|
||||||
|
test({ assert, raf, target, logs }) {
|
||||||
|
let divs = target.querySelectorAll('div');
|
||||||
|
divs.forEach((div) => {
|
||||||
|
// @ts-expect-error
|
||||||
|
div.getBoundingClientRect = function () {
|
||||||
|
// @ts-expect-error
|
||||||
|
const index = [...this.parentNode.children].indexOf(this);
|
||||||
|
const top = index * 30;
|
||||||
|
|
||||||
|
return {
|
||||||
|
left: 0,
|
||||||
|
right: 100,
|
||||||
|
top,
|
||||||
|
bottom: top + 20
|
||||||
|
};
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
const [btn] = target.querySelectorAll('button');
|
||||||
|
flushSync(() => btn.click());
|
||||||
|
|
||||||
|
raf.tick(1);
|
||||||
|
assert.deepEqual(logs, []);
|
||||||
|
raf.tick(100);
|
||||||
|
assert.deepEqual(logs, []);
|
||||||
|
}
|
||||||
|
});
|
||||||
@ -0,0 +1,19 @@
|
|||||||
|
<script>
|
||||||
|
import { flip } from "svelte/animate";
|
||||||
|
|
||||||
|
let numbers = $state([0,1]);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<button onclick={() => numbers.reverse()}>reverse</button>
|
||||||
|
|
||||||
|
{#each numbers as num (num)}
|
||||||
|
<div
|
||||||
|
onintrostart={() => console.log("intro start")}
|
||||||
|
onoutrostart={() => console.log("outro start")}
|
||||||
|
onintroend={() => console.log("intro end")}
|
||||||
|
onoutroend={() => console.log("outro end")}
|
||||||
|
animate:flip={{ duration: 100 }}
|
||||||
|
>
|
||||||
|
{num}
|
||||||
|
</div>
|
||||||
|
{/each}
|
||||||
Loading…
Reference in new issue