Skip to content

Commit 5cf823e

Browse files
committed
Update hot-reloading setup & disable on StackBlitz
1 parent d64fc9f commit 5cf823e

File tree

4 files changed

+23
-3
lines changed

4 files changed

+23
-3
lines changed

examples/parent-child-demo/src/App.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react';
2-
import { hot } from 'react-hot-loader';
2+
import { hot } from 'react-hot-loader/root';
33
import { resetInstanceIdCounters, Log } from 'react-lifecycle-visualizer';
44

55
import './style.scss';
@@ -14,5 +14,7 @@ const App = () => (
1414
</div>
1515
);
1616

17-
// Don't set up hot reloading on StackBlitz (where `module` is not defined.)
18-
export default typeof module === 'undefined' ? App : hot(module)(App);
17+
const isOnStackBlitz = module && module.id.match(/https:\/\/.+\.github\.stackblitz\.io\//);
18+
19+
// StackBlitz already does hot reloading, and setting it up here again causes errors, so we disable it.
20+
export default isOnStackBlitz ? App : hot(App);

package-lock.json

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
"@babel/preset-env": "^7.4.5",
5656
"@babel/preset-react": "^7.0.0",
5757
"@babel/preset-stage-2": "^7.0.0",
58+
"@hot-loader/react-dom": "^16.8.6",
5859
"@types/react": "^16.8.22",
5960
"@types/react-dom": "^16.8.4",
6061
"ajv": "^6.10.0",

webpack.config.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ module.exports = {
99
filename: 'client-bundle.js',
1010
publicPath: '/dist-demo/'
1111
},
12+
resolve: {
13+
alias: {
14+
'react-dom': '@hot-loader/react-dom'
15+
}
16+
},
1217
module: {
1318
rules: [{
1419
test: /\.(js|jsx)$/,

0 commit comments

Comments
 (0)