🐛 Fix unexpected console errors on removing shape.

Caused because in some instances selected shapes set
will contain an id that is already removed from object.
This is a tipical race condition.
This commit is contained in:
Andrey Antukh 2021-04-13 13:10:51 +02:00
parent 239ec12529
commit 94ccc013d7
4 changed files with 15 additions and 11 deletions

View file

@ -233,7 +233,8 @@
:stroke-width (/ select-guide-width zoom)
:stroke-dasharray (/ select-guide-dasharray zoom)}}])])
(mf/defc measurement [{:keys [bounds frame selected-shapes hover-shape zoom]}]
(mf/defc measurement
[{:keys [bounds frame selected-shapes hover-shape zoom]}]
(let [selected-ids (into #{} (map :id) selected-shapes)
selected-selrect (gsh/selection-rect selected-shapes)
hover-selrect (:selrect hover-shape)
@ -244,7 +245,7 @@
[:g.measurement-feedback {:pointer-events "none"}
[:& selection-guides {:selrect selected-selrect :bounds bounds :zoom zoom}]
[:& size-display {:selrect selected-selrect :zoom zoom}]
(if (or (not hover-shape) (not hover-selected-shape?))
(when frame
[:g.hover-shapes

View file

@ -88,7 +88,11 @@
zoom (d/check-num zoom 1)
drawing-tool (:tool drawing)
drawing-obj (:object drawing)
selected-shapes (->> selected (mapv #(get objects %)))
selected-shapes (into []
(comp (map #(get objects %))
(filter some?))
selected)
selected-frames (into #{} (map :frame-id) selected-shapes)
;; Only when we have all the selected shapes in one frame
@ -292,7 +296,7 @@
{:page-id page-id}])
[:& widgets/viewport-actions]
(when show-prototypes?
[:& interactions/interactions
{:selected selected}])

View file

@ -68,9 +68,9 @@
::mf/wrap [#(mf/memo' % (mf/check-props ["shapes" "zoom"]))]}
[props]
(let [shapes (obj/get props "shapes")
zoom (obj/get props "zoom")
color (if (or (> (count shapes) 1) (nil? (:shape-ref (first shapes))))
"#31EFB8" "#00E0FF")]
zoom (obj/get props "zoom")
color (if (or (> (count shapes) 1) (nil? (:shape-ref (first shapes))))
"#31EFB8" "#00E0FF")]
(for [shape shapes]
[:& outline {:key (str "outline-" (:id shape))
:shape (gsh/transform-shape shape)
@ -97,7 +97,8 @@
shapes (->> outlines-ids
(filter #(not= edition %))
(map #(get objects %))
(filterv show-outline?))]
(filterv show-outline?)
(filter some?))]
[:g.outlines {:display (when (some? transform) "none")}
[:& shape-outlines-render {:shapes shapes

View file

@ -90,9 +90,7 @@
(let [target (.-target ^js event)]
(when (and (not (.-isContentEditable target)) ;; ignore when pasting into
(not= (.-tagName target) "INPUT")) ;; an editable control
(-> ^js event
(.getBrowserEvent)
(.-clipboardData)))))
(.. ^js event getBrowserEvent -clipboardData))))
(defn extract-text
[clipboard-data]