Skip to content
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

fix: always call tick() if defined in transitions #12883

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions packages/svelte/src/internal/client/dom/elements/transitions.js
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,7 @@ function animate(element, options, counterpart, t2, on_finish, on_abort) {
animation.finished
.then(() => {
on_finish?.();
on_finish = undefined;

if (t2 === 1) {
animation.cancel();
Expand All @@ -422,22 +423,25 @@ function animate(element, options, counterpart, t2, on_finish, on_abort) {
}
});
});
} else {
}

if (tick) {
// Timer
if (t1 === 0) {
tick?.(0, 1); // TODO put in nested effect, to avoid interleaved reads/writes?
tick(0, 1); // TODO put in nested effect, to avoid interleaved reads/writes?
}

task = loop((now) => {
if (now >= end) {
tick?.(t2, 1 - t2);
tick(t2, 1 - t2);
on_finish?.();
on_finish = undefined;
return false;
}

if (now >= start) {
var p = t1 + delta * easing((now - start) / duration);
tick?.(p, 1 - p);
tick(p, 1 - p);
}

return true;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { flushSync } from 'svelte';
import { ok, test } from '../../test';

export default test({
test({ assert, component, target, raf, logs }) {
const button = target.querySelector('button');

flushSync(() => button?.click());
const div = target.querySelector('div');
ok(div);

let ended = 0;
div.addEventListener('introend', () => {
ended += 1;
});

assert.equal(div.style.scale, '0');
assert.deepEqual(logs, ['tick: 0']);

raf.tick(50);
assert.equal(div.style.scale, '0.5');
assert.deepEqual(logs, ['tick: 0', 'tick: 0.5']);

raf.tick(100);
assert.equal(div.style.scale, '');
assert.deepEqual(logs, ['tick: 0', 'tick: 0.5', 'tick: 1']);

assert.equal(ended, 1);
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<script>
let visible = false;

function foo() {
return {
duration: 100,
css: (t) => {
return `scale: ${t}`;
},
tick: (t) => {
console.log(`tick: ${t}`);
}
};
}
</script>

<button on:click={() => (visible = !visible)}>toggle</button>

{#if visible}
<div transition:foo></div>
{/if}
Loading