rt2zz / redux-persist

persist and rehydrate a redux store
MIT License
12.94k stars 866 forks source link

Does not render from the server for isomorphic applications #876

Open clayrisser opened 6 years ago

clayrisser commented 6 years ago

Why are we subscribing to the persistor after the component renders? This breaks redux-persist for isomorphic applications because the server does not rerender since the html has already been sent to the client.

componentDidMount() {
  this._unsubscribe = this.props.persistor.subscribe(
    this.handlePersistorState
  )
  this.handlePersistorState()
}

Subscribing to the persistor before the first (and only) render enables proper isomorphic support.

componentWillMount() {
  this._unsubscribe = this.props.persistor.subscribe(
    this.handlePersistorState
  )
  this.handlePersistorState()
}

https://github.com/rt2zz/redux-persist/blob/master/src/integration/react.js#L27-L32

clayrisser commented 6 years ago

If you want this fix immediately, you can add the following to the dependencies section of your package.json file.

"redux-persist": "git+https://github.com/codejamninja/redux-persist.git#npm"