Skip to content

Commit 10b7445

Browse files
bso-odooged-odoo
authored andcommitted
interactions vs history
1 parent 7f9a9cb commit 10b7445

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

addons/html_builder/static/src/website_builder/plugins/website_edit_service.js

+13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { registry } from "@web/core/registry";
22
import { PublicRoot } from "@web/legacy/js/public/public_root";
33
import { Colibri } from "@web/public/colibri";
4+
import { Interaction } from "@web/public/interaction";
45
import { patch } from "@web/core/utils/patch";
56

67
export function buildEditableInteractions(builders) {
@@ -125,6 +126,18 @@ registry.category("services").add("website_edit", {
125126
applyTOut(...args) {
126127
historyCallbacks.ignoreDOMMutations(() => super.applyTOut(...args));
127128
},
129+
}),
130+
patch(Interaction.prototype, {
131+
insert(...args) {
132+
const el = args[0];
133+
super.insert(...args);
134+
// Avoid deletion accidents.
135+
// E.g. if an interaction inserts a node into a parent
136+
// node, and an option uses replaceChildren on the
137+
// parent node, you do not want the inserted node to be
138+
// reinserted upon undo of the option's action.
139+
el.dataset.skipHistoryHack = "true";
140+
},
128141
})
129142
);
130143
};

addons/html_editor/static/src/core/history_plugin.js

+22
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,21 @@ export class HistoryPlugin extends Plugin {
534534
}
535535
case "childList": {
536536
record.addedNodes.forEach((added) => {
537+
// When nodes are expected to not be observed by the
538+
// history, e.g. because they belong to a distinct
539+
// lifecycle such as interactions, some operations such
540+
// as replaceChildren might impact such a node together
541+
// with observed ones.
542+
// Marking the node with skipHistoryHack makes sure that
543+
// it does not accidentally get observed during those
544+
// operations.
545+
// TODO Find a better solution.
546+
if (
547+
added?.dataset?.skipHistoryHack ||
548+
added?.closest?.("data-skip-history-hack")
549+
) {
550+
return;
551+
}
537552
const mutation = {
538553
type: "add",
539554
};
@@ -556,6 +571,13 @@ export class HistoryPlugin extends Plugin {
556571
this.currentStep.mutations.push(mutation);
557572
});
558573
record.removedNodes.forEach((removed) => {
574+
// TODO Find a better solution.
575+
if (
576+
removed?.dataset?.skipHistoryHack ||
577+
removed?.closest?.("data-skip-history-hack")
578+
) {
579+
return;
580+
}
559581
this.currentStep.mutations.push({
560582
type: "remove",
561583
id: this.nodeToIdMap.get(removed),

0 commit comments

Comments
 (0)