diff --git a/src/components/Provider.js b/src/components/Provider.js index 6b079d5ec..308f4da71 100644 --- a/src/components/Provider.js +++ b/src/components/Provider.js @@ -1,4 +1,5 @@ import { Component, PropTypes, Children } from 'react' +import Subscription from '../utils/Subscription' import storeShape from '../utils/storeShape' import warning from '../utils/warning' @@ -20,7 +21,7 @@ function warnAboutReceivingStore() { export default class Provider extends Component { getChildContext() { - return { store: this.store } + return { store: this.store, storeSubscription: null } } constructor(props, context) { @@ -49,6 +50,7 @@ Provider.propTypes = { children: PropTypes.element.isRequired } Provider.childContextTypes = { - store: storeShape.isRequired + store: storeShape.isRequired, + storeSubscription: PropTypes.instanceOf(Subscription) } Provider.displayName = 'Provider' diff --git a/test/components/Provider.spec.js b/test/components/Provider.spec.js index 66a88cc0d..fdb6c7bed 100644 --- a/test/components/Provider.spec.js +++ b/test/components/Provider.spec.js @@ -109,6 +109,29 @@ describe('React', () => { expect(child.context.store.getState()).toEqual(11) expect(spy.calls.length).toBe(0) }) + + it('should handle subscriptions correctly when there is nested Providers', () => { + const reducer = (state = 0, action) => (action.type === 'INC' ? state + 1 : state) + + const innerStore = createStore(reducer) + const innerMapStateToProps = expect.createSpy().andCall(state => ({ count: state })) + @connect(innerMapStateToProps) + class Inner extends Component { + render() { return
{this.props.count}
} + } + + const outerStore = createStore(reducer) + @connect(state => ({ count: state })) + class Outer extends Component { + render() { return } + } + + TestUtils.renderIntoDocument() + expect(innerMapStateToProps.calls.length).toBe(1) + + innerStore.dispatch({ type: 'INC'}) + expect(innerMapStateToProps.calls.length).toBe(2) + }) }) it('should pass state consistently to mapState', () => {