File tree 2 files changed +35
-0
lines changed
html_builder/static/src/website_builder/plugins
html_editor/static/src/core
2 files changed +35
-0
lines changed Original file line number Diff line number Diff line change 1
1
import { registry } from "@web/core/registry" ;
2
2
import { PublicRoot } from "@web/legacy/js/public/public_root" ;
3
3
import { Colibri } from "@web/public/colibri" ;
4
+ import { Interaction } from "@web/public/interaction" ;
4
5
import { patch } from "@web/core/utils/patch" ;
5
6
6
7
export function buildEditableInteractions ( builders ) {
@@ -125,6 +126,18 @@ registry.category("services").add("website_edit", {
125
126
applyTOut ( ...args ) {
126
127
historyCallbacks . ignoreDOMMutations ( ( ) => super . applyTOut ( ...args ) ) ;
127
128
} ,
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
+ } ,
128
141
} )
129
142
) ;
130
143
} ;
Original file line number Diff line number Diff line change @@ -534,6 +534,21 @@ export class HistoryPlugin extends Plugin {
534
534
}
535
535
case "childList" : {
536
536
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
+ }
537
552
const mutation = {
538
553
type : "add" ,
539
554
} ;
@@ -556,6 +571,13 @@ export class HistoryPlugin extends Plugin {
556
571
this . currentStep . mutations . push ( mutation ) ;
557
572
} ) ;
558
573
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
+ }
559
581
this . currentStep . mutations . push ( {
560
582
type : "remove" ,
561
583
id : this . nodeToIdMap . get ( removed ) ,
You can’t perform that action at this time.
0 commit comments