From 88dd41f0650327d9ebb847423bd12446484070aa Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Fri, 23 Oct 2026 14:59:14 +0200 Subject: [PATCH] :bug: Record user undo changes before starting derived component sync Hand applied transitions to the component watcher only after the workspace records their undo entry. Keep the handoff synchronous with the captured prior file data. This preserves transaction order when nesting triggers several component syncs. Fix F137. The minimal replay failed both undo and redo before the fix; its 4 checks now pass. Existing sync scenarios pass their behavior and undo checks; 60 golden digests need review for the accumulated Phase 4 fixes. Common benchmark ratios against Phase 1e: main 10/100/1000 0.46/0.52/0.53; levels 0.47; chain 0.51; library 0.51; many 0.49; switch 0.61. This handoff changes no common benchmark code. AI-assisted-by: GPT-6 --- frontend/src/app/main/data/changes.cljs | 9 +++++++ frontend/src/app/main/data/workspace.cljs | 26 +++++++++++-------- .../app/main/data/workspace/libraries.cljs | 2 +- .../composable_tests/generated_test.cljs | 3 +++ 4 files changed, 28 insertions(+), 12 deletions(-) diff --git a/frontend/src/app/main/data/changes.cljs b/frontend/src/app/main/data/changes.cljs index 145d3c12ad..cb7f78ca3a 100644 --- a/frontend/src/app/main/data/changes.cljs +++ b/frontend/src/app/main/data/changes.cljs @@ -41,6 +41,15 @@ (def changes-applied? (ptk/type? ::changes-applied)) +(def changes-recorded? + (ptk/type? ::changes-recorded)) + +(defn changes-recorded + "The commit has applied and its undo entry has been recorded. Derived + edits can now follow it without reversing transaction history." + [transition] + (ptk/data-event ::changes-recorded transition)) + (defn- fix-page-id "For events that modifies the page, page-id does not comes as a property so we assign it from the `id` property." diff --git a/frontend/src/app/main/data/workspace.cljs b/frontend/src/app/main/data/workspace.cljs index e36cc65caf..514e85533c 100644 --- a/frontend/src/app/main/data/workspace.cljs +++ b/frontend/src/app/main/data/workspace.cljs @@ -499,19 +499,23 @@ (rx/take-until stopper-s))) (->> stream - (rx/filter dch/commit?) + (rx/filter dch/changes-applied?) (rx/map deref) (rx/mapcat - (fn [{:keys [file-id save-undo? undo-changes redo-changes undo-group tags stack-undo? selected-before translation?]}] - (if (and save-undo? (seq undo-changes)) - (let [entry {:undo-changes (mapv #(assoc % ::dwu/file-id file-id) undo-changes) - :redo-changes (mapv #(assoc % ::dwu/file-id file-id) redo-changes) - :undo-group undo-group - :tags tags - :selected-before selected-before - :translation (boolean translation?)}] - (rx/of (dwu/append-undo entry stack-undo?))) - (rx/empty)))))) + (fn [{:keys [commit] :as transition}] + (let [{:keys [file-id save-undo? undo-changes redo-changes undo-group + tags stack-undo? selected-before translation?]} commit] + (rx/concat + (if (and save-undo? (seq undo-changes)) + (let [entry {:undo-changes (mapv #(assoc % ::dwu/file-id file-id) undo-changes) + :redo-changes (mapv #(assoc % ::dwu/file-id file-id) redo-changes) + :undo-group undo-group + :tags tags + :selected-before selected-before + :translation (boolean translation?)}] + (rx/of (dwu/append-undo entry stack-undo?))) + (rx/empty)) + (rx/of (dch/changes-recorded transition)))))))) (rx/take-until stopper-s))))))) (defn initialize-workspace diff --git a/frontend/src/app/main/data/workspace/libraries.cljs b/frontend/src/app/main/data/workspace/libraries.cljs index 7ee6fed997..b9aa924a0d 100644 --- a/frontend/src/app/main/data/workspace/libraries.cljs +++ b/frontend/src/app/main/data/workspace/libraries.cljs @@ -1553,7 +1553,7 @@ local-commits-s (->> stream - (rx/filter dch/changes-applied?) + (rx/filter dch/changes-recorded?) (rx/map deref) (rx/filter #(= :local (get-in % [:commit :source]))) ;; Keep waits pending while component changes are checked. diff --git a/frontend/test/frontend_tests/composable_tests/generated_test.cljs b/frontend/test/frontend_tests/composable_tests/generated_test.cljs index d21402a152..a64bca9ee6 100644 --- a/frontend/test/frontend_tests/composable_tests/generated_test.cljs +++ b/frontend/test/frontend_tests/composable_tests/generated_test.cljs @@ -86,3 +86,6 @@ (t/deftest ^:async nested-text-rotation-shrunk-regression (await (replay {:world [2 0 {:text true}] :ops [[:nest 0] [:detach 0] [:rotate 0]]}))) + +(t/deftest ^:async nesting-restores-default-constraints-on-undo + (await (replay {:world [2 0] :ops [[:nest 0]]})))