diff --git a/frontend/src/app/main/data/workspace/libraries.cljs b/frontend/src/app/main/data/workspace/libraries.cljs index 4a06dd72c5..bc147df275 100644 --- a/frontend/src/app/main/data/workspace/libraries.cljs +++ b/frontend/src/app/main/data/workspace/libraries.cljs @@ -1095,15 +1095,24 @@ (when (seq (:redo-changes changes)) (rx/of (dch/commit-changes changes))) (when-not (empty? updated-frames) - (rx/merge - (rx/of (ptk/data-event :layout/update {:ids (map :id updated-frames) :undo-group undo-group})) - (->> (rx/from updated-frames) - (rx/mapcat - (fn [shape] - (rx/of - (dwt/clear-thumbnail file-id (:page-id shape) (:id shape) "frame") - (when-not (= (:frame-id shape) uuid/zero) - (dwt/clear-thumbnail file-id (:page-id shape) (:frame-id shape) "frame")))))))) + (let [frames-by-page (->> updated-frames + (group-by :page-id))] + (rx/merge + ;; Emit one layout/update event for each page + (rx/from + (map (fn [[page-id frames]] + (ptk/data-event :layout/update + {:page-id page-id + :ids (map :id frames) + :undo-group undo-group})) + frames-by-page)) + (->> (rx/from updated-frames) + (rx/mapcat + (fn [shape] + (rx/of + (dwt/clear-thumbnail file-id (:page-id shape) (:id shape) "frame") + (when-not (= (:frame-id shape) uuid/zero) + (dwt/clear-thumbnail file-id (:page-id shape) (:frame-id shape) "frame"))))))))) (when (not= file-id library-id) ;; When we have just updated the library file, give some time for the diff --git a/frontend/src/app/main/data/workspace/shape_layout.cljs b/frontend/src/app/main/data/workspace/shape_layout.cljs index 9880d68293..1d1ac195d4 100644 --- a/frontend/src/app/main/data/workspace/shape_layout.cljs +++ b/frontend/src/app/main/data/workspace/shape_layout.cljs @@ -131,11 +131,12 @@ ;; they are process together. It will get a better performance. (rx/buffer-time 100) (rx/filter #(d/not-empty? %)) - (rx/map + (rx/mapcat (fn [data] - (let [page-id (->> data (keep :page-id) first) - ids (reduce #(into %1 (:ids %2)) #{} data)] - (update-layout-positions {:page-id page-id :ids ids})))) + (->> (group-by :page-id data) + (map (fn [[page-id items]] + (let [ids (reduce #(into %1 (:ids %2)) #{} items)] + (update-layout-positions {:page-id page-id :ids ids}))))))) (rx/take-until stopper)))))) (defn finalize-shape-layout