Skip to content

Commit 8a013c4

Browse files
authored
fix: transition parameters are not reactive (#9836)
* test: add tests of transitions in new runtime * fix: move evaluation of props * format * add changeset
1 parent 180b332 commit 8a013c4

File tree

6 files changed

+64
-5
lines changed

6 files changed

+64
-5
lines changed

.changeset/bright-peas-juggle.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
A transition's parameters are now evaluated when the transition is initialized.

packages/svelte/src/internal/client/transitions.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,6 @@ function is_transition_block(block) {
421421
export function bind_transition(dom, get_transition_fn, props_fn, direction, global) {
422422
const transition_effect = /** @type {import('./types.js').EffectSignal} */ (current_effect);
423423
const block = current_block;
424-
const props = props_fn === null ? {} : props_fn();
425424

426425
let can_show_intro_on_mount = true;
427426
let can_apply_lazy_transitions = false;
@@ -467,8 +466,9 @@ export function bind_transition(dom, get_transition_fn, props_fn, direction, glo
467466
const transition_fn = get_transition_fn();
468467
/** @param {DOMRect} [from] */
469468
const init = (from) =>
470-
untrack(() =>
471-
direction === 'key'
469+
untrack(() => {
470+
const props = props_fn === null ? {} : props_fn();
471+
return direction === 'key'
472472
? /** @type {import('./types.js').AnimateFn<any>} */ (transition_fn)(
473473
dom,
474474
{ from: /** @type {DOMRect} */ (from), to: dom.getBoundingClientRect() },
@@ -477,8 +477,8 @@ export function bind_transition(dom, get_transition_fn, props_fn, direction, glo
477477
)
478478
: /** @type {import('./types.js').TransitionFn<any>} */ (transition_fn)(dom, props, {
479479
direction
480-
})
481-
);
480+
});
481+
});
482482

483483
transition = create_transition(dom, init, direction, transition_effect);
484484
const is_intro = direction === 'in';
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { test } from '../../test';
2+
3+
export default test({
4+
test({ assert, component, target }) {
5+
const div = /** @type {HTMLDivElement & { foo?: number }} */ (target.querySelector('div'));
6+
7+
assert.equal(div.foo, undefined);
8+
component.foo = 2;
9+
component.visible = false;
10+
assert.equal(div.foo, 2);
11+
}
12+
});
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<script>
2+
const { visible = true, foo = 1 } = $props();
3+
4+
function bar(node, params) {
5+
node.foo = params;
6+
return () => ({});
7+
}
8+
</script>
9+
10+
{#if visible}
11+
<div transition:bar={foo}></div>
12+
{/if}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { test } from '../../test';
2+
3+
export default test({
4+
test({ assert, component, target, raf }) {
5+
component.visible = true;
6+
7+
const div = /** @type {HTMLDivElement & { foo: number }} */ (target.querySelector('div'));
8+
raf.tick(0);
9+
assert.equal(div.foo, 0);
10+
11+
raf.tick(50);
12+
assert.equal(div.foo, 0.5);
13+
}
14+
});
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<script>
2+
const { visible = false } = $props();
3+
4+
function foo(node, params) {
5+
return {
6+
duration: 100,
7+
tick: t => {
8+
node.foo = t;
9+
}
10+
};
11+
}
12+
</script>
13+
14+
{#if visible}
15+
<div transition:foo></div>
16+
{/if}

0 commit comments

Comments
 (0)