Skip to content

Commit 36fc203

Browse files
authored
fix: correctly update tweened store initialized with nullish value (#10356)
Co-authored-by: Rich Harris <[email protected]>
1 parent a53b443 commit 36fc203

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

.changeset/quiet-timers-speak.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
fix: correctly update tweened store initialized with nullish value

packages/svelte/src/motion/tweened.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,12 @@ export function tweened(value, defaults = {}) {
8989
* @param {import('./private').TweenedOptions<T>} [opts]
9090
*/
9191
function set(new_value, opts) {
92+
target_value = new_value;
93+
9294
if (value == null) {
9395
store.set((value = new_value));
9496
return Promise.resolve();
9597
}
96-
target_value = new_value;
9798

9899
/** @type {import('../internal/client/types').Task | null} */
99100
let previous_task = task;

packages/svelte/tests/motion/test.ts

+10
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,15 @@ describe('motion', () => {
2626
size.set(100, { duration: 0 });
2727
assert.equal(get(size), 100);
2828
});
29+
30+
it('updates correctly when initialized with a `null`-ish value', () => {
31+
const size = tweened(undefined as unknown as number, { duration: 0 });
32+
33+
size.set(10);
34+
assert.equal(get(size), 10);
35+
36+
size.update((v) => v + 10);
37+
assert.equal(get(size), 20);
38+
});
2939
});
3040
});

0 commit comments

Comments
 (0)