@@ -239,9 +239,6 @@ export default function connectAdvanced(
239
239
const childPropsFromStoreUpdate = useRef ( )
240
240
const renderIsScheduled = useRef ( false )
241
241
242
- const latestReduxState = useRef ( )
243
- const latestReduxStateIsValid = useRef ( false )
244
-
245
242
const actualChildProps = usePureOnlyMemo ( ( ) => {
246
243
// Tricky logic here:
247
244
// - This render may have been triggered by a Redux store update that produced new child props
@@ -257,16 +254,10 @@ export default function connectAdvanced(
257
254
}
258
255
259
256
return childPropsSelector (
260
- latestReduxStateIsValid . current
261
- ? latestReduxState . current
262
- : previousStateUpdateResult . reduxState ,
257
+ previousStateUpdateResult . reduxState ,
263
258
wrapperProps
264
259
)
265
- } , [
266
- latestReduxStateIsValid . current ,
267
- previousStateUpdateResult . reduxState ,
268
- wrapperProps
269
- ] )
260
+ } , [ previousStateUpdateResult . reduxState , wrapperProps ] )
270
261
271
262
// We need this to execute synchronously every time we re-render. However, React warns
272
263
// about useLayoutEffect in SSR, so we try to detect environment and fall back to
@@ -322,8 +313,11 @@ export default function connectAdvanced(
322
313
323
314
// If the child props haven't changed, nothing to do here - cascade the subscription update
324
315
if ( newChildProps === lastChildProps . current ) {
325
- latestReduxState . current = latestStoreState
326
- latestReduxStateIsValid . current = true
316
+ forceComponentUpdateDispatch ( prev => {
317
+ prev . error = error
318
+ prev . reduxState = latestStoreState
319
+ return prev
320
+ } )
327
321
328
322
if ( ! renderIsScheduled . current ) {
329
323
notifyNestedSubs ( )
@@ -338,8 +332,6 @@ export default function connectAdvanced(
338
332
renderIsScheduled . current = true
339
333
340
334
// If the child props _did_ change (or we caught an error), this wrapper component needs to re-render
341
- latestReduxStateIsValid . current = false
342
- latestReduxState . current = undefined
343
335
forceComponentUpdateDispatch ( {
344
336
error,
345
337
reduxState : latestStoreState
0 commit comments