@@ -24,6 +24,9 @@ import {
2424} from 'react'
2525
2626const IS_PRODUCTION = process . env . NODE_ENV === 'production'
27+ const IS_TEST = process . env . NODE_ENV === 'test'
28+ const isNode =
29+ ! IS_TEST && process && process . title && process . title . includes ( 'node' )
2730
2831export type IReactComponent < P = any > =
2932 | StatelessComponent < P >
@@ -81,8 +84,19 @@ export const createHook = <Config extends IConfiguration>(
8184 }
8285 const useForceRerender = ( ) => {
8386 const [ , setState ] = useState ( ( ) => true )
87+ const mountedRef = useRef ( true )
88+
89+ useEffect (
90+ ( ) => ( ) => {
91+ mountedRef . current = false
92+ } ,
93+ [ ]
94+ )
95+
8496 const forceRerender = ( _ , __ , flushId ) : void => {
85- setState ( flushId )
97+ if ( mountedRef . current ) {
98+ setState ( flushId )
99+ }
86100 }
87101 return forceRerender
88102 }
@@ -98,22 +112,14 @@ export const createHook = <Config extends IConfiguration>(
98112 )
99113 }
100114
101- if ( ( overmind as any ) . mode . mode === MODE_SSR ) {
115+ if ( isNode || ( overmind as any ) . mode . mode === MODE_SSR ) {
102116 return {
103117 state : overmind . state ,
104118 actions : overmind . actions ,
105119 effects : overmind . effects ,
106120 addMutationListener : overmind . addMutationListener ,
107121 }
108122 }
109-
110- const component = useCurrentComponent ( )
111- const name = component . name
112- component . __componentId =
113- typeof component . __componentId === 'undefined'
114- ? nextComponentId ++
115- : component . __componentId
116-
117123 const { current : tree } = useRef < any > (
118124 ( overmind as any ) . proxyStateTree . getTrackStateTree ( )
119125 )
@@ -132,6 +138,13 @@ export const createHook = <Config extends IConfiguration>(
132138
133139 useLayoutEffect ( ( ) => tree . stopTracking ( ) )
134140 } else {
141+ const component = useCurrentComponent ( )
142+ const name = component . name
143+ component . __componentId =
144+ typeof component . __componentId === 'undefined'
145+ ? nextComponentId ++
146+ : component . __componentId
147+
135148 const { current : componentInstanceId } = useRef < any > (
136149 currentComponentInstanceId ++
137150 )
0 commit comments