@@ -60,7 +60,7 @@ console.log = (original => {
60
60
} ) ( console . log ) ;
61
61
62
62
63
- const circularComponentTable = new Map ( ) ;
63
+ const circularComponentTable = new Set ( ) ;
64
64
65
65
// module.exports = (snap, mode) => {
66
66
export default ( snap , mode ) => {
@@ -114,6 +114,8 @@ export default (snap, mode) => {
114
114
115
115
// Carlos: This runs after EVERY Fiber commit. It creates a new snapshot,
116
116
//
117
+
118
+ let ctRunning = 0 ;
117
119
function createTree ( currentFiber , tree = new Tree ( 'root' , 'root' ) , fromSibling = false ) {
118
120
// Base case: child or sibling pointed to null
119
121
console . log ( 'createTree: creating tree' ) ;
@@ -140,7 +142,7 @@ export default (snap, mode) => {
140
142
let componentFound = false ;
141
143
142
144
// Check if node is a stateful setState component
143
- if ( stateNode && stateNode . state && ( tag === 0 || tag === 1 ) ) { // { || tag === 2)) {
145
+ if ( stateNode && stateNode . state && ( tag === 0 || tag === 1 || tag === 2 ) ) { // { || tag === 2)) {
144
146
// Save component's state and setState() function to our record for future
145
147
// time-travel state changing. Add record index to snapshot so we can retrieve.
146
148
console . log ( 'createTree() found setState component' ) ;
@@ -151,7 +153,7 @@ export default (snap, mode) => {
151
153
152
154
// Check if node is a hooks useState function
153
155
let hooksIndex ;
154
- if ( memoizedState && ( tag === 0 || tag === 1 || tag === 10 ) ) {
156
+ if ( memoizedState && ( tag === 0 || tag === 1 || tag === 2 || tag === 10 ) ) {
155
157
if ( memoizedState . queue ) {
156
158
console . log ( 'createTree() found hooks component' ) ;
157
159
// Hooks states are stored as a linked list using memoizedState.next,
@@ -174,9 +176,10 @@ export default (snap, mode) => {
174
176
}
175
177
176
178
// This grabs stateless components
177
- if ( ! componentFound && ( tag === 0 || tag === 1 ) ) { // || tag === 2)) {
179
+ /*
180
+ if (!componentFound && (tag === 0 || tag === 1 || tag === 2)) {
178
181
newState = 'stateless';
179
- }
182
+ }*/
180
183
181
184
// Adds performance metrics to the component data
182
185
componentData = {
@@ -207,38 +210,49 @@ export default (snap, mode) => {
207
210
208
211
// Recurse on children
209
212
210
- if ( child ) { // && !circularComponentTable.has(child)) {
213
+ if ( child && ! circularComponentTable . has ( child ) ) {
211
214
// If this node had state we appended to the children array,
212
215
// so attach children to the newly appended child.
213
216
// Otherwise, attach children to this same node.
214
217
console . log ( 'going into child' ) ;
215
- // circularComponentTable.set (child, true );
218
+ circularComponentTable . add ( child ) ;
216
219
createTree ( child , newNode ) ;
217
220
}
218
221
// Recurse on siblings
219
- if ( sibling ) { // && !circularComponentTable.has(sibling)) {
222
+ if ( sibling && ! circularComponentTable . has ( sibling ) ) {
220
223
console . log ( 'going into sibling' ) ;
221
- // circularComponentTable.set (sibling, true );
224
+ circularComponentTable . add ( sibling ) ;
222
225
createTree ( sibling , newNode , true ) ;
223
226
}
224
227
228
+ if ( circularComponentTable . has ( child ) ) {
229
+ console . log ( 'found circular child, exiting tree loop' ) ;
230
+ }
231
+
232
+ if ( circularComponentTable . has ( sibling ) ) {
233
+ console . log ( 'found circular sibling, exiting tree loop' ) ;
234
+ }
235
+
225
236
// // console.log('linkFiber.js: processed children and sibling, returning tree');
226
237
return tree ;
227
238
}
228
239
240
+ let updateSnapshotTreeCount = 0 ;
229
241
function updateSnapShotTree ( ) {
230
242
// console.log('updateSnapshotTree(), checking if fiberRoot updated');
243
+
244
+ updateSnapshotTreeCount ++ ;
245
+ if ( updateSnapshotTreeCount > 1 ) alwaysLog ( 'MULTIPLE SNAPSHOT TREE UPDATES:' , updateSnapshotTreeCount ) ;
231
246
if ( fiberRoot ) {
232
247
console . log ( 'updateSnapshotTree(), updating snapshot' , snap . tree ) ;
233
248
const { current } = fiberRoot ;
234
249
snap . tree = createTree ( current ) ;
235
250
console . log ( 'updateSnapshotTree(), completed snapshot' , snap . tree ) ;
236
251
}
252
+ updateSnapshotTreeCount -- ;
237
253
}
238
254
239
- return async ( ) => {
240
-
241
-
255
+ return async ( ) => {
242
256
/* const container = document.getElementById('root');
243
257
if (container._internalRoot) {
244
258
fiberRoot = container._internalRoot;
@@ -254,7 +268,8 @@ export default (snap, mode) => {
254
268
const devTools = window . __REACT_DEVTOOLS_GLOBAL_HOOK__ ;
255
269
const reactInstance = devTools ? devTools . renderers . get ( 1 ) : null ;
256
270
fiberRoot = devTools . getFiberRoots ( 1 ) . values ( ) . next ( ) . value ;
257
-
271
+
272
+ alwaysLog ( 'fiberRoot:' , fiberRoot ) ;
258
273
if ( reactInstance && reactInstance . version ) {
259
274
devTools . onCommitFiberRoot = ( function ( original ) {
260
275
return function ( ...args ) {
0 commit comments