File tree Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -117,7 +117,7 @@ export default function connectAdvanced(
117117 }
118118
119119 getChildContext ( ) {
120- return { [ subscriptionKey ] : this . subscription }
120+ return { [ subscriptionKey ] : this . subscription || this . parentSub }
121121 }
122122
123123 componentDidMount ( ) {
Original file line number Diff line number Diff line change @@ -2149,5 +2149,26 @@ describe('React', () => {
21492149 store . dispatch ( { type : 'INC' } )
21502150 expect ( mapStateToProps . calls . length ) . toBe ( 2 )
21512151 } )
2152+
2153+ it ( 'should subscribe properly when a middle connected component does not subscribe' , ( ) => {
2154+
2155+ @connect ( state => ( { count : state } ) )
2156+ class A extends React . Component { render ( ) { return < B { ...this . props } /> } }
2157+
2158+ @connect ( ) // no mapStateToProps. therefore it should be transparent for subscriptions
2159+ class B extends React . Component { render ( ) { return < C { ...this . props } /> } }
2160+
2161+ @connect ( ( state , props ) => {
2162+ expect ( props . count ) . toBe ( state )
2163+ return { count : state * 10 + props . count }
2164+ } )
2165+ class C extends React . Component { render ( ) { return < div > { this . props . count } </ div > } }
2166+
2167+ const store = createStore ( ( state = 0 , action ) => ( action . type === 'INC' ? state += 1 : state ) )
2168+ TestUtils . renderIntoDocument ( < ProviderMock store = { store } > < A /> </ ProviderMock > )
2169+
2170+ store . dispatch ( { type : 'INC' } )
2171+ } )
2172+
21522173 } )
21532174} )
You can’t perform that action at this time.
0 commit comments