From 3f69c2ba8c6dcf6306a4d6e19afcb74184ae91e3 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Sat, 14 Nov 2026 15:20:47 +0100 Subject: [PATCH] :bug: Sync copies when a copy nested in a main is moved The component watcher drops a translation commit that moves only shapes outside mains or whole mains. It found the main of each moved shape with `get-component-shape`, which stops at the nearest copy head, so a copy placed in a main, or a shape inside one, looked like a shape outside any main: moving it with the WASM engine on, whose drags commit as translations, left the main's copies where they were. The watcher now walks up through nested copies to the main instance the shape lies in. The benchmark covers JVM code; this change is ClojureScript only, so it is not run. AI-assisted-by: claude-opus-5-5 --- .../src/app/main/data/workspace/libraries.cljs | 16 +++++++++++++--- .../data/workspace_sync_barrier_test.cljs | 10 ++++++++++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/frontend/src/app/main/data/workspace/libraries.cljs b/frontend/src/app/main/data/workspace/libraries.cljs index d4363833d1..549583852a 100644 --- a/frontend/src/app/main/data/workspace/libraries.cljs +++ b/frontend/src/app/main/data/workspace/libraries.cljs @@ -1597,6 +1597,16 @@ (component-sync-events state component-id file-id undo-group) [(dwu/commit-undo-transaction undo-id)])))))) +(defn- main-ancestor + "The main instance `shape` is or lies inside, through any copies nested in + it, or nil." + [objects shape] + (loop [shape shape] + (cond + (or (nil? shape) (cfh/root? shape)) nil + (ctk/main-instance? shape) shape + :else (recur (get objects (:parent-id shape)))))) + (defn- moves-whole-mains? "Whether the `changes` of a translation commit, applied on the file `data`, move only shapes outside mains, or whole mains: every shape they @@ -1606,9 +1616,9 @@ (let [objects (dm/get-in data [:pages-index page-id :objects]) ids (into #{} (map :id) changes)] (every? (fn [id] - (let [root (ctn/get-component-shape objects (get objects id) {:allow-main? true})] - (or (not (ctk/main-instance? root)) - (contains? ids (:id root))))) + (let [main (main-ancestor objects (get objects id))] + (or (nil? main) + (contains? ids (:id main))))) ids))) (group-by :page-id (filter #(= :mod-obj (:type %)) changes)))) diff --git a/frontend/test/frontend_tests/data/workspace_sync_barrier_test.cljs b/frontend/test/frontend_tests/data/workspace_sync_barrier_test.cljs index 789d36da50..bfa79d8f4c 100644 --- a/frontend/test/frontend_tests/data/workspace_sync_barrier_test.cljs +++ b/frontend/test/frontend_tests/data/workspace_sync_barrier_test.cljs @@ -111,6 +111,16 @@ (t/is open?) (t/is (= red (ftm/fill-of :copy-child))))))) +(t/deftest translation-of-a-copy-nested-in-a-main-syncs-the-copies + ;; a copy placed in a main is part of it: moving it is an edit of the main + (t/async done + (ftm/install! (setup/nested-component-with-copy)) + (st/emit! (ftm/fill-commit :main2-nested-head red {:translation? true})) + (-> (pwrf/wait-for-layout-update nil 2000) + (.then #(t/is (= red (ftm/fill-of :copy2-child)))) + (.catch #(t/is false (str "the wait threw: " %))) + (.finally done)))) + (t/deftest derived-commit-leaves-nothing-pending (t/async done (run-commit done {:skip-component-sync? true} dropped)))