From 6c0233d0dddc774e91e528c3df73b5449513e9ce Mon Sep 17 00:00:00 2001 From: Eva Marco Date: Wed, 30 Sep 2026 10:40:18 +0200 Subject: [PATCH] :bug: Skip shape validation when applying changes locally apply-changes-local replays the pending redo changes on a local copy of the data, so that later builder calls can read up-to-date values. It replayed :validate-shapes too, so the validator ran on that copy, which has no real file id and no libraries, and reported false errors such as :component-main-external. This broke Ctrl+K on a component when it duplicates the main instance and resizes the variant container. Skip :validate-shapes when applying changes locally. AI-assisted-by: claude-opus-5-5 --- .../src/app/common/files/changes_builder.cljc | 2 ++ .../test/common_tests/files_changes_test.cljc | 24 +++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/common/src/app/common/files/changes_builder.cljc b/common/src/app/common/files/changes_builder.cljc index f324a51f4e..4587c3416c 100644 --- a/common/src/app/common/files/changes_builder.cljc +++ b/common/src/app/common/files/changes_builder.cljc @@ -198,6 +198,8 @@ redo-changes (:redo-changes changes) new-changes (if (< index (count redo-changes)) (->> (subvec (:redo-changes changes) index) + ;; Validation only makes sense on the real file data + (remove #(= :validate-shapes (:type %))) (map #(-> % (assoc :page-id uuid/zero) (dissoc :component-id)))) diff --git a/common/test/common_tests/files_changes_test.cljc b/common/test/common_tests/files_changes_test.cljc index 935ff092fb..bbb3007a36 100644 --- a/common/test/common_tests/files_changes_test.cljc +++ b/common/test/common_tests/files_changes_test.cljc @@ -14,6 +14,10 @@ [app.common.schema :as sm] [app.common.schema.generators :as sg] [app.common.schema.test :as smt] + [app.common.test-helpers.components :as thc] + [app.common.test-helpers.compositions :as tho] + [app.common.test-helpers.files :as thf] + [app.common.test-helpers.shapes :as ths] [app.common.time :as ct] [app.common.types.file :as ctf] [app.common.types.shape :as cts] @@ -1165,3 +1169,23 @@ (nil? (get-in result2 [:pages-index page-id :default-grids]))))) {:num 1000}))) + +(t/deftest apply-changes-local-skips-validate-shapes + ;; The builder applies pending changes to a local copy of the data, which + ;; has neither the real file id nor the libraries, so a :validate-shapes + ;; change must not run there. On CLJS it would report false errors. + (let [file (-> (thf/sample-file :file1) + (tho/add-simple-component :c01 :m01 :r01)) + page (thf/current-page file) + main (ths/get-shape file :m01) + comp-id (:id (thc/get-component file :c01)) + + changes (-> (pcb/empty-changes nil) + (pcb/with-page-id (:id page)) + (pcb/with-library-data (:data file)) + (pcb/with-objects (:objects page)) + (pcb/validate-shapes (:id page) [(:id main)] "test") + (pcb/update-component comp-id (fn [c] (assoc c :name "New name")) + {:apply-changes-local-library? true}))] + + (t/is (= 2 (count (:redo-changes changes))))))