You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
IndeterminateComponent,// Before we know whether it is function or class
10
-
HostRoot,// Root of a host tree. Could be nested inside another node.
11
-
HostPortal,// A subtree. Could be an entry point to a different renderer.
12
-
/**
13
-
* Host Component: a type of component that represents a native DOM element in the browser environment, such as div, span, input, h1 etc.
14
-
*/
15
-
HostComponent,// has stateNode of html elements
16
-
HostText,
17
-
Fragment,
18
-
Mode,
19
-
ContextConsumer,
20
10
ContextProvider,
21
-
ForwardRef,
22
-
Profiler,
23
-
SuspenseComponent,
24
-
MemoComponent,
25
-
SimpleMemoComponent,// A higher order component where if the component renders the same result given the same props, react skips rendering the component and uses last rendered result. Has memoizedProps/memoizedState but no stateNode
// with memoizedState we can grab the root type and construct an Abstract Syntax Tree from the hooks structure using Acorn in order to extract the hook getters and match them with their corresponding setters in an object
// ---------OBTAIN STATE & SET STATE METHODS FROM CLASS COMPONENT-----------
93
-
// Check if node is a stateful class component when user use setState.
94
-
// If user use setState to define/manage state, the state object will be stored in stateNode.state => grab the state object stored in the stateNode.state
95
-
// Example: for tic-tac-toe demo-app: Board is a stateful component that use setState to store state data.
// Base Case: if has visited the component, return
40
+
if(circularComponentTable.has(currentFiberNode)){
41
+
return;
42
+
}else{
43
+
circularComponentTable.add(currentFiberNode);
44
+
}
45
+
46
+
// ------------------OBTAIN DATA FROM THE CURRENT FIBER NODE----------------
47
+
// Destructure the current fiber node:
48
+
const{
49
+
sibling,
50
+
stateNode,
51
+
child,
52
+
// with memoizedState we can grab the root type and construct an Abstract Syntax Tree from the hooks structure using Acorn in order to extract the hook getters and match them with their corresponding setters in an object
// --------OBTAIN STATE & DISPATCH METHODS FROM FUNCTIONAL COMPONENT--------
107
-
// Check if node is a stateful class component when user use setState.
108
-
// If user use useState to define/manage state, the state object will be stored in memoizedState.queue => grab the state object stored in the memoizedState.queue
109
-
if(
110
-
!nextJSDefaultComponent.has(componentName)&&
111
-
!remixDefaultComponents.has(componentName)&&
112
-
memoizedState&&
113
-
(tag===FunctionComponent||tag===IndeterminateComponent||tag===ContextProvider)//TODO: Need to figure out why we need context provider
114
-
){
115
-
if(memoizedState.queue){
116
-
try{
117
-
// Hooks states are stored as a linked list using memoizedState.next,
118
-
// so we must traverse through the list and get the states.
119
-
// We then store them along with the corresponding memoizedState.queue,
120
-
// which includes the dispatch() function we use to change their state.
// Save component's state and dispatch() function to our record for future time-travel state changing. Add record index to snapshot so we can retrieve.
* 1. We will only interested in components that are one of these types: Function Component, Class Component, Indeterminate Component or Context Provider.
85
+
* NOTE: this list of components may change depending on future use
86
+
* 2. If user use Next JS, filter out default NextJS components
87
+
* 3. If user use Remix JS, filter out default Remix components
88
+
*/
89
+
90
+
if(
91
+
!allowedComponentTypes.has(tag)||
92
+
nextJSDefaultComponent.has(componentName)||
93
+
remixDefaultComponents.has(componentName)
94
+
){
95
+
// -------------------TRAVERSE TO NEXT FIBERNODE------------------------
96
+
// If currentFiberNode has children, recurse on children
97
+
if(child)_createComponentActionsRecord(child);
98
+
99
+
// If currentFiberNode has siblings, recurse on siblings
100
+
if(sibling){
101
+
_createComponentActionsRecord(sibling);
128
102
}
103
+
// ---------RETURN THE TREE OUTPUT & PASS TO FRONTEND FOR RENDERING-------
104
+
return;
105
+
}
106
+
107
+
// ---------OBTAIN STATE & SET STATE METHODS FROM CLASS COMPONENT-----------
108
+
// Check if node is a stateful class component when user use setState.
109
+
// If user use setState to define/manage state, the state object will be stored in stateNode.state => grab the state object stored in the stateNode.state
110
+
// Example: for tic-tac-toe demo-app: Board is a stateful component that use setState to store state data.
// --------OBTAIN STATE & DISPATCH METHODS FROM FUNCTIONAL COMPONENT--------
117
+
// Check if node is a stateful class component when user use setState.
118
+
// If user use useState to define/manage state, the state object will be stored in memoizedState.queue => grab the state object stored in the memoizedState.queue
119
+
if(
120
+
(tag===FunctionComponent||
121
+
tag===IndeterminateComponent||
122
+
//TODO: Need to figure out why we need context provider
123
+
tag===ContextProvider)&&
124
+
memoizedState
125
+
){
126
+
if(memoizedState.queue){
127
+
try{
128
+
// Hooks states are stored as a linked list using memoizedState.next,
129
+
// so we must traverse through the list and get the states.
130
+
// We then store them along with the corresponding memoizedState.queue,
131
+
// which includes the dispatch() function we use to change their state.
// Save component's state and dispatch() function to our record for future time-travel state changing. Add record index to snapshot so we can retrieve.
135
+
componentActionsRecord.saveNew(component);
136
+
});
137
+
}catch(err){
138
+
console.log('ERROR: Failed Element during JSX parsing',{
139
+
componentName,
140
+
});
141
+
}
142
+
}
143
+
}
135
144
136
-
// If currentFiberNode has siblings, recurse on siblings
Copy file name to clipboardExpand all lines: src/backend/controllers/createTree/createTree.ts
+10-40Lines changed: 10 additions & 40 deletions
Original file line number
Diff line number
Diff line change
@@ -7,31 +7,7 @@ import {
7
7
FunctionComponent,
8
8
ClassComponent,
9
9
IndeterminateComponent,// Before we know whether it is function or class
10
-
HostRoot,// Root of a host tree. Could be nested inside another node.
11
-
HostPortal,// A subtree. Could be an entry point to a different renderer.
12
-
/**
13
-
* Host Component: a type of component that represents a native DOM element in the browser environment, such as div, span, input, h1 etc.
14
-
*/
15
-
HostComponent,// has stateNode of html elements
16
-
HostText,
17
-
Fragment,
18
-
Mode,
19
-
ContextConsumer,
20
10
ContextProvider,
21
-
ForwardRef,
22
-
Profiler,
23
-
SuspenseComponent,
24
-
MemoComponent,
25
-
SimpleMemoComponent,// A higher order component where if the component renders the same result given the same props, react skips rendering the component and uses last rendered result. Has memoizedProps/memoizedState but no stateNode
26
-
LazyComponent,
27
-
IncompleteClassComponent,
28
-
DehydratedFragment,
29
-
SuspenseListComponent,
30
-
FundamentalComponent,
31
-
ScopeComponent,
32
-
Block,
33
-
OffscreenComponent,
34
-
LegacyHiddenComponent,
35
11
}from'../../types/backendTypes';
36
12
// import function that creates a tree
37
13
importTreefrom'../../models/tree';
@@ -57,7 +33,6 @@ import {
57
33
* 3. Build a new state snapshot
58
34
* Every time a state change is made in the accompanying app, the extension creates a Tree “snapshot” of the current state, and adds it to the current “cache” of snapshots in the extension
59
35
* @param currentFiberNode A Fiber object
60
-
* @param tree A Tree object, default initialized to an instance given 'root' and 'root'
61
36
* @return An instance of a Tree object
62
37
*/
63
38
// TODO: Not sure why the ritd need to be outside of the createTree function. Want to put inside, but in case this need to be keep track for front end.
@@ -80,6 +55,7 @@ export default function createTree(currentFiberNode: Fiber): Tree {
80
55
}else{
81
56
circularComponentTable.add(currentFiberNode);
82
57
}
58
+
83
59
// ------------------OBTAIN DATA FROM THE CURRENT FIBER NODE----------------
84
60
// Destructure the current fiber node:
85
61
const{
@@ -145,12 +121,12 @@ export default function createTree(currentFiberNode: Fiber): Tree {
145
121
if(sibling){
146
122
_createTree(sibling,tree);
147
123
}
148
-
// -------------RETURN THE TREE OUTPUT & PASS TO FRONTEND FOR RENDERING-------
124
+
// ---------RETURN THE TREE OUTPUT & PASS TO FRONTEND FOR RENDERING-------
149
125
returntree;
150
126
}
151
127
152
128
// --------------INITIALIZE OBJECT TO CONTAIN COMPONENT DATA---------------
153
-
letnewState: any|{hooksState?: any[]}={};
129
+
letnewState: 'stateless'|object='stateless';
154
130
letcomponentData: {
155
131
actualDuration?: number;
156
132
actualStartTime?: number;
@@ -170,7 +146,6 @@ export default function createTree(currentFiberNode: Fiber): Tree {
170
146
props: {},
171
147
context: {},
172
148
};
173
-
letisStatefulComponent=false;
174
149
175
150
// ---------------APPEND PROP DATA FROM REACT DEV TOOL----------------------
176
151
// Check to see if the parent component has any props
@@ -239,8 +214,8 @@ export default function createTree(currentFiberNode: Fiber): Tree {
239
214
// Save state information in componentData.
240
215
componentData.state=stateNode.state;
241
216
// Passess to front end
242
-
newState=stateNode.state;
243
-
isStatefulComponent=true;
217
+
// TODO: Refactor this, this is currently being used for Tree & Diff tabs
218
+
newState=componentData.state;
244
219
}
245
220
246
221
// --------OBTAIN STATE & DISPATCH METHODS FROM FUNCTIONAL COMPONENT--------
@@ -261,31 +236,26 @@ export default function createTree(currentFiberNode: Fiber): Tree {
// Save component's state and dispatch() function to our record for future time-travel state changing. Add record index to snapshot so we can retrieve.
0 commit comments