From 81581b00120924ec0dae99654e9fd2c8b9970f02 Mon Sep 17 00:00:00 2001 From: Malash Date: Tue, 29 Oct 2019 22:57:19 +0800 Subject: [PATCH] try to update refs immediately rather than useIsomorphicLayoutEffect --- src/components/connectAdvanced.js | 10 +++++----- src/hooks/useSelector.js | 8 +++----- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/components/connectAdvanced.js b/src/components/connectAdvanced.js index cafa0baa3..12cf6fe3b 100644 --- a/src/components/connectAdvanced.js +++ b/src/components/connectAdvanced.js @@ -280,15 +280,15 @@ export default function connectAdvanced( return childPropsSelector(store.getState(), wrapperProps) }, [store, previousStateUpdateResult, wrapperProps]) + // We want to capture the wrapper props and child props we used for later comparisons + lastWrapperProps.current = wrapperProps + lastChildProps.current = actualChildProps + renderIsScheduled.current = false + // We need this to execute synchronously every time we re-render. However, React warns // about useLayoutEffect in SSR, so we try to detect environment and fall back to // just useEffect instead to avoid the warning, since neither will run anyway. useIsomorphicLayoutEffect(() => { - // We want to capture the wrapper props and child props we used for later comparisons - lastWrapperProps.current = wrapperProps - lastChildProps.current = actualChildProps - renderIsScheduled.current = false - // If the render was from a store update, clear out that reference and cascade the subscriber update if (childPropsFromStoreUpdate.current) { childPropsFromStoreUpdate.current = null diff --git a/src/hooks/useSelector.js b/src/hooks/useSelector.js index 2a4eda6c0..7a26770f0 100644 --- a/src/hooks/useSelector.js +++ b/src/hooks/useSelector.js @@ -66,11 +66,9 @@ function useSelectorWithStoreAndSubscription( throw new Error(errorMessage) } - useIsomorphicLayoutEffect(() => { - latestSelector.current = selector - latestSelectedState.current = selectedState - latestSubscriptionCallbackError.current = undefined - }) + latestSelector.current = selector + latestSelectedState.current = selectedState + latestSubscriptionCallbackError.current = undefined useIsomorphicLayoutEffect(() => { function checkForUpdates() {