@@ -89,7 +89,6 @@ type ReactimeData = {
89
89
function traverseHooks ( memoizedState : any ) : HookStates {
90
90
const hooksStates : HookStates = [ ] ;
91
91
while ( memoizedState ) {
92
- // the !== undefined conditional is necessary here for correctly displaying react hooks because TypeScript recognizes 0 and "" as falsey value - DO NOT REMOVE
93
92
if ( memoizedState . queue ) {
94
93
hooksStates . push ( {
95
94
component : memoizedState . queue ,
@@ -293,6 +292,13 @@ export function createTree(
293
292
// if (!tree) return tree; //TO BE DELETE: WE HAVE A DEFAULT PARAMETER TREE, THIS WILL NEVER BE TRUE
294
293
// These have the newest state. We update state and then
295
294
// called updateSnapshotTree()
295
+
296
+ // Base Case: if has visited, return
297
+ if ( circularComponentTable . has ( currentFiberNode ) ) {
298
+ return ;
299
+ } else {
300
+ circularComponentTable . add ( currentFiberNode ) ;
301
+ }
296
302
const {
297
303
sibling,
298
304
stateNode,
@@ -359,7 +365,7 @@ export function createTree(
359
365
props : { } ;
360
366
context : { } ;
361
367
state ?: { } ;
362
- hooksState ?: any [ ] ;
368
+ hooksState ?: { } ;
363
369
hooksIndex ?: number [ ] ;
364
370
index ?: number ;
365
371
} = {
@@ -381,7 +387,16 @@ export function createTree(
381
387
tag === ContextProvider ) &&
382
388
memoizedProps
383
389
) {
384
- Object . assign ( componentData . props , convertDataToString ( memoizedProps ) ) ;
390
+ switch ( elementType . name ) {
391
+ case 'Router' :
392
+ componentData . props = { pathname : memoizedProps ?. location ?. pathname } ;
393
+ break ;
394
+ case 'RenderedRoute' :
395
+ componentData . props = { pathname : memoizedProps ?. match ?. pathname } ;
396
+ break ;
397
+ default :
398
+ Object . assign ( componentData . props , convertDataToString ( memoizedProps ) ) ;
399
+ }
385
400
}
386
401
387
402
// ------------APPEND STATE & CONTEXT DATA FROM REACT DEV TOOL----------------
@@ -441,8 +456,6 @@ export function createTree(
441
456
}
442
457
443
458
// ---------OBTAIN STATE & DISPATCH METHODS FROM FUNCTIONAL COMPONENT---------
444
- // REGULAR REACT HOOKS
445
- let hooksIndex ;
446
459
// Check if node is a hooks useState function
447
460
if (
448
461
memoizedState &&
@@ -460,15 +473,15 @@ export function createTree(
460
473
const hooksNames = getHooksNames ( elementType . toString ( ) ) ;
461
474
// Intialize state & index:
462
475
newState . hooksState = [ ] ;
463
- componentData . hooksState = [ ] ;
476
+ componentData . hooksState = { } ;
464
477
componentData . hooksIndex = [ ] ;
465
- hooksStates . forEach ( ( state , i ) => {
478
+ hooksStates . forEach ( ( { state, component } , i ) => {
466
479
// 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.
467
- componentData . hooksIndex . push ( componentActionsRecord . saveNew ( state . component ) ) ;
480
+ componentData . hooksIndex . push ( componentActionsRecord . saveNew ( component ) ) ;
468
481
// Save state information in componentData.
469
- newState . hooksState . push ( { [ hooksNames [ i ] . hookName ] : state . state } ) ;
482
+ newState . hooksState . push ( { [ hooksNames [ i ] . varName ] : state } ) ;
470
483
// Passess to front end
471
- componentData . hooksState . push ( { [ hooksNames [ i ] . hookName ] : state . state } ) ;
484
+ componentData . hooksState [ hooksNames [ i ] . varName ] = state ;
472
485
} ) ;
473
486
isStatefulComponent = true ;
474
487
}
@@ -492,7 +505,6 @@ export function createTree(
492
505
*/
493
506
let rtid : string | null = null ;
494
507
// We want to add this fiber node to the snapshot
495
- // if (componentFound || (newState === 'stateless' && !newState.hooksState)) {
496
508
if ( isStatefulComponent || newState === 'stateless' ) {
497
509
// Grab JSX Component & replace the 'fromLinkFiber' class value
498
510
if ( currentFiberNode . child ?. stateNode ?. setAttribute ) {
@@ -512,41 +524,30 @@ export function createTree(
512
524
currentFiberNode . child . stateNode . classList . add ( rtid ) ;
513
525
}
514
526
rtidCounter += 1 ; // I THINK THIS SHOULD BE UP IN THE IF STATEMENT. Still unsure the use of rtid
527
+
528
+ // Obtain component name:
529
+ const componentName =
530
+ elementType ?. _context ?. displayName || //For ContextProvider
531
+ elementType ?. _result ?. name || //For lazy Component
532
+ elementType ?. render ?. name ||
533
+ elementType ?. name ||
534
+ 'nameless' ;
515
535
// checking if tree fromSibling is true
516
536
if ( fromSibling ) {
517
- newNode = tree . addSibling (
518
- newState ,
519
- elementType ? elementType . name : 'nameless' ,
520
- componentData ,
521
- rtid ,
522
- ) ;
537
+ newNode = tree . addSibling ( newState , componentName , componentData , rtid ) ;
523
538
} else {
524
- newNode = tree . addChild (
525
- newState ,
526
- elementType ? elementType . name : 'nameless' ,
527
- componentData ,
528
- rtid ,
529
- ) ;
539
+ newNode = tree . addChild ( newState , componentName , componentData , rtid ) ;
530
540
}
531
541
} else {
532
542
newNode = tree ;
533
543
}
534
544
535
545
// ----------------------TRAVERSE TO NEXT FIBERNODE---------------------------
536
- // Recurse on children
537
- if ( child && ! circularComponentTable . has ( child ) ) {
538
- // If this node had state we appended to the children array,
539
- // so attach children to the newly appended child.
540
- // Otherwise, attach children to this same node.
541
- circularComponentTable . add ( child ) ;
542
- createTree ( child , circularComponentTable , newNode ) ;
543
- }
546
+ // If currentFiberNode has children, recurse on children
547
+ if ( child ) createTree ( child , circularComponentTable , newNode ) ;
544
548
545
- // Recurse on siblings
546
- if ( sibling && ! circularComponentTable . has ( sibling ) ) {
547
- circularComponentTable . add ( sibling ) ;
548
- createTree ( sibling , circularComponentTable , newNode , true ) ;
549
- }
549
+ // If currentFiberNode has siblings, recurse on siblings
550
+ if ( sibling ) createTree ( sibling , circularComponentTable , newNode , true ) ;
550
551
551
552
// -------------RETURN THE TREE OUTPUT & PASS TO FRONTEND FOR RENDERING-------
552
553
return tree ;
0 commit comments