mirror of https://github.com/sveltejs/svelte
fix: ensure previous transitions are properly aborted (#12460)
* fix: ensure previous transitions are properly aborted - nullify options when the transition is aborted. This ensures a change in options is reflected the next time, else it would stick around indefinetly - abort previous intro (if exists) when new intro plays (same for outro) fixes #11372 * add a test --------- Co-authored-by: Rich Harris <rich.harris@vercel.com>pull/12459/head
parent
436cc99740
commit
3d354f0d5c
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'svelte': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix: ensure previous transitions are properly aborted
|
@ -0,0 +1,27 @@
|
|||||||
|
import { test } from '../../test';
|
||||||
|
|
||||||
|
export default test({
|
||||||
|
get props() {
|
||||||
|
return { visible: false };
|
||||||
|
},
|
||||||
|
|
||||||
|
test({ assert, component, target, raf, logs }) {
|
||||||
|
component.visible = true;
|
||||||
|
const span = /** @type {HTMLSpanElement & { foo: number }} */ (target.querySelector('span'));
|
||||||
|
|
||||||
|
raf.tick(50);
|
||||||
|
assert.equal(span.foo, 0.5);
|
||||||
|
|
||||||
|
component.visible = false;
|
||||||
|
assert.equal(span.foo, 0.5);
|
||||||
|
|
||||||
|
raf.tick(75);
|
||||||
|
assert.equal(span.foo, 0.25);
|
||||||
|
|
||||||
|
component.visible = true;
|
||||||
|
raf.tick(100);
|
||||||
|
assert.equal(span.foo, 0.5);
|
||||||
|
|
||||||
|
assert.deepEqual(logs, ['transition']); // should only run once
|
||||||
|
}
|
||||||
|
});
|
@ -0,0 +1,18 @@
|
|||||||
|
<script>
|
||||||
|
export let visible;
|
||||||
|
|
||||||
|
function foo(node) {
|
||||||
|
console.log('transition');
|
||||||
|
|
||||||
|
return {
|
||||||
|
duration: 100,
|
||||||
|
tick: (t) => {
|
||||||
|
node.foo = t;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{#if visible}
|
||||||
|
<span transition:foo>hello</span>
|
||||||
|
{/if}
|
@ -0,0 +1,31 @@
|
|||||||
|
import { test } from '../../test';
|
||||||
|
|
||||||
|
export default test({
|
||||||
|
get props() {
|
||||||
|
return { visible: false };
|
||||||
|
},
|
||||||
|
|
||||||
|
test({ assert, component, target, raf, logs }) {
|
||||||
|
component.visible = true;
|
||||||
|
const span = /** @type {HTMLSpanElement & { foo: number, bar: number }} */ (
|
||||||
|
target.querySelector('span')
|
||||||
|
);
|
||||||
|
|
||||||
|
raf.tick(50);
|
||||||
|
assert.equal(span.foo, 0.5);
|
||||||
|
|
||||||
|
component.visible = false;
|
||||||
|
assert.equal(span.foo, 0.5);
|
||||||
|
|
||||||
|
raf.tick(75);
|
||||||
|
assert.equal(span.foo, 0.75);
|
||||||
|
assert.equal(span.bar, 0.75);
|
||||||
|
|
||||||
|
component.visible = true;
|
||||||
|
raf.tick(100);
|
||||||
|
assert.equal(span.foo, 0.25);
|
||||||
|
assert.equal(span.bar, 1);
|
||||||
|
|
||||||
|
assert.deepEqual(logs, ['in', 'out', 'in']);
|
||||||
|
}
|
||||||
|
});
|
@ -0,0 +1,29 @@
|
|||||||
|
<script>
|
||||||
|
export let visible;
|
||||||
|
|
||||||
|
function foo(node) {
|
||||||
|
console.log('in');
|
||||||
|
|
||||||
|
return {
|
||||||
|
duration: 100,
|
||||||
|
tick: (t) => {
|
||||||
|
node.foo = t;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function bar(node) {
|
||||||
|
console.log('out');
|
||||||
|
|
||||||
|
return {
|
||||||
|
duration: 100,
|
||||||
|
tick: (t) => {
|
||||||
|
node.bar = t;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{#if visible}
|
||||||
|
<span in:foo out:bar>hello</span>
|
||||||
|
{/if}
|
Loading…
Reference in new issue