@@ -49,18 +49,6 @@ const componentActionsRecord = require('./masterState');
49
49
50
50
module . exports = ( snap , mode ) => {
51
51
let fiberRoot = null ;
52
- let astHooks ;
53
- let concurrent = false ; // flag to check if we are in concurrent mode
54
- const reactWorkTags = [
55
- 'FunctionComponent' ,
56
- 'ClassComponent' ,
57
- 'IndeterminateComponent' ,
58
- 'HostRoot' , // Root of a host tree. Could be nested inside another node.
59
- 'HostPortal' , // A subtree. Could be an entry point to a different renderer.
60
- 'HostComponent' ,
61
- 'HostText' ,
62
- ] ;
63
-
64
52
65
53
async function sendSnapshot ( ) {
66
54
// Don't send messages while jumping or while paused
@@ -81,14 +69,14 @@ module.exports = (snap, mode) => {
81
69
// Carlos: Injects instrumentation to update our state tree every time
82
70
// a hooks component changes state
83
71
function traverseHooks ( memoizedState ) {
84
- const hooksComponents = [ ] ;
72
+ const hooksStates = [ ] ;
85
73
while ( memoizedState && memoizedState . queue ) {
86
74
// Carlos: these two are legacy comments, we should look into them later
87
75
// prevents useEffect from crashing on load
88
76
// if (memoizedState.next.queue === null) { // prevents double pushing snapshot updates
89
77
if ( memoizedState . memoizedState ) {
90
78
console . log ( 'memoizedState in traverseHooks is:' , memoizedState ) ;
91
- hooksComponents . push ( {
79
+ hooksStates . push ( {
92
80
component : memoizedState . queue ,
93
81
state : memoizedState . memoizedState ,
94
82
} ) ;
@@ -97,7 +85,7 @@ module.exports = (snap, mode) => {
97
85
memoizedState = memoizedState . next !== memoizedState
98
86
? memoizedState . next : null ;
99
87
}
100
- return hooksComponents ;
88
+ return hooksStates ;
101
89
}
102
90
103
91
// Carlos: This runs after EVERY Fiber commit. It creates a new snapshot,
@@ -107,7 +95,6 @@ module.exports = (snap, mode) => {
107
95
if ( ! currentFiber ) return null ;
108
96
if ( ! tree ) return tree ;
109
97
110
-
111
98
// These have the newest state. We update state and then
112
99
// called updateSnapshotTree()
113
100
const {
@@ -126,39 +113,39 @@ module.exports = (snap, mode) => {
126
113
let newState = null ;
127
114
let componentData = { } ;
128
115
let componentFound = false ;
129
- // Check if node is a stateful component
116
+
117
+ // Check if node is a stateful setState component
130
118
if ( stateNode && stateNode . state && ( tag === 0 || tag === 1 ) ) {
131
119
console . log ( 'in create tree if' )
132
120
console . log ( 'this is currentFiber from createTree' , currentFiber )
133
121
// Save component's state and setState() function to our record for future
134
122
// time-travel state changing. Add record index to snapshot so we can retrieve.
135
123
componentData . index = componentActionsRecord . saveNew ( stateNode . state , stateNode ) ;
136
- newState = stateNode . state ;
124
+ newState . state = stateNode . state ;
137
125
componentFound = true ;
138
- // tree.appendToChild(stateNode.state, elementType.name, index); // Add component to tree
139
- } else if ( tag === 0 || tag === 1 ) {
140
- // grab stateless components here
141
- newState = 'stateless' ;
142
- // tree.appendChild({}, elementType.name) // Add component to tree
143
126
}
144
127
145
- // Check if node is a hooks function
128
+ // Check if node is a hooks useState function
146
129
let hooksIndex ;
147
130
if ( memoizedState && ( tag === 0 || tag === 1 || tag === 10 ) ) {
148
131
console . log ( 'in create tree if' )
149
132
console . log ( 'this is currentFiber from createTree' , currentFiber )
150
133
if ( memoizedState . queue ) {
151
- const hooksComponents = traverseHooks ( memoizedState ) ;
152
- hooksComponents . forEach ( c => {
153
- hooksIndex = componentActionsRecord . saveNew ( c . state , c . component ) ;
154
- if ( newState . hooksState ) {
155
- newState . hooksState . push ( [ c . state , hooksIndex ] ) ;
134
+ // Hooks states are stored as a linked list using memoizedState.next,
135
+ // so we must traverse through the list and get the states.
136
+ // We then store them along with the corresponding memoizedState.queue,
137
+ // which includes the dispatch() function we use to change their state.
138
+ const hooksStates = traverseHooks ( memoizedState ) ;
139
+ hooksStates . forEach ( state => {
140
+ hooksIndex = componentActionsRecord . saveNew ( state . state , state . component ) ;
141
+ if ( newState && newState . hooksState ) {
142
+ newState . hooksState . push ( [ state . state , hooksIndex ] ) ;
143
+ } else if ( newState ) {
144
+ newState . hooksState = [ [ state . state , hooksIndex ] ] ;
156
145
} else {
157
- newState . hooksState = [ [ c . state , hooksIndex ] ] ;
146
+ newState = { hooksState : [ [ state . state , hooksIndex ] ] } ;
158
147
}
159
148
componentFound = true ;
160
- // newState = { ...newState, hooksState: c.state };
161
- // tree.appendSibling(c.state, elementType.name ? elementType.name : 'nameless', index);
162
149
} ) ;
163
150
}
164
151
} else {
@@ -175,6 +162,12 @@ module.exports = (snap, mode) => {
175
162
}
176
163
}
177
164
165
+ // This grabs stateless components
166
+ if ( ! componentFound && ( tag === 0 || tag === 1 ) ) {
167
+ newState = 'stateless' ;
168
+ }
169
+
170
+ // Adds performance metrics to the component data
178
171
componentData = {
179
172
...componentData ,
180
173
actualDuration,
@@ -191,6 +184,9 @@ module.exports = (snap, mode) => {
191
184
192
185
// Recurse on children
193
186
if ( child ) {
187
+ // If this node had state we appended to the children array,
188
+ // so attach children to the newly appended child.
189
+ // Otherwise, attach children to this same node.
194
190
if ( tree . children . length > 0 ) {
195
191
createTree ( child , tree . children [ tree . children . length - 1 ] ) ;
196
192
} else {
@@ -237,6 +233,7 @@ module.exports = (snap, mode) => {
237
233
238
234
// ! BUG: skips 1st hook click
239
235
function updateSnapShotTree ( ) {
236
+ < << << << HEAD
240
237
/* let current;
241
238
// If concurrent mode, grab current.child
242
239
if (concurrent) {
@@ -260,21 +257,17 @@ module.exports = (snap, mode) => {
260
257
// Point fiberRoot to FiberRootNode
261
258
if ( container . _internalRoot ) {
262
259
fiberRoot = container . _internalRoot ;
263
- concurrent = true ;
264
260
} else {
265
261
const {
266
262
_reactRootContainer : { _internalRoot } ,
267
263
_reactRootContainer,
268
264
} = container ;
269
265
// Only assign internal root if it actually exists
270
266
fiberRoot = _internalRoot || _reactRootContainer ;
271
- // console.log('_reactRootContainer is:', _reactRootContainer);
272
- // console.log('linkFiber.js, fiberRoot:', fiberRoot);
273
267
}
274
268
const devTools = window . __REACT_DEVTOOLS_GLOBAL_HOOK__ ;
275
269
console . log ( 'this is devTools' , devTools )
276
270
const reactInstance = devTools ? devTools . renderers . get ( 1 ) : null ;
277
- const overrideHookState = reactInstance ? reactInstance . overrideHookState : null ;
278
271
279
272
if ( reactInstance && reactInstance . version ) {
280
273
devTools . onCommitFiberRoot = ( function ( original ) {
0 commit comments