@@ -24,7 +24,6 @@ export default function timeJumpInitiation(mode: Status) {
2424 * @param targetSnapshot - The target snapshot to re-render. The payload from index.ts is assigned to targetSnapshot
2525 */
2626 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
2827 mode . jumping = true ;
2928 // Reset mode.navigating
3029 delete mode . navigating ;
@@ -50,21 +49,25 @@ async function updateReactFiberTree(
5049 circularComponentTable : Set < any > = new Set ( ) ,
5150) : Promise < void > {
5251 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+
6056 if ( targetSnapshot . state === 'stateless' || targetSnapshot . state === 'root' ) {
6157 targetSnapshot . children . forEach ( ( child ) => updateReactFiberTree ( child , circularComponentTable ) ) ;
6258 return ;
6359 }
6460
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+ } ) ;
6669
67- // ------------------------STATEFUL CLASS COMPONENT-------------------------
70+ // Handle class components
6871 if ( index !== null ) {
6972 const classComponent = componentActionsRecord . getComponentByIndex ( index ) ;
7073 if ( classComponent !== undefined ) {
@@ -74,27 +77,55 @@ async function updateReactFiberTree(
7477 return ;
7578 }
7679
77- // ----------------------STATEFUL FUNCTIONAL COMPONENT----------------------
80+ // Handle hooks
7881 if ( hooksIndex !== null ) {
7982 const functionalComponent = componentActionsRecord . getComponentByIndexHooks ( hooksIndex ) ;
8083
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 ] ;
9296 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+ } ) ;
94104 }
95105 }
96106 }
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 ) ) ;
98129 return ;
99130 }
100131}
0 commit comments