mirror of
https://github.com/penpot/penpot.git
synced 2025-12-11 22:14:05 +01:00
🐛 Fix a race condition on move-object
That happens when an in-flight move-object change tries to move object to an already deleted parent
This commit is contained in:
committed by
Alejandro Alonso
parent
b8c0c5c310
commit
bd65f3932e
@@ -818,30 +818,31 @@
|
|||||||
(as-> $$ (reduce (partial assign-frame-id frame-id) $$ (:shapes obj))))))
|
(as-> $$ (reduce (partial assign-frame-id frame-id) $$ (:shapes obj))))))
|
||||||
|
|
||||||
(move-objects [objects]
|
(move-objects [objects]
|
||||||
(let [valid? (every? (partial is-valid-move? objects) shapes)
|
(let [parent (get objects parent-id)]
|
||||||
parent (get objects parent-id)
|
;; Do not proceed with the move if parent does not
|
||||||
after-shape-index (d/index-of (:shapes parent) after-shape)
|
;; exists; this can happen on a race condition when an
|
||||||
index (if (nil? after-shape-index) index (inc after-shape-index))
|
;; inflight move operations lands when parent is deleted
|
||||||
frame-id (if (= :frame (:type parent))
|
(if (and (seq shapes) (every? (partial is-valid-move? objects) shapes) parent)
|
||||||
(:id parent)
|
(let [index (or (some-> (d/index-of (:shapes parent) after-shape) inc) index)
|
||||||
(:frame-id parent))]
|
frame-id (if (cfh/frame-shape? parent)
|
||||||
|
(:id parent)
|
||||||
|
(:frame-id parent))]
|
||||||
|
(as-> objects $
|
||||||
|
;; Add the new shapes to the parent object.
|
||||||
|
(d/update-when $ parent-id #(add-to-parent % index shapes))
|
||||||
|
|
||||||
(if (and valid? (seq shapes))
|
;; Update each individual shape link to the new parent
|
||||||
(as-> objects $
|
(reduce update-parent-id $ shapes)
|
||||||
;; Add the new shapes to the parent object.
|
|
||||||
(d/update-when $ parent-id #(add-to-parent % index shapes))
|
|
||||||
|
|
||||||
;; Update each individual shape link to the new parent
|
;; Analyze the old parents and clear the old links
|
||||||
(reduce update-parent-id $ shapes)
|
;; only if the new parent is different form old
|
||||||
|
;; parent.
|
||||||
|
(reduce (partial remove-from-old-parent objects) $ shapes)
|
||||||
|
|
||||||
;; Analyze the old parents and clear the old links
|
;; Ensure that all shapes of the new parent has a
|
||||||
;; only if the new parent is different form old
|
;; correct link to the topside frame.
|
||||||
;; parent.
|
(reduce (partial update-frame-id frame-id) $ shapes)))
|
||||||
(reduce (partial remove-from-old-parent objects) $ shapes)
|
|
||||||
|
|
||||||
;; Ensure that all shapes of the new parent has a
|
|
||||||
;; correct link to the topside frame.
|
|
||||||
(reduce (partial assign-frame-id frame-id) $ shapes))
|
|
||||||
objects)))]
|
objects)))]
|
||||||
|
|
||||||
(if page-id
|
(if page-id
|
||||||
|
|||||||
Reference in New Issue
Block a user