Skip to content

Commit

Permalink
Fix HMR : client was not working + mismatch between server/client (#749)
Browse files Browse the repository at this point in the history
  • Loading branch information
hrasoa authored and jaredpalmer committed Sep 12, 2018
1 parent 50d428f commit 560a9f4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
23 changes: 16 additions & 7 deletions examples/with-react-loadable/src/client.js
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();
}
3 changes: 2 additions & 1 deletion examples/with-react-loadable/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ Loadable.preloadAll().then(() => {
if (module.hot) {
console.log('✅ Server-side HMR Enabled!');

module.hot.accept('./server', () => {
module.hot.accept('./server', async () => {
console.log('🔁 HMR Reloading `./server`...');
server.removeListener('request', currentApp);
const newApp = require('./server').default;
await Loadable.preloadAll();
server.on('request', newApp);
currentApp = newApp;
});
Expand Down

0 comments on commit 560a9f4

Please sign in to comment.