File tree 2 files changed +29
-1
lines changed
2 files changed +29
-1
lines changed Original file line number Diff line number Diff line change @@ -38,10 +38,13 @@ export default function createConnector(React) {
38
38
constructor ( props , context ) {
39
39
super ( props , context ) ;
40
40
41
- this . unsubscribe = context . redux . subscribe ( ::this . handleChange ) ;
42
41
this . state = this . selectState ( props , context ) ;
43
42
}
44
43
44
+ componentDidMount ( ) {
45
+ this . unsubscribe = this . context . redux . subscribe ( ::this . handleChange ) ;
46
+ }
47
+
45
48
componentWillReceiveProps ( nextProps ) {
46
49
if ( nextProps . select !== this . props . select ) {
47
50
// Force the state slice recalculation
Original file line number Diff line number Diff line change @@ -202,5 +202,30 @@ describe('React', () => {
202
202
) ;
203
203
} ) . toThrow ( / s e l e c t / ) ;
204
204
} ) ;
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
+ } ) ;
205
230
} ) ;
206
231
} ) ;
You can’t perform that action at this time.
0 commit comments