From 3acfc65894c624cf6e8a59ebd15c1fdad55a8b10 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Tue, 25 Aug 2026 12:01:19 +0000 Subject: [PATCH] :recycle: Refactor detach-preview-sprite! to use atomic swap Use idiomatic atomic swap! update instead of non-atomic read-then-write pattern. The new implementation computes the decremented refs inside swap! and only removes the node when the result reaches zero. AI-assisted-by: mimo-v2.5 --- frontend/src/app/main/fonts.cljs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/frontend/src/app/main/fonts.cljs b/frontend/src/app/main/fonts.cljs index ddd613428b..644169d3de 100644 --- a/frontend/src/app/main/fonts.cljs +++ b/frontend/src/app/main/fonts.cljs @@ -238,12 +238,9 @@ the last open dropdown closes. The cached node and `:ids` stay, so reopening re-attaches without a refetch or re-parse." [node] - (let [refs (max 0 (dec (:refs @preview-sprite)))] - (if (pos? refs) - (swap! preview-sprite assoc :refs refs) - (do - (dom/remove! node) - (swap! preview-sprite assoc :refs 0))))) + (let [new-state (swap! preview-sprite update :refs #(max 0 (dec %)))] + (when (zero? (:refs new-state)) + (dom/remove! node)))) (defn- add-font-css! "Creates a style element and attaches it to the dom."