1- import { ID , Tree } from "../../view/store/types" ;
1+ import { DevNodeType , ID , Tree } from "../../view/store/types" ;
22import { parseTable } from "./string-table" ;
33import { MsgTypes } from "./events" ;
44import { deepClone } from "../../view/components/profiler/flamegraph/modes/adjustNodesToRight" ;
@@ -19,16 +19,32 @@ export function ops2Tree(oldTree: Tree, existingRoots: ID[], ops: number[]) {
1919 const removals : ID [ ] = [ ] ;
2020 const reasons : RenderReasonMap = new Map ( ) ;
2121 let stats : ParsedStats | null = null ;
22+ const rendered : ID [ ] = [ ] ;
2223
2324 let i = ops [ 1 ] + 1 ;
2425 const strings = parseTable ( ops . slice ( 1 , i + 1 ) ) ;
2526
2627 for ( i += 1 ; i < ops . length ; i ++ ) {
2728 switch ( ops [ i ] ) {
28- case MsgTypes . ADD_ROOT :
29- roots . push ( ops [ i + 1 ] ) ;
29+ case MsgTypes . ADD_ROOT : {
30+ const id = ops [ i + 1 ] ;
31+ roots . push ( id ) ;
3032 i += 1 ;
33+
34+ pending . set ( id , {
35+ children : [ ] ,
36+ depth : - 1 ,
37+ id,
38+ hocs : null ,
39+ name : "__VIRTUAL__ROOT__" ,
40+ parent : - 1 ,
41+ type : DevNodeType . Group ,
42+ key : "" ,
43+ startTime : - 1 ,
44+ endTime : - 1 ,
45+ } ) ;
3146 break ;
47+ }
3248 case MsgTypes . ADD_VNODE : {
3349 const id = ops [ i + 1 ] ;
3450 const parentId = ops [ i + 3 ] ;
@@ -39,6 +55,8 @@ export function ops2Tree(oldTree: Tree, existingRoots: ID[], ops: number[]) {
3955 clone . children . push ( id ) ;
4056 }
4157
58+ rendered . push ( id ) ;
59+
4260 pending . set ( id , {
4361 children : [ ] ,
4462 depth : parent ? parent . depth + 1 : 0 ,
@@ -61,6 +79,8 @@ export function ops2Tree(oldTree: Tree, existingRoots: ID[], ops: number[]) {
6179 x . startTime = ops [ i + 2 ] / 1000 ;
6280 x . endTime = ops [ i + 3 ] / 1000 ;
6381
82+ rendered . push ( id ) ;
83+
6484 i += 3 ;
6585 break ;
6686 }
@@ -85,7 +105,7 @@ export function ops2Tree(oldTree: Tree, existingRoots: ID[], ops: number[]) {
85105 }
86106
87107 // Check if node was a root
88- const rootIdx = roots . indexOf ( node . id ) ;
108+ const rootIdx = roots . indexOf ( node . parent ) ;
89109 if ( rootIdx > - 1 ) {
90110 roots . splice ( rootIdx , 1 ) ;
91111 }
@@ -159,5 +179,5 @@ export function ops2Tree(oldTree: Tree, existingRoots: ID[], ops: number[]) {
159179 }
160180 }
161181
162- return { rootId, roots, tree : pending , removals, reasons, stats } ;
182+ return { rootId, roots, tree : pending , removals, reasons, stats, rendered } ;
163183}
0 commit comments