From 552e23eabfa272fd96033c600e3c217658139124 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Sun, 25 Oct 2026 09:18:29 +0100 Subject: [PATCH] :bug: Sync restored components after variant name changes Restoring a variant whose container has gone converts its variant value into its main name. Report the restored component id to the normal sync cascade: its main is absent from the old page objects, so ordinary shape change detection misses it. Copies receive the new name in the restore's undo group, while authored name overrides remain intact. F183: the portable regression fails one assertion before the fix and passes all six after it. Original and shrunk programs pass. The focused suite passes 138 tests / 2576 assertions with unchanged goldens. Live WASM checks direct, nested and indirect copies, custom names and undo/redo. Frontend passes 1536 tests / 9179 assertions; plugin 68 cases, lint and formatting pass. The isolated Stage 3 check passes 53 tests / 373 assertions. Common JVM/JS, backend and exporter suites pass. Phase 1e benchmark ratios: mains 10/100/1000 .50/.56/.57, levels .51, chain .51, library .52, many shapes .50, variant switch .62. AI-assisted-by: GPT-6 --- common/src/app/common/files/changes.cljc | 4 ++++ common/src/app/common/logic/instances.cljc | 4 +++- .../common_tests/logic/comp_sync_test.cljc | 19 +++++++++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/common/src/app/common/files/changes.cljc b/common/src/app/common/files/changes.cljc index b6b418f30e..dc34b5b3b3 100644 --- a/common/src/app/common/files/changes.cljc +++ b/common/src/app/common/files/changes.cljc @@ -1296,6 +1296,10 @@ (into #{} xform shape-and-parents)) (when component-id #{component-id}))) +(defmethod components-changed :restore-component + [_ {:keys [id]}] + #{id}) + (defmethod components-changed :default [_ _] nil) diff --git a/common/src/app/common/logic/instances.cljc b/common/src/app/common/logic/instances.cljc index 03fe1f5784..12e62e141f 100644 --- a/common/src/app/common/logic/instances.cljc +++ b/common/src/app/common/logic/instances.cljc @@ -279,7 +279,9 @@ changes (-> changes (pcb/with-page page) (pcb/with-objects (:objects page)) - (pcb/with-library-data library-data)) + (pcb/with-library-data library-data) + ;; undone last, it gives the component back its shapes as stored + (pcb/update-component component-id identity {:objects? true})) changes (cond-> (pcb/add-object changes first-shape {:ignore-touched true}) (some? old-id) (pcb/amend-last-change #(assoc % :old-id old-id))) ; on copy/paste old id is used later to reorder the paster layers changes (reduce #(pcb/add-object %1 %2 {:ignore-touched true}) diff --git a/common/test/common_tests/logic/comp_sync_test.cljc b/common/test/common_tests/logic/comp_sync_test.cljc index c76ccc633f..f96596349e 100644 --- a/common/test/common_tests/logic/comp_sync_test.cljc +++ b/common/test/common_tests/logic/comp_sync_test.cljc @@ -1380,6 +1380,25 @@ (ch/components-changed (:data file) (change {:type :assign :value {:opacity 0.5}})))) (t/is (nil? (ch/components-changed (:data file) (change {:type :assign :value {:interactions []}})))))) +(t/deftest restoring-a-variant-without-its-container-syncs-the-new-main-name + (let [initial (tm/apply-to (n/make-variant-container "restore" [["b" "#ffffff"]]) + (setup/empty-situation)) + initial (tm/with-file initial + (thc/instantiate-component (tm/file initial) :sync-restore-v0-component :copy)) + deletion (n/delete-component :sync-restore-v0-root) + deleted (-> initial (r/step deletion) r/settle) + restored (-> deleted (r/step (n/restore-component deletion)) r/settle) + main (tm/resolve-shape restored :sync-restore-v0-root) + copy (tm/resolve-shape restored :copy)] + (t/is (nil? (ths/get-shape (tm/file deleted) :sync-restore-vcontainer))) + (t/is (= "Board / b" (:name main))) + (t/is (= (:name main) (:name copy))) + (t/is (empty? (:touched copy))) + (t/is (= (thn/normalize-file (tm/file deleted)) + (thn/normalize-file (tm/file (r/step restored (n/undo)))))) + (t/is (= (thn/normalize-file (tm/file restored)) + (thn/normalize-file (tm/file (-> restored (r/step (n/undo)) (r/step (n/redo))))))))) + (t/deftest test-sync-of-a-flip ;; the main flips its child as the editor does: a transform that scales ;; it by -1, which toggles :flip-x