Skip to content

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

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

Merged
merged 1 commit into from
Jan 31, 2024
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/quiet-timers-speak.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

fix: correctly update tweened store initialized with nullish value
3 changes: 2 additions & 1 deletion packages/svelte/src/motion/tweened.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 10 additions & 0 deletions packages/svelte/tests/motion/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
});