File tree 2 files changed +33
-1
lines changed
2 files changed +33
-1
lines changed Original file line number Diff line number Diff line change @@ -291,7 +291,7 @@ export default function connectAdvanced(
291
291
} )
292
292
293
293
// Our re-subscribe logic only runs when the store/subscription setup changes
294
- useEffect ( ( ) => {
294
+ useIsomorphicLayoutEffect ( ( ) => {
295
295
// If we're not subscribed to the store, nothing to do here
296
296
if ( ! shouldHandleStateChanges ) return
297
297
Original file line number Diff line number Diff line change @@ -1926,6 +1926,38 @@ describe('React', () => {
1926
1926
1927
1927
expect ( mapStateToProps ) . toHaveBeenCalledTimes ( 2 )
1928
1928
} )
1929
+
1930
+ it ( 'should not notify nested components after they are unmounted' , ( ) => {
1931
+ @connect ( state => ( { count : state } ) )
1932
+ class Parent extends Component {
1933
+ render ( ) {
1934
+ return this . props . count === 1 ? < Child /> : null
1935
+ }
1936
+ }
1937
+
1938
+ const mapStateToProps = jest . fn ( state => ( { count : state } ) )
1939
+ @connect ( mapStateToProps )
1940
+ class Child extends Component {
1941
+ render ( ) {
1942
+ return < div > { this . props . count } </ div >
1943
+ }
1944
+ }
1945
+
1946
+ const store = createStore ( ( state = 0 , action ) =>
1947
+ action . type === 'INC' ? state + 1 : state
1948
+ )
1949
+ rtl . render (
1950
+ < ProviderMock store = { store } >
1951
+ < Parent />
1952
+ </ ProviderMock >
1953
+ )
1954
+
1955
+ expect ( mapStateToProps ) . toHaveBeenCalledTimes ( 0 )
1956
+ store . dispatch ( { type : 'INC' } )
1957
+ expect ( mapStateToProps ) . toHaveBeenCalledTimes ( 1 )
1958
+ store . dispatch ( { type : 'INC' } )
1959
+ expect ( mapStateToProps ) . toHaveBeenCalledTimes ( 1 )
1960
+ } )
1929
1961
} )
1930
1962
1931
1963
describe ( 'Custom context and store-as-prop' , ( ) => {
You can’t perform that action at this time.
0 commit comments