0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-03-14 16:51:18 -05:00

🐛 Add missing retry cancelation when thumbnail is discarded

This commit is contained in:
Andrey Antukh 2023-11-24 17:03:10 +01:00 committed by Aitor
parent 0528c26b5e
commit 5486ab43a8
2 changed files with 16 additions and 3 deletions

View file

@ -125,6 +125,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
@ -137,14 +138,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)

View file

@ -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))))))