@@ -226,7 +226,7 @@ export default function connectAdvanced(
226
226
const [
227
227
previousStateUpdateResult ,
228
228
forceComponentUpdateDispatch
229
- ] = useState ( { reduxStore : store . getState ( ) } )
229
+ ] = useState ( { reduxState : store . getState ( ) } )
230
230
231
231
// Propagate any mapState/mapDispatch errors upwards
232
232
if ( previousStateUpdateResult && previousStateUpdateResult . error ) {
@@ -239,7 +239,8 @@ export default function connectAdvanced(
239
239
const childPropsFromStoreUpdate = useRef ( )
240
240
const renderIsScheduled = useRef ( false )
241
241
242
- const latestReduxStore = useRef ( )
242
+ const latestReduxState = useRef ( )
243
+ const latestReduxStateIsValid = useRef ( false )
243
244
244
245
const actualChildProps = usePureOnlyMemo ( ( ) => {
245
246
// Tricky logic here:
@@ -255,17 +256,15 @@ export default function connectAdvanced(
255
256
return childPropsFromStoreUpdate . current
256
257
}
257
258
258
- // TODO We're reading the store directly in render() here. Bad idea?
259
- // This will likely cause Bad Things (TM) to happen in Concurrent Mode.
260
- // Note that we do this because on renders _not_ caused by store updates, we need the latest store state
261
- // to determine what the child props should be.
262
259
return childPropsSelector (
263
- latestReduxStore . current || previousStateUpdateResult . reduxStore ,
260
+ latestReduxStateIsValid . current
261
+ ? latestReduxState . current
262
+ : previousStateUpdateResult . reduxState ,
264
263
wrapperProps
265
264
)
266
265
} , [
267
- latestReduxStore . current ,
268
- previousStateUpdateResult . reduxStore ,
266
+ latestReduxStateIsValid . current ,
267
+ previousStateUpdateResult . reduxState ,
269
268
wrapperProps
270
269
] )
271
270
@@ -323,7 +322,8 @@ export default function connectAdvanced(
323
322
324
323
// If the child props haven't changed, nothing to do here - cascade the subscription update
325
324
if ( newChildProps === lastChildProps . current ) {
326
- latestReduxStore . current = latestStoreState
325
+ latestReduxState . current = latestStoreState
326
+ latestReduxStateIsValid . current = true
327
327
328
328
if ( ! renderIsScheduled . current ) {
329
329
notifyNestedSubs ( )
@@ -338,10 +338,11 @@ export default function connectAdvanced(
338
338
renderIsScheduled . current = true
339
339
340
340
// If the child props _did_ change (or we caught an error), this wrapper component needs to re-render
341
- latestReduxStore . current = undefined
341
+ latestReduxStateIsValid . current = false
342
+ latestReduxState . current = undefined
342
343
forceComponentUpdateDispatch ( {
343
344
error,
344
- reduxStore : latestStoreState
345
+ reduxState : latestStoreState
345
346
} )
346
347
}
347
348
}
0 commit comments