@@ -59,19 +59,19 @@ export default (snap, mode) => {
59
59
function sendSnapshot ( ) {
60
60
// Don't send messages while jumping or while paused
61
61
circularComponentTable . clear ( ) ;
62
- console . log ( 'sending snapshot' ) ;
62
+ // console.log('sending snapshot');
63
63
if ( mode . jumping || mode . paused ) return ;
64
- console . log ( 'PAYLOAD: before cleaning' , snap . tree ) ;
64
+ // console.log('PAYLOAD: before cleaning', snap.tree);
65
65
66
66
if ( ! snap . tree ) {
67
- console . log ( 'snapshot empty, sending root' ) ;
67
+ // console.log('snapshot empty, sending root');
68
68
snap . tree = new Tree ( 'root' ) ;
69
69
}
70
70
const payload = snap . tree . cleanTreeCopy ( ) ; // snap.tree.getCopy();
71
71
72
- console . log ( 'PAYLOAD: after cleaning' , payload ) ;
73
- //try {
74
- //await window.postMessage({
72
+ // console.log('PAYLOAD: after cleaning', payload);
73
+ // try {
74
+ // await window.postMessage({
75
75
window . postMessage ( {
76
76
action : 'recordSnap' ,
77
77
payload,
@@ -105,7 +105,7 @@ export default (snap, mode) => {
105
105
//
106
106
function createTree ( currentFiber , tree = new Tree ( 'root' ) , fromSibling = false ) {
107
107
// Base case: child or sibling pointed to null
108
- console . log ( 'linkFiber.js: creating tree' ) ;
108
+ // console.log('linkFiber.js: creating tree');
109
109
if ( ! currentFiber ) return null ;
110
110
if ( ! tree ) return tree ;
111
111
@@ -132,7 +132,7 @@ export default (snap, mode) => {
132
132
if ( stateNode && stateNode . state && ( tag === 0 || tag === 1 || tag === 2 ) ) {
133
133
// Save component's state and setState() function to our record for future
134
134
// time-travel state changing. Add record index to snapshot so we can retrieve.
135
- console . log ( 'linkFiber.js: found stateNode component' ) ;
135
+ // console.log('linkFiber.js: found stateNode component');
136
136
componentData . index = componentActionsRecord . saveNew ( stateNode . state , stateNode ) ;
137
137
newState = stateNode . state ;
138
138
componentFound = true ;
@@ -142,7 +142,7 @@ export default (snap, mode) => {
142
142
let hooksIndex ;
143
143
if ( memoizedState && ( tag === 0 || tag === 1 || tag === 10 ) ) {
144
144
if ( memoizedState . queue ) {
145
- console . log ( 'linkFiber.js: found hooks component' ) ;
145
+ // console.log('linkFiber.js: found hooks component');
146
146
// Hooks states are stored as a linked list using memoizedState.next,
147
147
// so we must traverse through the list and get the states.
148
148
// We then store them along with the corresponding memoizedState.queue,
@@ -163,7 +163,7 @@ export default (snap, mode) => {
163
163
}
164
164
165
165
// This grabs stateless components
166
- if ( ! componentFound && ( tag === 0 || tag === 1 ) ) {
166
+ if ( ! componentFound && ( tag === 0 || tag === 1 || tag === 2 ) ) {
167
167
newState = 'stateless' ;
168
168
}
169
169
@@ -176,20 +176,19 @@ export default (snap, mode) => {
176
176
treeBaseDuration,
177
177
} ;
178
178
179
- console . log ( 'linkFiber.js: adding new state to tree:' , newState ) ;
180
- if ( componentFound ) {
181
- console . log ( 'componentFound, calling tree.addChild' ) ;
179
+ let newNode = null ;
180
+ if ( componentFound || newState === 'stateless' ) {
182
181
if ( fromSibling ) {
183
- tree . addSibling ( newState , elementType . name ? elementType . name : elementType , componentData ) ;
182
+ newNode = tree . addSibling ( newState ,
183
+ elementType . name ? elementType . name : elementType ,
184
+ componentData ) ;
184
185
} else {
185
- tree . addChild ( newState , elementType . name ? elementType . name : elementType , componentData ) ;
186
- }
187
- } else if ( newState === 'stateless' ) {
188
- if ( fromSibling ) {
189
- tree . addSibling ( newState , elementType . name ? elementType . name : elementType , componentData ) ;
190
- } else {
191
- tree . addChild ( newState , elementType . name ? elementType . name : elementType , componentData ) ;
186
+ newNode = tree . addChild ( newState ,
187
+ elementType . name ? elementType . name : elementType ,
188
+ componentData ) ;
192
189
}
190
+ } else {
191
+ newNode = tree ;
193
192
}
194
193
195
194
// Recurse on children
@@ -198,32 +197,28 @@ export default (snap, mode) => {
198
197
// If this node had state we appended to the children array,
199
198
// so attach children to the newly appended child.
200
199
// Otherwise, attach children to this same node.
201
- console . log ( 'going into child' ) ;
200
+ // console.log('going into child');
202
201
// circularComponentTable.set(child, true);
203
- if ( tree . children . length > 0 ) {
204
- createTree ( child , tree . children [ tree . children . length - 1 ] ) ;
205
- } else {
206
- createTree ( child , tree ) ;
207
- }
202
+ createTree ( child , newNode ) ;
208
203
}
209
204
// Recurse on siblings
210
205
if ( sibling ) { // && !circularComponentTable.has(sibling)) {
211
- console . log ( 'going into sibling' ) ;
206
+ // console.log('going into sibling');
212
207
// circularComponentTable.set(sibling, true);
213
- createTree ( sibling , tree , true ) ;
208
+ createTree ( sibling , newNode , true ) ;
214
209
}
215
210
216
- console . log ( 'linkFiber.js: processed children and sibling, returning tree' ) ;
211
+ // console.log('linkFiber.js: processed children and sibling, returning tree');
217
212
return tree ;
218
213
}
219
214
220
215
function updateSnapShotTree ( ) {
221
- console . log ( 'linkFiber.js, updateSnapshotTree(), checking if we have fiberRoot to update ' ) ;
216
+ // console.log('linkFiber.js, updateSnapshotTree(), checking if fiberRoot updated ');
222
217
if ( fiberRoot ) {
223
- console . log ( 'linkFiber.js, updateSnapshotTree(), fiberRoot found , updating snapshot' , snap . tree ) ;
218
+ // console.log('linkFiber.js, updateSnapshotTree(), updating snapshot', snap.tree);
224
219
const { current } = fiberRoot ;
225
220
snap . tree = createTree ( current ) ;
226
- console . log ( 'linkFiber.js, updateSnapshotTree(), completed snapshot' , snap . tree ) ;
221
+ // console.log('linkFiber.js, updateSnapshotTree(), completed snapshot', snap.tree);
227
222
}
228
223
}
229
224
@@ -241,15 +236,13 @@ export default (snap, mode) => {
241
236
242
237
const devTools = window . __REACT_DEVTOOLS_GLOBAL_HOOK__ ;
243
238
const reactInstance = devTools ? devTools . renderers . get ( 1 ) : null ;
244
- console . log ( 'devTools:' , devTools ) ;
239
+ // console.log('devTools:', devTools);
245
240
246
241
if ( reactInstance && reactInstance . version ) {
247
242
devTools . onCommitFiberRoot = ( function ( original ) {
248
243
return function ( ...args ) {
249
244
fiberRoot = args [ 1 ] ;
250
- console . log ( 'this is fiberRoot' , fiberRoot ) ;
251
245
updateSnapShotTree ( ) ;
252
- console . log ( 'snap.tree is: ' , snap . tree ) ;
253
246
sendSnapshot ( ) ;
254
247
return original ( ...args ) ;
255
248
} ;
@@ -260,7 +253,7 @@ export default (snap, mode) => {
260
253
// This message is sent from contentScript.js in chrome extension bundles
261
254
window . addEventListener ( 'message' , ( { data : { action } } ) => {
262
255
if ( action === 'contentScriptStarted' ) {
263
- console . log ( 'content script started received at linkFiber.js' )
256
+ // console.log('content script started received at linkFiber.js')
264
257
sendSnapshot ( ) ;
265
258
}
266
259
} ) ;
0 commit comments