File tree Expand file tree Collapse file tree 4 files changed +24
-3
lines changed
Expand file tree Collapse file tree 4 files changed +24
-3
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ " rrweb " : patch
3+ ---
4+
5+ updating record and playback side to account for mutations where a node is missing a parent but it gets added in a different iteration of the mutation
Original file line number Diff line number Diff line change @@ -383,9 +383,11 @@ export default class MutationBuffer {
383383 }
384384
385385 for ( const n of this . movedSet ) {
386+ const parentNode = dom . parentNode ( n ) ;
386387 if (
387388 isParentRemoved ( this . removesSubTreeCache , n , this . mirror ) &&
388- ! this . movedSet . has ( dom . parentNode ( n ) ! )
389+ ! this . movedSet . has ( parentNode ! ) &&
390+ ( ! this . addedSet . has ( parentNode ! ) )
389391 ) {
390392 continue ;
391393 }
Original file line number Diff line number Diff line change @@ -82,6 +82,7 @@ import {
8282 getPositionsAndIndex ,
8383 uniqueTextMutations ,
8484 StyleSheetMirror ,
85+ type ResolveTree
8586} from '../utils' ;
8687import getInjectStyleRules from './styles/inject-style' ;
8788import './styles/style.css' ;
@@ -1703,6 +1704,18 @@ export class Replayer {
17031704 appendNode ( mutation ) ;
17041705 } ) ;
17051706
1707+ const nodeIdsToBeAdded = ( resolveTrees : Array < ResolveTree > ) => {
1708+ const ids = new Set ( ) ;
1709+ for ( const tree of resolveTrees ) {
1710+ ids . add ( tree . value . node . id ) ;
1711+ if ( tree . children && tree . children . length > 0 ) {
1712+ const res = nodeIdsToBeAdded ( tree . children ) ;
1713+ res . forEach ( id => ids . add ( id ) ) ;
1714+ }
1715+ }
1716+ return ids ;
1717+ } ;
1718+
17061719 const startTime = Date . now ( ) ;
17071720 while ( queue . length ) {
17081721 // transform queue to resolve tree
@@ -1717,7 +1730,8 @@ export class Replayer {
17171730 }
17181731 for ( const tree of resolveTrees ) {
17191732 const parent = mirror . getNode ( tree . value . parentId ) ;
1720- if ( ! parent ) {
1733+ const ids = nodeIdsToBeAdded ( resolveTrees ) ;
1734+ if ( ! parent && ! ids . has ( tree . value . parentId ) ) {
17211735 this . debug (
17221736 'Drop resolve tree since there is no parent for the root node.' ,
17231737 tree ,
Original file line number Diff line number Diff line change @@ -354,7 +354,7 @@ export function polyfill(win = window) {
354354 }
355355}
356356
357- type ResolveTree = {
357+ export type ResolveTree = {
358358 value : addedNodeMutation ;
359359 children : ResolveTree [ ] ;
360360 parent : ResolveTree | null ;
You can’t perform that action at this time.
0 commit comments