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 @@ -367,9 +367,11 @@ export default class MutationBuffer {
367367 }
368368
369369 for ( const n of this . movedSet ) {
370+ const parentNode = dom . parentNode ( n ) ;
370371 if (
371372 isParentRemoved ( this . removesSubTreeCache , n , this . mirror ) &&
372- ! this . movedSet . has ( dom . parentNode ( n ) ! )
373+ ! this . movedSet . has ( parentNode ! ) &&
374+ ( ! this . addedSet . has ( parentNode ! ) )
373375 ) {
374376 continue ;
375377 }
Original file line number Diff line number Diff line change @@ -83,6 +83,7 @@ import {
8383 getPositionsAndIndex ,
8484 uniqueTextMutations ,
8585 StyleSheetMirror ,
86+ type ResolveTree
8687} from '../utils' ;
8788import getInjectStyleRules from './styles/inject-style' ;
8889import './styles/style.css' ;
@@ -1707,6 +1708,18 @@ export class Replayer {
17071708 appendNode ( mutation ) ;
17081709 } ) ;
17091710
1711+ const nodeIdsToBeAdded = ( resolveTrees : Array < ResolveTree > ) => {
1712+ const ids = new Set ( ) ;
1713+ for ( const tree of resolveTrees ) {
1714+ ids . add ( tree . value . node . id ) ;
1715+ if ( tree . children && tree . children . length > 1 ) {
1716+ const res = nodeIdsToBeAdded ( tree . children ) ;
1717+ res . forEach ( id => ids . add ( id ) ) ;
1718+ }
1719+ }
1720+ return ids ;
1721+ } ;
1722+
17101723 const startTime = Date . now ( ) ;
17111724 while ( queue . length ) {
17121725 // transform queue to resolve tree
@@ -1721,7 +1734,8 @@ export class Replayer {
17211734 }
17221735 for ( const tree of resolveTrees ) {
17231736 const parent = mirror . getNode ( tree . value . parentId ) ;
1724- if ( ! parent ) {
1737+ const ids = nodeIdsToBeAdded ( resolveTrees ) ;
1738+ if ( ! parent && ! ids . has ( tree . value . parentId ) ) {
17251739 this . debug (
17261740 'Drop resolve tree since there is no parent for the root node.' ,
17271741 tree ,
Original file line number Diff line number Diff line change @@ -333,7 +333,7 @@ export function polyfill(win = window) {
333333 }
334334}
335335
336- type ResolveTree = {
336+ export type ResolveTree = {
337337 value : addedNodeMutation ;
338338 children : ResolveTree [ ] ;
339339 parent : ResolveTree | null ;
You can’t perform that action at this time.
0 commit comments