1
0
Fork 0
mirror of https://github.com/terribleplan/next.js.git synced 2024-01-19 02:48:18 +00:00

Run initializeStore() only once per route on server (#5644)

On the server `props.initialMobxState` received by the `constructor` is a fully functioning mobx store that was instantiated by `getInitialProps()` only a few ticks earlier.
Thus, creating a new instance is unneccessary.

In the browser, however, `props.initialMobxState` is a hydrated plain object and thus the store needs to be initialized.
This commit is contained in:
Már Örlygsson 2018-11-20 14:53:28 +00:00 committed by Tim Neutkens
parent 76202f2fb2
commit 766d7d5fe4

View file

@ -21,7 +21,10 @@ class MyMobxApp extends App {
constructor(props) {
super(props)
this.mobxStore = initializeStore(props.initialMobxState)
const isServer = typeof window === 'undefined'
this.mobxStore = isServer ?
props.initialMobxState:
initializeStore(props.initialMobxState)
}
render() {