From 54ff7a6ba3a219b84e3323119bc7dc70bf332d6e Mon Sep 17 00:00:00 2001 From: Mark Erikson Date: Fri, 1 Apr 2022 10:04:20 -0400 Subject: [PATCH] Backport compat fix for React 18 strict effects Subscriptions in Provider need to be set up in the effect, not in the `useMemo` hook. Port of commit 9a210fd from 8.x development --- src/components/Provider.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/Provider.js b/src/components/Provider.js index 9bae9445f..a62cce2ec 100644 --- a/src/components/Provider.js +++ b/src/components/Provider.js @@ -7,7 +7,6 @@ import { useIsomorphicLayoutEffect } from '../utils/useIsomorphicLayoutEffect' function Provider({ store, context, children }) { const contextValue = useMemo(() => { const subscription = createSubscription(store) - subscription.onStateChange = subscription.notifyNestedSubs return { store, subscription, @@ -18,6 +17,7 @@ function Provider({ store, context, children }) { useIsomorphicLayoutEffect(() => { const { subscription } = contextValue + subscription.onStateChange = subscription.notifyNestedSubs subscription.trySubscribe() if (previousState !== store.getState()) {