-
-
Add Images
+
diff --git a/addons/html_builder/static/src/website_builder/plugins/website_edit_service.js b/addons/html_builder/static/src/website_builder/plugins/website_edit_service.js
index e13c8ffd252a7..55986aff4ca07 100644
--- a/addons/html_builder/static/src/website_builder/plugins/website_edit_service.js
+++ b/addons/html_builder/static/src/website_builder/plugins/website_edit_service.js
@@ -1,6 +1,7 @@
import { registry } from "@web/core/registry";
import { PublicRoot } from "@web/legacy/js/public/public_root";
import { Colibri } from "@web/public/colibri";
+import { Interaction } from "@web/public/interaction";
import { patch } from "@web/core/utils/patch";
export function buildEditableInteractions(builders) {
@@ -125,6 +126,18 @@ registry.category("services").add("website_edit", {
applyTOut(...args) {
historyCallbacks.ignoreDOMMutations(() => super.applyTOut(...args));
},
+ }),
+ patch(Interaction.prototype, {
+ insert(...args) {
+ const el = args[0];
+ super.insert(...args);
+ // Avoid deletion accidents.
+ // E.g. if an interaction inserts a node into a parent
+ // node, and an option uses replaceChildren on the
+ // parent node, you do not want the inserted node to be
+ // reinserted upon undo of the option's action.
+ el.dataset.skipHistoryHack = "true";
+ },
})
);
};
diff --git a/addons/html_editor/static/src/core/history_plugin.js b/addons/html_editor/static/src/core/history_plugin.js
index 3c2e369cf56ad..b4974d0c7ac3e 100644
--- a/addons/html_editor/static/src/core/history_plugin.js
+++ b/addons/html_editor/static/src/core/history_plugin.js
@@ -534,6 +534,21 @@ export class HistoryPlugin extends Plugin {
}
case "childList": {
record.addedNodes.forEach((added) => {
+ // When nodes are expected to not be observed by the
+ // history, e.g. because they belong to a distinct
+ // lifecycle such as interactions, some operations such
+ // as replaceChildren might impact such a node together
+ // with observed ones.
+ // Marking the node with skipHistoryHack makes sure that
+ // it does not accidentally get observed during those
+ // operations.
+ // TODO Find a better solution.
+ if (
+ added?.dataset?.skipHistoryHack ||
+ added?.closest?.("data-skip-history-hack")
+ ) {
+ return;
+ }
const mutation = {
type: "add",
};
@@ -556,6 +571,13 @@ export class HistoryPlugin extends Plugin {
this.currentStep.mutations.push(mutation);
});
record.removedNodes.forEach((removed) => {
+ // TODO Find a better solution.
+ if (
+ removed?.dataset?.skipHistoryHack ||
+ removed?.closest?.("data-skip-history-hack")
+ ) {
+ return;
+ }
this.currentStep.mutations.push({
type: "remove",
id: this.nodeToIdMap.get(removed),