Skip to content

Commit 3d0476a

Browse files
committed
Merge pull request #179 from mattybow/master
subscribe moved from Connector constructor to componentDidMount
2 parents d7dbfcb + b8ed2a8 commit 3d0476a

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

src/components/createConnector.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,13 @@ export default function createConnector(React) {
3838
constructor(props, context) {
3939
super(props, context);
4040

41-
this.unsubscribe = context.redux.subscribe(::this.handleChange);
4241
this.state = this.selectState(props, context);
4342
}
4443

44+
componentDidMount() {
45+
this.unsubscribe = this.context.redux.subscribe(::this.handleChange);
46+
}
47+
4548
componentWillReceiveProps(nextProps) {
4649
if (nextProps.select !== this.props.select) {
4750
// Force the state slice recalculation

test/components/Connector.spec.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,5 +202,30 @@ describe('React', () => {
202202
);
203203
}).toThrow(/select/);
204204
});
205+
206+
it('does not throw error when `renderToString` is called on server', () => {
207+
const { renderToString } = React;
208+
const redux = createRedux({ string: stringBuilder });
209+
class TestComp extends Component {
210+
componentWillMount() {
211+
// simulate response action on data returning
212+
redux.dispatch({ type: 'APPEND', body: 'a'});
213+
}
214+
render() {
215+
return (<div>{this.props.string}</div>);
216+
}
217+
}
218+
const el = (
219+
<Provider redux={redux}>
220+
{() => (
221+
<Connector select={state => ({ string: state.string })}>
222+
{({ string }) => <TestComp string={string} />}
223+
</Connector>
224+
)}
225+
</Provider>
226+
);
227+
expect(() => renderToString(el)).toNotThrow();
228+
229+
});
205230
});
206231
});

0 commit comments

Comments
 (0)