6
6
isShadowRoot ,
7
7
needMaskingText ,
8
8
maskInputValue ,
9
- Mirror ,
10
9
isNativeShadowDom ,
11
10
getInputType ,
12
11
toLowerCase ,
@@ -169,7 +168,7 @@ export default class MutationBuffer {
169
168
private addedSet = new Set < Node > ( ) ;
170
169
private movedSet = new Set < Node > ( ) ;
171
170
private droppedSet = new Set < Node > ( ) ;
172
- private removesSubTreeCache = new Set < Node > ( ) ;
171
+ private removesAndDescendants = new Set < Node > ( ) ;
173
172
174
173
private mutationCb : observerParam [ 'mutationCb' ] ;
175
174
private blockClass : observerParam [ 'blockClass' ] ;
@@ -367,9 +366,11 @@ export default class MutationBuffer {
367
366
}
368
367
369
368
for ( const n of this . movedSet ) {
369
+ const movedParent = dom . parentNode ( n ) ;
370
370
if (
371
- isParentRemoved ( this . removesSubTreeCache , n , this . mirror ) &&
372
- ! this . movedSet . has ( dom . parentNode ( n ) ! )
371
+ movedParent && // can't be removed if it doesn't exist
372
+ this . removesAndDescendants . has ( movedParent ) &&
373
+ ! this . movedSet . has ( movedParent )
373
374
) {
374
375
continue ;
375
376
}
@@ -379,7 +380,7 @@ export default class MutationBuffer {
379
380
for ( const n of this . addedSet ) {
380
381
if (
381
382
! isAncestorInSet ( this . droppedSet , n ) &&
382
- ! isParentRemoved ( this . removesSubTreeCache , n , this . mirror )
383
+ ! this . removesAndDescendants . has ( dom . parentNode ( n ) ! )
383
384
) {
384
385
pushAdd ( n ) ;
385
386
} else if ( isAncestorInSet ( this . movedSet , n ) ) {
@@ -515,7 +516,7 @@ export default class MutationBuffer {
515
516
this . addedSet = new Set < Node > ( ) ;
516
517
this . movedSet = new Set < Node > ( ) ;
517
518
this . droppedSet = new Set < Node > ( ) ;
518
- this . removesSubTreeCache = new Set < Node > ( ) ;
519
+ this . removesAndDescendants = new Set < Node > ( ) ;
519
520
this . movedMap = { } ;
520
521
521
522
this . mutationCb ( payload ) ;
@@ -750,7 +751,7 @@ export default class MutationBuffer {
750
751
? true
751
752
: undefined ,
752
753
} ) ;
753
- processRemoves ( n , this . removesSubTreeCache ) ;
754
+ populateWithDescendants ( n , this . removesAndDescendants ) ;
754
755
}
755
756
this . mapRemoves . push ( n ) ;
756
757
} ) ;
@@ -814,35 +815,20 @@ function deepDelete(addsSet: Set<Node>, n: Node) {
814
815
dom . childNodes ( n ) . forEach ( ( childN ) => deepDelete ( addsSet , childN ) ) ;
815
816
}
816
817
817
- function processRemoves ( n : Node , cache : Set < Node > ) {
818
+ function populateWithDescendants ( n : Node , s : Set < Node > ) {
818
819
const queue = [ n ] ;
819
820
820
821
while ( queue . length ) {
821
822
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
822
823
const next = queue . pop ( ) ! ;
823
- if ( cache . has ( next ) ) continue ;
824
- cache . add ( next ) ;
824
+ if ( s . has ( next ) ) continue ;
825
+ s . add ( next ) ;
825
826
dom . childNodes ( next ) . forEach ( ( n ) => queue . push ( n ) ) ;
826
827
}
827
828
828
829
return ;
829
830
}
830
831
831
- function isParentRemoved ( removes : Set < Node > , n : Node , mirror : Mirror ) : boolean {
832
- if ( removes . size === 0 ) return false ;
833
- return _isParentRemoved ( removes , n , mirror ) ;
834
- }
835
-
836
- function _isParentRemoved (
837
- removes : Set < Node > ,
838
- n : Node ,
839
- _mirror : Mirror ,
840
- ) : boolean {
841
- const node : ParentNode | null = dom . parentNode ( n ) ;
842
- if ( ! node ) return false ;
843
- return removes . has ( node ) ;
844
- }
845
-
846
832
function isAncestorInSet ( set : Set < Node > , n : Node ) : boolean {
847
833
if ( set . size === 0 ) return false ;
848
834
return _isAncestorInSet ( set , n ) ;
0 commit comments