Skip to content

Commit

Permalink
fix: Make Tween work with continuous target changes (#14895)
Browse files Browse the repository at this point in the history
* Read previous_value at a later stage in Tween.set

* Add changeset

* tweak

---------

Co-authored-by: Rich Harris <[email protected]>
  • Loading branch information
TheSpeedM and Rich-Harris authored Jan 6, 2025
1 parent dbdb8cd commit a646780
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/violet-cows-reply.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

fix: make Tween work with continuous target changes
7 changes: 4 additions & 3 deletions packages/svelte/src/motion/tweened.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,6 @@ export class Tween {
set(value, options) {
set(this.#target, value);

let previous_value = this.#current.v;
let previous_task = this.#task;

let started = false;
Expand All @@ -254,10 +253,12 @@ export class Tween {
if (!started) {
started = true;

fn = interpolate(/** @type {any} */ (previous_value), value);
const prev = this.#current.v;

fn = interpolate(prev, value);

if (typeof duration === 'function') {
duration = duration(/** @type {any} */ (previous_value), value);
duration = duration(prev, value);
}

previous_task?.abort();
Expand Down

0 comments on commit a646780

Please sign in to comment.