Skip to content

Commit

Permalink
Fix for '[HMR] You need to restart the application!' on server sided err
Browse files Browse the repository at this point in the history
  • Loading branch information
Bram-Zijp committed Aug 24, 2018
1 parent c0013d4 commit c8b55be
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions packages/create-razzle-app/templates/default/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,23 @@ server.listen(process.env.PORT || 3000, error => {
if (module.hot) {
console.log('✅ Server-side HMR Enabled!');

const noErrors = () => {
try {
require('./server').default;
} catch (error) {
console.error(error);
return false;
}
return true;
};

module.hot.accept('./server', () => {
console.log('🔁 HMR Reloading `./server`...');
server.removeListener('request', currentApp);
const newApp = require('./server').default;
server.on('request', newApp);
currentApp = newApp;
if (noErrors()) {
console.log('🔁 HMR Reloading `./server`...');
server.removeListener('request', currentApp);
const newApp = require('./server').default;
server.on('request', newApp);
currentApp = newApp;
}
});
}

0 comments on commit c8b55be

Please sign in to comment.