@@ -45,7 +45,6 @@ export default function timeJumpInitiation(mode: Status) {
45
45
*
46
46
*/
47
47
async function updateReactFiberTree (
48
- //TypeScript Note: Adding a tree type to targetSnapshot throws errors for destructuring componentData below. Not sure how precisely to fix
49
48
targetSnapshot ,
50
49
circularComponentTable : Set < any > = new Set ( ) ,
51
50
) : Promise < void > {
@@ -57,47 +56,43 @@ async function updateReactFiberTree(
57
56
circularComponentTable . add ( targetSnapshot ) ;
58
57
}
59
58
// ------------------------STATELESS/ROOT COMPONENT-------------------------
60
- // Since stateless component has no data to update, continue to traverse its child nodes:
61
59
if ( targetSnapshot . state === 'stateless' || targetSnapshot . state === 'root' ) {
62
60
targetSnapshot . children . forEach ( ( child ) => updateReactFiberTree ( child , circularComponentTable ) ) ;
63
61
return ;
64
62
}
65
63
66
- // Destructure component data:
67
- const { index , state , hooksIndex , hooksState } = targetSnapshot . componentData ;
64
+ const { index , state , hooksIndex , hooksState , reducerState } = targetSnapshot . componentData ;
65
+
68
66
// ------------------------STATEFUL CLASS COMPONENT-------------------------
69
- // Check if it is a stateful class component
70
- // Index can be zero => falsy value => DO NOT REMOVE NULL
71
67
if ( index !== null ) {
72
- // Obtain the BOUND update method at the given index
73
68
const classComponent = componentActionsRecord . getComponentByIndex ( index ) ;
74
- // This conditional avoids the error that occurs when classComponent is undefined
75
69
if ( classComponent !== undefined ) {
76
- // Update component state
77
- await classComponent . setState (
78
- // prevState contains the states of the snapshots we are jumping FROM, not jumping TO
79
- ( prevState ) => state ,
80
- ) ;
70
+ await classComponent . setState ( ( ) => state ) ;
81
71
}
82
- // Iterate through new children after state has been set
83
72
targetSnapshot . children . forEach ( ( child ) => updateReactFiberTree ( child , circularComponentTable ) ) ;
84
73
return ;
85
74
}
86
75
87
76
// ----------------------STATEFUL FUNCTIONAL COMPONENT----------------------
88
- // Check if it is a stateful functional component
89
- // if yes, grab all relevant components for this snapshot by its index
90
- // call dispatch on each component passing in the corresponding currState value
91
- //index can be zero => falsy value => DO NOT REMOVE NULL
92
77
if ( hooksIndex !== null ) {
93
- // Obtain the array of BOUND update methods at the given indexes.
94
- // NOTE: each useState will be a separate update method. So if a component have 3 useState, we will obtain an array of 3 update methods.
95
78
const functionalComponent = componentActionsRecord . getComponentByIndexHooks ( hooksIndex ) ;
96
- // Update component state
97
- for ( let i in functionalComponent ) {
98
- await functionalComponent [ i ] . dispatch ( Object . values ( hooksState ) [ i ] ) ;
79
+
80
+ // Handle reducer state if present
81
+ if ( reducerState ) {
82
+ try {
83
+ // For reducer components, update using the first dispatch function
84
+ await functionalComponent [ 0 ] ?. dispatch ( reducerState ) ;
85
+ } catch ( err ) {
86
+ console . error ( 'Error updating reducer state:' , err ) ;
87
+ }
88
+ } else {
89
+ // Handle normal useState components
90
+ for ( let i in functionalComponent ) {
91
+ if ( functionalComponent [ i ] ?. dispatch ) {
92
+ await functionalComponent [ i ] . dispatch ( Object . values ( hooksState ) [ i ] ) ;
93
+ }
94
+ }
99
95
}
100
- // Iterate through new children after state has been set
101
96
targetSnapshot . children . forEach ( ( child ) => updateReactFiberTree ( child ) ) ;
102
97
return ;
103
98
}
0 commit comments