File tree Expand file tree Collapse file tree 1 file changed +25
-8
lines changed
packages/node_modules/overmind-react/src Expand file tree Collapse file tree 1 file changed +25
-8
lines changed Original file line number Diff line number Diff line change @@ -108,16 +108,33 @@ const useState = <Config extends IConfiguration>(): Overmind<Config>['state'] =
108108 }
109109
110110 if ( IS_PRODUCTION ) {
111- react . useEffect (
112- ( ) => ( ) => {
113- ; ( overmind as any ) . proxyStateTree . disposeTree ( trackingRef . current . tree )
114- } ,
115- [ ]
116- )
111+ react . useLayoutEffect ( ( ) => {
112+ trackingRef . current . mounted = true
113+
117114
118- react . useLayoutEffect ( ( ) => trackingRef . current . tree . stopTracking ( ) )
115+ if ( trackingRef . current . hasUpdatedBeforeCommit ) {
116+ forceRerender ( )
117+ }
119118
120- trackingRef . current . tree . track ( forceRerender )
119+ return ( ) => {
120+ ; ( overmind as any ) . proxyStateTree . disposeTree ( trackingRef . current . tree )
121+ }
122+ } , [ ] )
123+
124+ react . useLayoutEffect ( ( ) => {
125+ if ( trackingRef . current . stopTrackingTask ) {
126+ unstable_cancelCallback ( trackingRef . current . stopTrackingTask )
127+ trackingRef . current . stopTrackingTask = null
128+ }
129+ trackingRef . current . tree . stopTracking ( )
130+ } )
131+ trackingRef . current . tree . track ( ( ) => {
132+ if ( trackingRef . current . mounted ) {
133+ forceRerender ( )
134+ } else {
135+ trackingRef . current . hasUpdatedBeforeCommit = true
136+ }
137+ } )
121138 } else {
122139 const component = useCurrentComponent ( )
123140 const name = component . name
You can’t perform that action at this time.
0 commit comments