From 82796822d160d75e3f69e4c6bca8e6f37ad7b4a3 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Tue, 15 Feb 2022 11:13:16 +0100 Subject: [PATCH] :bug: Fix possible race condition on component rename and deletion --- CHANGES.md | 1 + .../app/main/data/workspace/libraries.cljs | 43 ++++++++++--------- 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 1c7ba2027..06a5c558f 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -5,6 +5,7 @@ ### :bug: Bugs fixed - Fix issue on handling empty content on boolean shapes +- Fix race condition issue on component renaming - Handle EOF errors on writting streamed response - Handle EOF errors on websocket send/ping methods - Disable parallel upload of file media on import (causes too much diff --git a/frontend/src/app/main/data/workspace/libraries.cljs b/frontend/src/app/main/data/workspace/libraries.cljs index fa8132e04..027e6514a 100644 --- a/frontend/src/app/main/data/workspace/libraries.cljs +++ b/frontend/src/app/main/data/workspace/libraries.cljs @@ -314,29 +314,32 @@ (ptk/reify ::rename-component ptk/WatchEvent (watch [it state _] - (let [[path name] (cp/parse-path-name new-name) - component (get-in state [:workspace-data :components id]) - objects (get component :objects) - ; Give the same name to the root shape - new-objects (assoc-in objects - [(:id component) :name] - name) + ;; NOTE: we need to ensure the component exists, because there + ;; are small posibilities of race conditions with component + ;; deletion. + (when-let [component (get-in state [:workspace-data :components id])] + (let [[path name] (cp/parse-path-name new-name) + objects (get component :objects) + ;; Give the same name to the root shape + new-objects (assoc-in objects + [(:id component) :name] + name) - rchanges [{:type :mod-component - :id id - :name name - :path path - :objects new-objects}] + rchanges [{:type :mod-component + :id id + :name name + :path path + :objects new-objects}] - uchanges [{:type :mod-component - :id id - :name (:name component) - :path (:path component) - :objects objects}]] + uchanges [{:type :mod-component + :id id + :name (:name component) + :path (:path component) + :objects objects}]] - (rx/of (dch/commit-changes {:redo-changes rchanges - :undo-changes uchanges - :origin it})))))) + (rx/of (dch/commit-changes {:redo-changes rchanges + :undo-changes uchanges + :origin it}))))))) (defn duplicate-component "Create a new component copied from the one with the given id."