From 94ccc013d7a9b874cbb472947c1c04885a3345a0 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Tue, 13 Apr 2021 13:10:51 +0200 Subject: [PATCH] :bug: 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. --- frontend/src/app/main/ui/measurements.cljs | 5 +++-- frontend/src/app/main/ui/workspace/viewport.cljs | 8 ++++++-- frontend/src/app/main/ui/workspace/viewport/outline.cljs | 9 +++++---- frontend/src/app/util/webapi.cljs | 4 +--- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/frontend/src/app/main/ui/measurements.cljs b/frontend/src/app/main/ui/measurements.cljs index b5b9521f9..baa197178 100644 --- a/frontend/src/app/main/ui/measurements.cljs +++ b/frontend/src/app/main/ui/measurements.cljs @@ -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 diff --git a/frontend/src/app/main/ui/workspace/viewport.cljs b/frontend/src/app/main/ui/workspace/viewport.cljs index ca4bdb610..309a976e3 100644 --- a/frontend/src/app/main/ui/workspace/viewport.cljs +++ b/frontend/src/app/main/ui/workspace/viewport.cljs @@ -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}]) diff --git a/frontend/src/app/main/ui/workspace/viewport/outline.cljs b/frontend/src/app/main/ui/workspace/viewport/outline.cljs index b84ef8322..84a7b4571 100644 --- a/frontend/src/app/main/ui/workspace/viewport/outline.cljs +++ b/frontend/src/app/main/ui/workspace/viewport/outline.cljs @@ -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 diff --git a/frontend/src/app/util/webapi.cljs b/frontend/src/app/util/webapi.cljs index f3ce1da2f..57bf1c9bf 100644 --- a/frontend/src/app/util/webapi.cljs +++ b/frontend/src/app/util/webapi.cljs @@ -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]