Skip to content

Commit f4d5584

Browse files
jimbollatimdorr
authored andcommitted
Fixes #577 (#579)
storeSubscription context object is lost when a component don't have a mapStateToProps
1 parent 00f6c6b commit f4d5584

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/components/connectAdvanced.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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() {

test/components/connect.spec.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff 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
})

0 commit comments

Comments
 (0)