From c5f2ffab693f53fbbd5345ded9bde57de7958c30 Mon Sep 17 00:00:00 2001 From: Eva Marco Date: Thu, 7 May 2026 15:24:25 +0200 Subject: [PATCH] :bug: Fix internal error when applying not valid value to margin input (#9311) --- common/src/app/common/data.cljc | 2 +- common/test/common_tests/data_test.cljc | 7 ++++++- .../src/app/main/data/workspace/shape_layout.cljs | 13 ++++++------- .../sidebar/options/menus/layout_item.cljs | 6 ++++++ 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/common/src/app/common/data.cljc b/common/src/app/common/data.cljc index cc1247dd8e..e0ad3cab15 100644 --- a/common/src/app/common/data.cljc +++ b/common/src/app/common/data.cljc @@ -379,7 +379,7 @@ :else (assoc object key value))) object)) - changes))) + (without-nils changes)))) (defn remove-at-index "Takes a vector and returns a vector with an element in the diff --git a/common/test/common_tests/data_test.cljc b/common/test/common_tests/data_test.cljc index dbe015cf89..56b43078dc 100644 --- a/common/test/common_tests/data_test.cljc +++ b/common/test/common_tests/data_test.cljc @@ -532,7 +532,12 @@ (t/is (= {nil 0 :b 2} (d/patch-object {nil 0 :a 1 :b 2} {:a nil}))) ;; transducer arity (1-arg returns a fn) (let [f (d/patch-object {:a 99})] - (t/is (= {:a 99 :b 2} (f {:a 1 :b 2}))))) + (t/is (= {:a 99 :b 2} (f {:a 1 :b 2})))) + ;; when object is nil, nil values in changes are stripped (not preserved) + (t/is (= {} (d/patch-object nil {:a nil}))) + (t/is (= {:a 1} (d/patch-object nil {:a 1 :b nil}))) + ;; nested path: patching a key that doesn't exist creates a new map without nils + (t/is (= {:b {:y 2}} (d/patch-object {:b nil} {:b {:x nil :y 2}})))) (t/deftest without-obj-test (t/is (= [1 3] (d/without-obj [1 2 3] 2))) diff --git a/frontend/src/app/main/data/workspace/shape_layout.cljs b/frontend/src/app/main/data/workspace/shape_layout.cljs index bbff39663a..83454294d6 100644 --- a/frontend/src/app/main/data/workspace/shape_layout.cljs +++ b/frontend/src/app/main/data/workspace/shape_layout.cljs @@ -555,10 +555,9 @@ ;; change parent to fixed (and row? auto-height? (every? ctl/fill-height? all-children)) (assoc :layout-item-v-sizing :fix)))) - (defn update-layout-child - ([ids changes] (update-layout-child ids changes nil)) - ([ids changes options] + ([ids attrs] (update-layout-child ids attrs nil)) + ([ids attrs options] (ptk/reify ::update-layout-child ptk/WatchEvent (watch [_ state _] @@ -568,20 +567,20 @@ children-ids (->> ids (mapcat #(cfh/get-children-ids objects %))) parent-ids (->> ids (map #(cfh/get-parent-id objects %))) undo-id (js/Symbol) - margin-attrs (-> (get changes :layout-item-margin) + margin-attrs (-> (get attrs :layout-item-margin) keys set)] (rx/of (dwu/start-undo-transaction undo-id) - (dwsh/update-shapes ids (d/patch-object changes) + (dwsh/update-shapes ids (d/patch-object attrs) (cond-> options (seq margin-attrs) (assoc :changed-sub-attr margin-attrs))) - (dwsh/update-shapes children-ids (partial fix-child-sizing objects changes) options) + (dwsh/update-shapes children-ids (partial fix-child-sizing objects attrs) options) (dwsh/update-shapes parent-ids (fn [parent objects] (-> parent - (fix-parent-sizing objects (set ids) changes) + (fix-parent-sizing objects (set ids) attrs) (cond-> (ctl/grid-layout? parent) (ctl/assign-cells objects)))) (merge options {:with-objects? true})) diff --git a/frontend/src/app/main/ui/workspace/sidebar/options/menus/layout_item.cljs b/frontend/src/app/main/ui/workspace/sidebar/options/menus/layout_item.cljs index c8e43e7f1c..e98e294810 100644 --- a/frontend/src/app/main/ui/workspace/sidebar/options/menus/layout_item.cljs +++ b/frontend/src/app/main/ui/workspace/sidebar/options/menus/layout_item.cljs @@ -147,6 +147,7 @@ :icon i/margin-top-bottom :min 0 :attr :m1 + :default nil :input-type :vertical-margin :property "Vertical margin " :nillable true @@ -178,6 +179,7 @@ :min 0 :attr :m2 :align :right + :default nil :input-type :horizontal-margin :property "Horizontal margin" :nillable true @@ -270,6 +272,7 @@ :icon i/margin-top :class (stl/css :top-margin-wrapper) :min 0 + :default nil :attr :m1 :input-type :vertical-margin :property "Top margin" @@ -298,6 +301,7 @@ :icon i/margin-right :class (stl/css :right-margin-wrapper) :min 0 + :default nil :attr :m2 :align :right :input-type :horizontal-margin @@ -329,6 +333,7 @@ :class (stl/css :bottom-margin-wrapper) :min 0 :attr :m3 + :default nil :align :right :input-type :vertical-margin :property "Bottom margin" @@ -358,6 +363,7 @@ :icon i/margin-left :class (stl/css :left-margin-wrapper) :min 0 + :default nil :attr :m4 :property "Left margin" :input-type :horizontal-margin