Skip to content
Merged
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
5 changes: 5 additions & 0 deletions .changeset/bright-peas-juggle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

A transition's parameters are now evaluated when the transition is initialized.
10 changes: 5 additions & 5 deletions packages/svelte/src/internal/client/transitions.js
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,6 @@ function is_transition_block(block) {
export function bind_transition(dom, transition_fn, props_fn, direction, global) {
const transition_effect = /** @type {import('./types.js').EffectSignal} */ (current_effect);
const block = current_block;
const props = props_fn === null ? {} : props_fn();

let can_show_intro_on_mount = true;
let can_apply_lazy_transitions = false;
Expand Down Expand Up @@ -458,8 +457,9 @@ export function bind_transition(dom, transition_fn, props_fn, direction, global)
effect(() => {
/** @param {DOMRect} [from] */
const init = (from) =>
untrack(() =>
direction === 'key'
untrack(() => {
const props = props_fn === null ? {} : props_fn();
return direction === 'key'
? /** @type {import('./types.js').AnimateFn<any>} */ (transition_fn)(
dom,
{ from: /** @type {DOMRect} */ (from), to: dom.getBoundingClientRect() },
Expand All @@ -468,8 +468,8 @@ export function bind_transition(dom, transition_fn, props_fn, direction, global)
)
: /** @type {import('./types.js').TransitionFn<any>} */ (transition_fn)(dom, props, {
direction
})
);
});
});

transition = create_transition(dom, init, direction, transition_effect);
const is_intro = direction === 'in';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { test } from '../../test';

export default test({
test({ assert, component, target }) {
const div = /** @type {HTMLDivElement & { foo?: number }} */ (target.querySelector('div'));

assert.equal(div.foo, undefined);
component.foo = 2;
component.visible = false;
assert.equal(div.foo, 2);
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<script>
const { visible = true, foo = 1 } = $props();

function bar(node, params) {
node.foo = params;
return () => ({});
}
</script>

{#if visible}
<div transition:bar={foo}></div>
{/if}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { test } from '../../test';

export default test({
test({ assert, component, target, raf }) {
component.visible = true;

const div = /** @type {HTMLDivElement & { foo: number }} */ (target.querySelector('div'));
raf.tick(0);
assert.equal(div.foo, 0);

raf.tick(50);
assert.equal(div.foo, 0.5);
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<script>
const { visible = false } = $props();

function foo(node, params) {
return {
duration: 100,
tick: t => {
node.foo = t;
}
};
}
</script>

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