mirror of
https://github.com/penpot/penpot.git
synced 2025-07-21 16:37:19 +02:00
🐛 Fix possible race condition on component rename and deletion
This commit is contained in:
parent
ce61b783fb
commit
82796822d1
2 changed files with 24 additions and 20 deletions
|
@ -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."
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue