-
-
Notifications
You must be signed in to change notification settings - Fork 866
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix HMR : client was not working + mismatch between server/client (#749)
- Loading branch information
1 parent
50d428f
commit 560a9f4
Showing
2 changed files
with
18 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,29 @@ | ||
import App from './App'; | ||
import React from 'react'; | ||
import { hydrate } from 'react-dom'; | ||
import Loadable from 'react-loadable'; | ||
import BrowserRouter from 'react-router-dom/BrowserRouter'; | ||
import App from './App'; | ||
|
||
const root = document.getElementById('root'); | ||
|
||
window.main = () => { | ||
render(App); | ||
}; | ||
|
||
if (module.hot) { | ||
module.hot.accept('./App', () => { | ||
const NewApp = require('./App').default; | ||
render(NewApp); | ||
}); | ||
} | ||
|
||
function render(Root) { | ||
Loadable.preloadReady().then(() => { | ||
hydrate( | ||
<BrowserRouter> | ||
<App /> | ||
<Root /> | ||
</BrowserRouter>, | ||
document.getElementById('root') | ||
root, | ||
); | ||
}); | ||
} | ||
|
||
if (module.hot) { | ||
module.hot.accept(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters