Skip to content

Commit 16a6253

Browse files
committed
removed useRef - fixed new test on CM
1 parent 5ed652c commit 16a6253

File tree

1 file changed

+7
-15
lines changed

1 file changed

+7
-15
lines changed

src/components/connectAdvanced.js

+7-15
Original file line numberDiff line numberDiff line change
@@ -239,9 +239,6 @@ export default function connectAdvanced(
239239
const childPropsFromStoreUpdate = useRef()
240240
const renderIsScheduled = useRef(false)
241241

242-
const latestReduxState = useRef()
243-
const latestReduxStateIsValid = useRef(false)
244-
245242
const actualChildProps = usePureOnlyMemo(() => {
246243
// Tricky logic here:
247244
// - This render may have been triggered by a Redux store update that produced new child props
@@ -257,16 +254,10 @@ export default function connectAdvanced(
257254
}
258255

259256
return childPropsSelector(
260-
latestReduxStateIsValid.current
261-
? latestReduxState.current
262-
: previousStateUpdateResult.reduxState,
257+
previousStateUpdateResult.reduxState,
263258
wrapperProps
264259
)
265-
}, [
266-
latestReduxStateIsValid.current,
267-
previousStateUpdateResult.reduxState,
268-
wrapperProps
269-
])
260+
}, [previousStateUpdateResult.reduxState, wrapperProps])
270261

271262
// We need this to execute synchronously every time we re-render. However, React warns
272263
// about useLayoutEffect in SSR, so we try to detect environment and fall back to
@@ -322,8 +313,11 @@ export default function connectAdvanced(
322313

323314
// If the child props haven't changed, nothing to do here - cascade the subscription update
324315
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+
})
327321

328322
if (!renderIsScheduled.current) {
329323
notifyNestedSubs()
@@ -338,8 +332,6 @@ export default function connectAdvanced(
338332
renderIsScheduled.current = true
339333

340334
// 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
343335
forceComponentUpdateDispatch({
344336
error,
345337
reduxState: latestStoreState

0 commit comments

Comments
 (0)