@@ -40,37 +40,47 @@ if (__DEBUG__) {
40
40
// ========================================================
41
41
const MOUNT_NODE = document . getElementById ( 'root' )
42
42
43
- let render = ( routerKey = null ) => {
43
+ let render = ( ) => {
44
44
const routes = require ( './routes/index' ) . default ( store )
45
45
46
46
ReactDOM . render (
47
47
< AppContainer
48
48
store = { store }
49
49
history = { history }
50
50
routes = { routes }
51
- routerKey = { routerKey }
52
51
/> ,
53
52
MOUNT_NODE
54
53
)
55
54
}
56
55
57
- // Enable HMR and catch runtime errors in RedBox
58
56
// This code is excluded from production bundle
59
- if ( __DEV__ && module . hot ) {
60
- const renderApp = render
61
- const renderError = ( error ) => {
62
- const RedBox = require ( 'redbox-react' ) . default
57
+ if ( __DEV__ ) {
58
+ if ( module . hot ) {
59
+ // Development render functions
60
+ const renderApp = render
61
+ const renderError = ( error ) => {
62
+ const RedBox = require ( 'redbox-react' ) . default
63
63
64
- ReactDOM . render ( < RedBox error = { error } /> , MOUNT_NODE )
65
- }
66
- render = ( ) => {
67
- try {
68
- renderApp ( Math . random ( ) )
69
- } catch ( error ) {
70
- renderError ( error )
64
+ ReactDOM . render ( < RedBox error = { error } /> , MOUNT_NODE )
65
+ }
66
+
67
+ // Wrap render in try/catch
68
+ render = ( ) => {
69
+ try {
70
+ renderApp ( )
71
+ } catch ( error ) {
72
+ renderError ( error )
73
+ }
71
74
}
75
+
76
+ // Setup hot module replacement
77
+ module . hot . accept ( './routes/index' , ( ) => {
78
+ setTimeout ( ( ) => {
79
+ ReactDOM . unmountComponentAtNode ( MOUNT_NODE )
80
+ render ( )
81
+ } )
82
+ } )
72
83
}
73
- module . hot . accept ( [ './routes/index' ] , ( ) => render ( ) )
74
84
}
75
85
76
86
// ========================================================
0 commit comments