nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: reduxjs/react-redux
Pull request #1235 (2019-04-12 14:23:47)

fix timing issue with setting up store subscription inside a connected component
This is a fix for #1226.

netlify[bot]: Deploy preview for *react-redux-docs* ready!

Built with commit e71e7f12186f84135e031322cbadb572a6c82d85

https://deploy-preview-1235--react-redux-docs.netlify.com
timdorr: Perfect. Thanks!

Patch:
diff --git a/src/components/connectAdvanced.js b/src/components/connectAdvanced.js
index 6169fcb..0678a80 100644
--- a/src/components/connectAdvanced.js
+++ b/src/components/connectAdvanced.js
@@ -291,7 +291,7 @@ export default function connectAdvanced(
       })
 
       // Our re-subscribe logic only runs when the store/subscription setup changes
-      useEffect(() => {
+      useIsomorphicLayoutEffect(() => {
         // If we're not subscribed to the store, nothing to do here
         if (!shouldHandleStateChanges) return
 


Test patch:
diff --git a/test/components/connect.spec.js b/test/components/connect.spec.js
index 9e8a3a9..b2bbe2a 100644
--- a/test/components/connect.spec.js
+++ b/test/components/connect.spec.js
@@ -1926,6 +1926,38 @@ describe('React', () => {
 
         expect(mapStateToProps).toHaveBeenCalledTimes(2)
       })
+
+      it('should not notify nested components after they are unmounted', () => {
+        @connect(state => ({ count: state }))
+        class Parent extends Component {
+          render() {
+            return this.props.count === 1 ? <Child /> : null
+          }
+        }
+
+        const mapStateToProps = jest.fn(state => ({ count: state }))
+        @connect(mapStateToProps)
+        class Child extends Component {
+          render() {
+            return <div>{this.props.count}</div>
+          }
+        }
+
+        const store = createStore((state = 0, action) =>
+          action.type === 'INC' ? state + 1 : state
+        )
+        rtl.render(
+          <ProviderMock store={store}>
+            <Parent />
+          </ProviderMock>
+        )
+
+        expect(mapStateToProps).toHaveBeenCalledTimes(0)
+        store.dispatch({ type: 'INC' })
+        expect(mapStateToProps).toHaveBeenCalledTimes(1)
+        store.dispatch({ type: 'INC' })
+        expect(mapStateToProps).toHaveBeenCalledTimes(1)
+      })
     })
 
     describe('Custom context and store-as-prop', () => {