0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-03-17 18:21:23 -05:00

Merge pull request #3856 from penpot/niwinz-develop-bugfixes-1

🐛 Add missing retry cancelation when thumbnail is discarded
This commit is contained in:
Aitor Moreno 2023-11-28 17:48:08 +01:00 committed by GitHub
commit 6ed35ffdc8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 3 deletions

View file

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

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