Skip to content

Commit 8efeff7

Browse files
fix(overmind-react): fix production
1 parent 7e3dac0 commit 8efeff7

File tree

1 file changed

+25
-8
lines changed
  • packages/node_modules/overmind-react/src

1 file changed

+25
-8
lines changed

packages/node_modules/overmind-react/src/index.ts

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)