diff --git a/frontend/src/app/main/data/workspace/common.cljs b/frontend/src/app/main/data/workspace/common.cljs index 5d6d7c00f3..b76dce9749 100644 --- a/frontend/src/app/main/data/workspace/common.cljs +++ b/frontend/src/app/main/data/workspace/common.cljs @@ -400,67 +400,74 @@ (into (d/ordered-set) empty-parents-xform all-parents) mk-del-obj-xf - (map (fn [id] - {:type :del-obj - :page-id page-id - :id id})) + (comp (filter (partial contains? objects)) + (map (fn [id] + {:type :del-obj + :page-id page-id + :id id}))) mk-add-obj-xf - (map (fn [id] - (let [item (get objects id)] - {:type :add-obj - :id (:id item) - :page-id page-id - :index (cp/position-on-parent id objects) - :frame-id (:frame-id item) - :parent-id (:parent-id item) - :obj item}))) + (comp (filter (partial contains? objects)) + (map (fn [id] + (let [item (get objects id)] + {:type :add-obj + :id (:id item) + :page-id page-id + :index (cp/position-on-parent id objects) + :frame-id (:frame-id item) + :parent-id (:parent-id item) + :obj item})))) mk-mod-touched-xf - (map (fn [id] - (let [parent (get objects id)] - {:type :mod-obj - :page-id page-id - :id (:id parent) - :operations [{:type :set-touched - :touched (:touched parent)}]}))) + (comp (filter (partial contains? objects)) + (map (fn [id] + (let [parent (get objects id)] + {:type :mod-obj + :page-id page-id + :id (:id parent) + :operations [{:type :set-touched + :touched (:touched parent)}]})))) mk-mod-int-del-xf - (map (fn [obj] - {:type :mod-obj - :page-id page-id - :id (:id obj) - :operations [{:type :set - :attr :interactions - :val (vec (remove (fn [interaction] - (contains? ids (:destination interaction))) - (:interactions obj)))}]})) + (comp (filter some?) + (map (fn [obj] + {:type :mod-obj + :page-id page-id + :id (:id obj) + :operations [{:type :set + :attr :interactions + :val (vec (remove (fn [interaction] + (contains? ids (:destination interaction))) + (:interactions obj)))}]}))) mk-mod-int-add-xf - (map (fn [obj] - {:type :mod-obj - :page-id page-id - :id (:id obj) - :operations [{:type :set - :attr :interactions - :val (:interactions obj)}]})) + (comp (filter some?) + (map (fn [obj] + {:type :mod-obj + :page-id page-id + :id (:id obj) + :operations [{:type :set + :attr :interactions + :val (:interactions obj)}]}))) mk-mod-unmask-xf - (map (fn [id] - {:type :mod-obj - :page-id page-id - :id id - :operations [{:type :set - :attr :masked-group? - :val false}]})) + (comp (filter (partial contains? objects)) + (map (fn [id] + {:type :mod-obj + :page-id page-id + :id id + :operations [{:type :set + :attr :masked-group? + :val false}]}))) mk-mod-mask-xf - (map (fn [id] - {:type :mod-obj - :page-id page-id - :id id - :operations [{:type :set - :attr :masked-group? - :val true}]})) + (comp (filter (partial contains? objects)) + (map (fn [id] + {:type :mod-obj + :page-id page-id + :id id + :operations [{:type :set + :attr :masked-group? + :val true}]}))) rchanges (-> [] diff --git a/frontend/src/app/main/data/workspace/texts.cljs b/frontend/src/app/main/data/workspace/texts.cljs index 1163a56873..841bf01819 100644 --- a/frontend/src/app/main/data/workspace/texts.cljs +++ b/frontend/src/app/main/data/workspace/texts.cljs @@ -67,8 +67,10 @@ (rx/of (dch/update-shapes [id] #(assoc % :content content)) (dwu/commit-undo-transaction))))) - (rx/of (dws/deselect-shape id) - (dwc/delete-shapes #{id}))))))) + + (when (some? id) + (rx/of (dws/deselect-shape id) + (dwc/delete-shapes #{id})))))))) (defn initialize-editor-state [{:keys [id content] :as shape} decorator] diff --git a/frontend/src/app/main/ui/workspace.cljs b/frontend/src/app/main/ui/workspace.cljs index 2086412dfb..533ce45248 100644 --- a/frontend/src/app/main/ui/workspace.cljs +++ b/frontend/src/app/main/ui/workspace.cljs @@ -6,8 +6,10 @@ (ns app.main.ui.workspace (:require + [app.util.timers :as ts] [app.main.data.messages :as dm] [app.main.data.workspace :as dw] + [app.main.data.workspace.persistence :as dwp] [app.main.refs :as refs] [app.main.store :as st] [app.main.ui.context :as ctx] @@ -122,7 +124,10 @@ (mf/deps project-id file-id) (fn [] (st/emit! (dw/initialize-file project-id file-id)) - (st/emitf (dw/finalize-file project-id file-id)))) + (fn [] + ;; Schedule to 100ms so we can do the update before the file is finalized + (st/emit! ::dwp/force-persist) + (ts/schedule 100 (st/emitf (dw/finalize-file project-id file-id)))))) (mf/use-effect (fn []