From 538ef3a3a41ce2a13bcaf61a2e75e231b83ddb07 Mon Sep 17 00:00:00 2001 From: marc2332 Date: Sun, 12 Jan 2025 23:43:30 +0100 Subject: [PATCH] fix: Manually drop previous animated values when the run callback reruns --- crates/hooks/src/use_animation.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/crates/hooks/src/use_animation.rs b/crates/hooks/src/use_animation.rs index 9f5718367..eb789d2f3 100644 --- a/crates/hooks/src/use_animation.rs +++ b/crates/hooks/src/use_animation.rs @@ -753,11 +753,16 @@ pub fn use_animation( let has_run_yet = use_signal(|| false); let task = use_signal(|| None); let last_direction = use_signal(|| AnimDirection::Reverse); + let mut prev_value = use_signal::>>(|| None); let context = use_memo(move || { + if let Some(prev_value) = prev_value.take() { + prev_value.manually_drop(); + } let mut conf = AnimConfiguration::default(); let value = run(&mut conf); let value = Signal::new(value); + prev_value.set(Some(value)); Context { value, conf } }); @@ -791,11 +796,16 @@ where let has_run_yet = use_signal(|| false); let task = use_signal(|| None); let last_direction = use_signal(|| AnimDirection::Reverse); + let mut prev_value = use_signal::>>(|| None); let context = use_memo(use_reactive(deps, move |deps| { + if let Some(prev_value) = prev_value.take() { + prev_value.manually_drop(); + } let mut conf = AnimConfiguration::default(); let value = run(&mut conf, deps); let value = Signal::new(value); + prev_value.set(Some(value)); Context { value, conf } }));