🐛 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
This commit is contained in:
Eva Marco 2026-09-30 10:40:18 +02:00 committed by Andrés Moya
parent f741571eb0
commit 6c0233d0dd
2 changed files with 26 additions and 0 deletions

View File

@ -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))))

View File

@ -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))))))