🐛 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:
Andrey Antukh
2025-11-05 12:25:57 +01:00
committed by Alejandro Alonso
parent b8c0c5c310
commit bd65f3932e

View File

@@ -818,15 +818,15 @@
(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)
(let [index (or (some-> (d/index-of (:shapes parent) after-shape) inc) index)
frame-id (if (cfh/frame-shape? parent)
(:id parent) (:id parent)
(:frame-id parent))] (:frame-id parent))]
(if (and valid? (seq shapes))
(as-> objects $ (as-> objects $
;; Add the new shapes to the parent object. ;; Add the new shapes to the parent object.
(d/update-when $ parent-id #(add-to-parent % index shapes)) (d/update-when $ parent-id #(add-to-parent % index shapes))
@@ -841,7 +841,8 @@
;; Ensure that all shapes of the new parent has a ;; Ensure that all shapes of the new parent has a
;; correct link to the topside frame. ;; correct link to the topside frame.
(reduce (partial assign-frame-id frame-id) $ shapes)) (reduce (partial update-frame-id frame-id) $ shapes)))
objects)))] objects)))]
(if page-id (if page-id