fix: correctly update tweened store initialized with nullish value (#10356)

Co-authored-by: Rich Harris <rich.harris@vercel.com>
pull/10353/head
Rich Harris 5 months ago committed by GitHub
parent a53b44338e
commit 36fc203eec
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: correctly update tweened store initialized with nullish value

@ -89,11 +89,12 @@ export function tweened(value, defaults = {}) {
* @param {import('./private').TweenedOptions<T>} [opts]
*/
function set(new_value, opts) {
target_value = new_value;
if (value == null) {
store.set((value = new_value));
return Promise.resolve();
}
target_value = new_value;
/** @type {import('../internal/client/types').Task | null} */
let previous_task = task;

@ -26,5 +26,15 @@ describe('motion', () => {
size.set(100, { duration: 0 });
assert.equal(get(size), 100);
});
it('updates correctly when initialized with a `null`-ish value', () => {
const size = tweened(undefined as unknown as number, { duration: 0 });
size.set(10);
assert.equal(get(size), 10);
size.update((v) => v + 10);
assert.equal(get(size), 20);
});
});
});

Loading…
Cancel
Save