@@ -60,13 +60,6 @@ async function updateReactFiberTree(
6060
6161 const { index, state, hooksIndex, hooksState, reducerStates } = targetSnapshot . componentData ;
6262
63- console . log ( 'Processing snapshot in timeJump:' , {
64- componentName : targetSnapshot . name ,
65- hasHooksIndex : ! ! hooksIndex ,
66- hooksState,
67- reducerStates,
68- } ) ;
69-
7063 // Handle class components
7164 if ( index !== null ) {
7265 const classComponent = componentActionsRecord . getComponentByIndex ( index ) ;
@@ -81,51 +74,86 @@ async function updateReactFiberTree(
8174 if ( hooksIndex !== null ) {
8275 const functionalComponent = componentActionsRecord . getComponentByIndexHooks ( hooksIndex ) ;
8376
84- console . log ( 'Retrieved functional component:' , {
85- hasComponent : ! ! functionalComponent ,
86- hooksIndexLength : hooksIndex . length ,
87- componentLength : functionalComponent ?. length ,
88- } ) ;
89-
9077 // Handle regular useState hooks
9178 if ( hooksState ) {
9279 const stateEntries = Object . entries ( hooksState ) ;
93-
9480 for ( let i = 0 ; i < stateEntries . length ; i ++ ) {
9581 const [ key , value ] = stateEntries [ i ] ;
9682 if ( functionalComponent [ i ] ?. dispatch ) {
97- console . log ( 'Dispatching state update:' , {
98- key,
99- value,
100- } ) ;
10183 await functionalComponent [ i ] . dispatch ( value ) ;
102- } else {
103- console . warn ( `No dispatch found for hook ${ i } :` , {
104- key,
105- value,
106- hasDispatch : ! ! functionalComponent [ i ] ?. dispatch ,
107- } ) ;
10884 }
10985 }
11086 }
11187
11288 // Handle reducer hooks
11389 if ( reducerStates && reducerStates . length > 0 ) {
114- console . log ( 'Processing reducer states:' , reducerStates ) ;
115-
11690 for ( const reducerState of reducerStates ) {
117- const { state, reducerIndex } = reducerState ;
91+ const { state : targetState , reducerIndex, hookName } = reducerState ;
11892 const reducer = functionalComponent [ reducerIndex ] ;
119- console . log ( 'reducer' , reducer ) ;
12093
12194 if ( reducer ?. dispatch ) {
122- console . log ( 'Dispatching reducer update:' , {
123- reducerIndex,
124- state,
95+ console . log ( 'Current reducer state:' , {
96+ hookName,
97+ currentState : reducer . lastRenderedState ,
98+ targetState,
12599 } ) ;
126- await reducer . dispatch ( state ) ;
100+
101+ // Store original values
102+ const originalReducer = reducer . lastRenderedReducer ;
103+ const originalState = reducer . lastRenderedState ;
104+
105+ try {
106+ // Set the new state directly
107+ reducer . lastRenderedState = targetState ;
108+
109+ // Override the reducer temporarily
110+ reducer . lastRenderedReducer = ( state : any , action : any ) => {
111+ if ( action . type === '@@REACTIME/FORCE_STATE_UPDATE' ) {
112+ return action . payload ;
113+ }
114+ return originalReducer ? originalReducer ( state , action ) : state ;
115+ } ;
116+
117+ // Dispatch the force update action
118+ const forceUpdateAction = {
119+ type : '@@REACTIME/FORCE_STATE_UPDATE' ,
120+ payload : targetState ,
121+ } ;
122+
123+ await reducer . dispatch ( forceUpdateAction ) ;
124+
125+ console . log ( 'Post-dispatch state:' , {
126+ hookName,
127+ newState : reducer . lastRenderedState ,
128+ success : JSON . stringify ( reducer . lastRenderedState ) === JSON . stringify ( targetState ) ,
129+ } ) ;
130+ } catch ( error ) {
131+ console . error ( 'Error updating reducer state:' , {
132+ hookName,
133+ error,
134+ componentName : targetSnapshot . name ,
135+ } ) ;
136+ // Restore original state on error
137+ reducer . lastRenderedState = originalState ;
138+ } finally {
139+ // Restore original reducer
140+ reducer . lastRenderedReducer = originalReducer ;
141+
142+ console . log ( 'Final reducer state check:' , {
143+ hookName,
144+ originalState,
145+ targetState,
146+ finalState : reducer . lastRenderedState ,
147+ stateMatchesTarget :
148+ JSON . stringify ( reducer . lastRenderedState ) === JSON . stringify ( targetState ) ,
149+ } ) ;
150+ }
127151 } else {
128- console . warn ( 'No dispatch found for reducer:' , reducerIndex ) ;
152+ console . warn ( 'No dispatch found for reducer:' , {
153+ hookName,
154+ reducerIndex,
155+ componentName : targetSnapshot . name ,
156+ } ) ;
129157 }
130158 }
131159 }
0 commit comments