@@ -176,7 +176,6 @@ export default class MutationBuffer {
176
176
private attributes : attributeCursor [ ] = [ ] ;
177
177
private attributeMap = new WeakMap < Node , attributeCursor > ( ) ;
178
178
private removes : removedNodeMutation [ ] = [ ] ;
179
- private removesMap = new Map < number , number > ( ) ;
180
179
private mapRemoves : Node [ ] = [ ] ;
181
180
182
181
private movedMap : Record < string , true > = { } ;
@@ -201,6 +200,7 @@ export default class MutationBuffer {
201
200
private addedSet = new Set < Node > ( ) ;
202
201
private movedSet = new Set < Node > ( ) ;
203
202
private droppedSet = new Set < Node > ( ) ;
203
+ private removesSubTreeCache = new Set < Node > ( ) ;
204
204
205
205
private mutationCb : observerParam [ 'mutationCb' ] ;
206
206
private blockClass : observerParam [ 'blockClass' ] ;
@@ -399,7 +399,7 @@ export default class MutationBuffer {
399
399
400
400
for ( const n of this . movedSet ) {
401
401
if (
402
- isParentRemoved ( this . removesMap , n , this . mirror ) &&
402
+ isParentRemoved ( this . removesSubTreeCache , n , this . mirror ) &&
403
403
! this . movedSet . has ( dom . parentNode ( n ) ! )
404
404
) {
405
405
continue ;
@@ -410,7 +410,7 @@ export default class MutationBuffer {
410
410
for ( const n of this . addedSet ) {
411
411
if (
412
412
! isAncestorInSet ( this . droppedSet , n ) &&
413
- ! isParentRemoved ( this . removesMap , n , this . mirror )
413
+ ! isParentRemoved ( this . removesSubTreeCache , n , this . mirror )
414
414
) {
415
415
pushAdd ( n ) ;
416
416
} else if ( isAncestorInSet ( this . movedSet , n ) ) {
@@ -547,10 +547,10 @@ export default class MutationBuffer {
547
547
this . attributes = [ ] ;
548
548
this . attributeMap = new WeakMap < Node , attributeCursor > ( ) ;
549
549
this . removes = [ ] ;
550
- this . removesMap = new Map < number , number > ( ) ;
551
550
this . addedSet = new Set < Node > ( ) ;
552
551
this . movedSet = new Set < Node > ( ) ;
553
552
this . droppedSet = new Set < Node > ( ) ;
553
+ this . removesSubTreeCache = new Set < Node > ( ) ;
554
554
this . movedMap = { } ;
555
555
556
556
this . mutationCb ( payload ) ;
@@ -785,7 +785,7 @@ export default class MutationBuffer {
785
785
? true
786
786
: undefined ,
787
787
} ) ;
788
- this . removesMap . set ( nodeId , this . removes . length - 1 ) ;
788
+ processRemoves ( n , this . removesSubTreeCache ) ;
789
789
}
790
790
this . mapRemoves . push ( n ) ;
791
791
} ) ;
@@ -849,29 +849,33 @@ function deepDelete(addsSet: Set<Node>, n: Node) {
849
849
dom . childNodes ( n ) . forEach ( ( childN ) => deepDelete ( addsSet , childN ) ) ;
850
850
}
851
851
852
- function isParentRemoved (
853
- removesMap : Map < number , number > ,
854
- n : Node ,
855
- mirror : Mirror ,
856
- ) : boolean {
857
- if ( removesMap . size === 0 ) return false ;
858
- return _isParentRemoved ( removesMap , n , mirror ) ;
852
+ function processRemoves ( n : Node , cache : Set < Node > ) {
853
+ const queue = [ n ] ;
854
+
855
+ while ( queue . length ) {
856
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
857
+ const next = queue . pop ( ) ! ;
858
+ if ( cache . has ( next ) ) continue ;
859
+ cache . add ( next ) ;
860
+ dom . childNodes ( next ) . forEach ( ( n ) => queue . push ( n ) ) ;
861
+ }
862
+
863
+ return ;
864
+ }
865
+
866
+ function isParentRemoved ( removes : Set < Node > , n : Node , mirror : Mirror ) : boolean {
867
+ if ( removes . size === 0 ) return false ;
868
+ return _isParentRemoved ( removes , n , mirror ) ;
859
869
}
860
870
861
871
function _isParentRemoved (
862
- removesMap : Map < number , number > ,
872
+ removes : Set < Node > ,
863
873
n : Node ,
864
- mirror : Mirror ,
874
+ _mirror : Mirror ,
865
875
) : boolean {
866
- let node : ParentNode | null = n . parentNode ;
867
- while ( node ) {
868
- const parentId = mirror . getId ( node ) ;
869
- if ( removesMap . has ( parentId ) ) {
870
- return true ;
871
- }
872
- node = node . parentNode ;
873
- }
874
- return false ;
876
+ const node : ParentNode | null = dom . parentNode ( n ) ;
877
+ if ( ! node ) return false ;
878
+ return removes . has ( node ) ;
875
879
}
876
880
877
881
function isAncestorInSet ( set : Set < Node > , n : Node ) : boolean {
0 commit comments