@@ -24,7 +24,6 @@ export default function timeJumpInitiation(mode: Status) {
24
24
* @param targetSnapshot - The target snapshot to re-render. The payload from index.ts is assigned to targetSnapshot
25
25
*/
26
26
return async function timeJump ( targetSnapshot : Tree ) : Promise < void > {
27
- console . log ( 'Time jump initiated with targetSnapshot:' , targetSnapshot ) ; // logging to see if the re-rendering bug lives here
28
27
mode . jumping = true ;
29
28
// Reset mode.navigating
30
29
delete mode . navigating ;
@@ -50,21 +49,25 @@ async function updateReactFiberTree(
50
49
circularComponentTable : Set < any > = new Set ( ) ,
51
50
) : Promise < void > {
52
51
if ( ! targetSnapshot ) return ;
53
- // Base Case: if has visited, return
54
- if ( circularComponentTable . has ( targetSnapshot ) ) {
55
- return ;
56
- } else {
57
- circularComponentTable . add ( targetSnapshot ) ;
58
- }
59
- // ------------------------STATELESS/ROOT COMPONENT-------------------------
52
+ if ( circularComponentTable . has ( targetSnapshot ) ) return ;
53
+
54
+ circularComponentTable . add ( targetSnapshot ) ;
55
+
60
56
if ( targetSnapshot . state === 'stateless' || targetSnapshot . state === 'root' ) {
61
57
targetSnapshot . children . forEach ( ( child ) => updateReactFiberTree ( child , circularComponentTable ) ) ;
62
58
return ;
63
59
}
64
60
65
- const { index, state, hooksIndex, hooksState, reducerState } = targetSnapshot . componentData ;
61
+ const { index, state, hooksIndex, hooksState, reducerStates } = targetSnapshot . componentData ;
62
+
63
+ console . log ( 'Processing snapshot in timeJump:' , {
64
+ componentName : targetSnapshot . name ,
65
+ hasHooksIndex : ! ! hooksIndex ,
66
+ hooksState,
67
+ reducerStates,
68
+ } ) ;
66
69
67
- // ------------------------STATEFUL CLASS COMPONENT-------------------------
70
+ // Handle class components
68
71
if ( index !== null ) {
69
72
const classComponent = componentActionsRecord . getComponentByIndex ( index ) ;
70
73
if ( classComponent !== undefined ) {
@@ -74,27 +77,55 @@ async function updateReactFiberTree(
74
77
return ;
75
78
}
76
79
77
- // ----------------------STATEFUL FUNCTIONAL COMPONENT----------------------
80
+ // Handle hooks
78
81
if ( hooksIndex !== null ) {
79
82
const functionalComponent = componentActionsRecord . getComponentByIndexHooks ( hooksIndex ) ;
80
83
81
- // Handle reducer state if present
82
- if ( reducerState ) {
83
- try {
84
- // For reducer components, update using the first dispatch function
85
- await functionalComponent [ 0 ] ?. dispatch ( reducerState ) ;
86
- } catch ( err ) {
87
- console . error ( 'Error updating reducer state:' , err ) ;
88
- }
89
- } else {
90
- // Handle normal useState components
91
- for ( let i in functionalComponent ) {
84
+ console . log ( 'Retrieved functional component:' , {
85
+ hasComponent : ! ! functionalComponent ,
86
+ hooksIndexLength : hooksIndex . length ,
87
+ componentLength : functionalComponent ?. length ,
88
+ } ) ;
89
+
90
+ // Handle regular useState hooks
91
+ if ( hooksState ) {
92
+ const stateEntries = Object . entries ( hooksState ) ;
93
+
94
+ for ( let i = 0 ; i < stateEntries . length ; i ++ ) {
95
+ const [ key , value ] = stateEntries [ i ] ;
92
96
if ( functionalComponent [ i ] ?. dispatch ) {
93
- await functionalComponent [ i ] . dispatch ( Object . values ( hooksState ) [ i ] ) ;
97
+ await functionalComponent [ i ] . dispatch ( value ) ;
98
+ } else {
99
+ console . warn ( `No dispatch found for hook ${ i } :` , {
100
+ key,
101
+ value,
102
+ hasDispatch : ! ! functionalComponent [ i ] ?. dispatch ,
103
+ } ) ;
94
104
}
95
105
}
96
106
}
97
- targetSnapshot . children . forEach ( ( child ) => updateReactFiberTree ( child ) ) ;
107
+
108
+ // Handle reducer hooks
109
+ if ( reducerStates && reducerStates . length > 0 ) {
110
+ console . log ( 'Processing reducer states:' , reducerStates ) ;
111
+
112
+ for ( const reducerState of reducerStates ) {
113
+ const { state, reducerIndex } = reducerState ;
114
+ const reducer = functionalComponent [ reducerIndex ] ;
115
+
116
+ if ( reducer ?. dispatch ) {
117
+ console . log ( 'Dispatching reducer update:' , {
118
+ reducerIndex,
119
+ state,
120
+ } ) ;
121
+ await reducer . dispatch ( state ) ;
122
+ } else {
123
+ console . warn ( 'No dispatch found for reducer:' , reducerIndex ) ;
124
+ }
125
+ }
126
+ }
127
+
128
+ targetSnapshot . children . forEach ( ( child ) => updateReactFiberTree ( child , circularComponentTable ) ) ;
98
129
return ;
99
130
}
100
131
}
0 commit comments