@@ -60,13 +60,6 @@ async function updateReactFiberTree(
60
60
61
61
const { index, state, hooksIndex, hooksState, reducerStates } = targetSnapshot . componentData ;
62
62
63
- console . log ( 'Processing snapshot in timeJump:' , {
64
- componentName : targetSnapshot . name ,
65
- hasHooksIndex : ! ! hooksIndex ,
66
- hooksState,
67
- reducerStates,
68
- } ) ;
69
-
70
63
// Handle class components
71
64
if ( index !== null ) {
72
65
const classComponent = componentActionsRecord . getComponentByIndex ( index ) ;
@@ -81,51 +74,86 @@ async function updateReactFiberTree(
81
74
if ( hooksIndex !== null ) {
82
75
const functionalComponent = componentActionsRecord . getComponentByIndexHooks ( hooksIndex ) ;
83
76
84
- console . log ( 'Retrieved functional component:' , {
85
- hasComponent : ! ! functionalComponent ,
86
- hooksIndexLength : hooksIndex . length ,
87
- componentLength : functionalComponent ?. length ,
88
- } ) ;
89
-
90
77
// Handle regular useState hooks
91
78
if ( hooksState ) {
92
79
const stateEntries = Object . entries ( hooksState ) ;
93
-
94
80
for ( let i = 0 ; i < stateEntries . length ; i ++ ) {
95
81
const [ key , value ] = stateEntries [ i ] ;
96
82
if ( functionalComponent [ i ] ?. dispatch ) {
97
- console . log ( 'Dispatching state update:' , {
98
- key,
99
- value,
100
- } ) ;
101
83
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
- } ) ;
108
84
}
109
85
}
110
86
}
111
87
112
88
// Handle reducer hooks
113
89
if ( reducerStates && reducerStates . length > 0 ) {
114
- console . log ( 'Processing reducer states:' , reducerStates ) ;
115
-
116
90
for ( const reducerState of reducerStates ) {
117
- const { state, reducerIndex } = reducerState ;
91
+ const { state : targetState , reducerIndex, hookName } = reducerState ;
118
92
const reducer = functionalComponent [ reducerIndex ] ;
119
- console . log ( 'reducer' , reducer ) ;
120
93
121
94
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,
125
99
} ) ;
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
+ }
127
151
} 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
+ } ) ;
129
157
}
130
158
}
131
159
}
0 commit comments