1
- import { ID , Tree } from "../../view/store/types" ;
1
+ import { DevNodeType , ID , Tree } from "../../view/store/types" ;
2
2
import { parseTable } from "./string-table" ;
3
3
import { MsgTypes } from "./events" ;
4
4
import { deepClone } from "../../view/components/profiler/flamegraph/modes/adjustNodesToRight" ;
@@ -19,16 +19,32 @@ export function ops2Tree(oldTree: Tree, existingRoots: ID[], ops: number[]) {
19
19
const removals : ID [ ] = [ ] ;
20
20
const reasons : RenderReasonMap = new Map ( ) ;
21
21
let stats : ParsedStats | null = null ;
22
+ const rendered : ID [ ] = [ ] ;
22
23
23
24
let i = ops [ 1 ] + 1 ;
24
25
const strings = parseTable ( ops . slice ( 1 , i + 1 ) ) ;
25
26
26
27
for ( i += 1 ; i < ops . length ; i ++ ) {
27
28
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 ) ;
30
32
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
+ } ) ;
31
46
break ;
47
+ }
32
48
case MsgTypes . ADD_VNODE : {
33
49
const id = ops [ i + 1 ] ;
34
50
const parentId = ops [ i + 3 ] ;
@@ -39,6 +55,8 @@ export function ops2Tree(oldTree: Tree, existingRoots: ID[], ops: number[]) {
39
55
clone . children . push ( id ) ;
40
56
}
41
57
58
+ rendered . push ( id ) ;
59
+
42
60
pending . set ( id , {
43
61
children : [ ] ,
44
62
depth : parent ? parent . depth + 1 : 0 ,
@@ -61,6 +79,8 @@ export function ops2Tree(oldTree: Tree, existingRoots: ID[], ops: number[]) {
61
79
x . startTime = ops [ i + 2 ] / 1000 ;
62
80
x . endTime = ops [ i + 3 ] / 1000 ;
63
81
82
+ rendered . push ( id ) ;
83
+
64
84
i += 3 ;
65
85
break ;
66
86
}
@@ -85,7 +105,7 @@ export function ops2Tree(oldTree: Tree, existingRoots: ID[], ops: number[]) {
85
105
}
86
106
87
107
// Check if node was a root
88
- const rootIdx = roots . indexOf ( node . id ) ;
108
+ const rootIdx = roots . indexOf ( node . parent ) ;
89
109
if ( rootIdx > - 1 ) {
90
110
roots . splice ( rootIdx , 1 ) ;
91
111
}
@@ -159,5 +179,5 @@ export function ops2Tree(oldTree: Tree, existingRoots: ID[], ops: number[]) {
159
179
}
160
180
}
161
181
162
- return { rootId, roots, tree : pending , removals, reasons, stats } ;
182
+ return { rootId, roots, tree : pending , removals, reasons, stats, rendered } ;
163
183
}
0 commit comments