diff --git a/frontend/src/app/main/ui/workspace/shapes/frame.cljs b/frontend/src/app/main/ui/workspace/shapes/frame.cljs index 5deae5db4..8d5968447 100644 --- a/frontend/src/app/main/ui/workspace/shapes/frame.cljs +++ b/frontend/src/app/main/ui/workspace/shapes/frame.cljs @@ -123,6 +123,7 @@ tries-ref (mf/use-ref 0) imposter-ref (mf/use-ref nil) + task-ref (mf/use-ref nil) on-load (mf/use-fn #(mf/set-ref-val! tries-ref 0)) on-error (mf/use-fn @@ -135,14 +136,20 @@ (when-not (nil? imposter) (dom/set-attribute! imposter "href" thumbnail-uri))))] (when (< new-tries 8) - (tm/schedule delay-in-ms retry-fn)))))] + (mf/set-ref-val! task-ref (tm/schedule delay-in-ms retry-fn))))))] ;; NOTE: we don't add deps because we want this to be executed ;; once on mount with only referenced the initial data (mf/with-effect [] (when-not (some? thumbnail-uri) (tm/schedule-on-idle - #(st/emit! (dwt/request-thumbnail file-id page-id frame-id "frame"))))) + #(st/emit! (dwt/request-thumbnail file-id page-id frame-id "frame")))) + #(when-let [task (mf/ref-val task-ref)] + (d/close! task))) + + (mf/with-effect [thumbnail-uri] + (when-let [task (mf/ref-val task-ref)] + (d/close! task))) (fdm/use-dynamic-modifiers objects (mf/ref-val content-ref) modifiers) diff --git a/frontend/src/app/util/timers.cljs b/frontend/src/app/util/timers.cljs index 5c56f2298..0e5a01c33 100644 --- a/frontend/src/app/util/timers.cljs +++ b/frontend/src/app/util/timers.cljs @@ -6,6 +6,7 @@ (ns app.util.timers (:require + [app.common.data :as d] [beicon.core :as rx] [promesa.core :as p])) @@ -14,7 +15,12 @@ (schedule 0 func)) ([ms func] (let [sem (js/setTimeout #(func) ms)] - (reify rx/IDisposable + (reify + d/ICloseable + (close! [_] + (js/clearTimeout sem)) + + rx/IDisposable (-dispose [_] (js/clearTimeout sem))))))