From ab0238a049cda6fe427df0fe7ea5c3238f70394c 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 | 25 +++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/common/src/app/common/files/changes_builder.cljc b/common/src/app/common/files/changes_builder.cljc index c038e33fcc..a5231fc252 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 18a07cce7d..89e331089f 100644 --- a/common/test/common_tests/files_changes_test.cljc +++ b/common/test/common_tests/files_changes_test.cljc @@ -17,6 +17,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.page :as ctp] @@ -1598,3 +1602,24 @@ :operations [{:type :set :attr :name :val "renamed"}]} {:type :set-plugin-data :object-type :shape :object-id (ids :rect-a) :page-id page-id :namespace "ns" :key "k" :value "v"}]))))) + +(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)))))) +