Skip to content

Commit 81581b0

Browse files
committed
try to update refs immediately rather than useIsomorphicLayoutEffect
1 parent 2eac861 commit 81581b0

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

src/components/connectAdvanced.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -280,15 +280,15 @@ export default function connectAdvanced(
280280
return childPropsSelector(store.getState(), wrapperProps)
281281
}, [store, previousStateUpdateResult, wrapperProps])
282282

283+
// We want to capture the wrapper props and child props we used for later comparisons
284+
lastWrapperProps.current = wrapperProps
285+
lastChildProps.current = actualChildProps
286+
renderIsScheduled.current = false
287+
283288
// We need this to execute synchronously every time we re-render. However, React warns
284289
// about useLayoutEffect in SSR, so we try to detect environment and fall back to
285290
// just useEffect instead to avoid the warning, since neither will run anyway.
286291
useIsomorphicLayoutEffect(() => {
287-
// We want to capture the wrapper props and child props we used for later comparisons
288-
lastWrapperProps.current = wrapperProps
289-
lastChildProps.current = actualChildProps
290-
renderIsScheduled.current = false
291-
292292
// If the render was from a store update, clear out that reference and cascade the subscriber update
293293
if (childPropsFromStoreUpdate.current) {
294294
childPropsFromStoreUpdate.current = null

src/hooks/useSelector.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,9 @@ function useSelectorWithStoreAndSubscription(
6666
throw new Error(errorMessage)
6767
}
6868

69-
useIsomorphicLayoutEffect(() => {
70-
latestSelector.current = selector
71-
latestSelectedState.current = selectedState
72-
latestSubscriptionCallbackError.current = undefined
73-
})
69+
latestSelector.current = selector
70+
latestSelectedState.current = selectedState
71+
latestSubscriptionCallbackError.current = undefined
7472

7573
useIsomorphicLayoutEffect(() => {
7674
function checkForUpdates() {

0 commit comments

Comments
 (0)