1
1
import React , { Component } from 'react' ;
2
+ import ReactDOM from 'react-dom' ;
2
3
import hoistNonReactStatic from 'hoist-non-react-statics' ;
3
4
import { getComponentDisplayName } from './internal/reactUtils' ;
4
5
import AppContainer from './AppContainer.dev' ;
5
6
import reactHotLoader from './reactHotLoader' ;
6
7
import { isOpened as isModuleOpened , hotModule , getLastModuleOpened } from './global/modules' ;
7
8
import logger from './logger' ;
8
9
import { clearExceptions , logException } from './errorReporter' ;
10
+ import { createQueue } from './utils/runQueue' ;
9
11
10
12
/* eslint-disable camelcase, no-undef */
11
13
const requireIndirect = typeof __webpack_require__ !== 'undefined' ? __webpack_require__ : require ;
@@ -29,22 +31,36 @@ const createHoc = (SourceComponent, TargetComponent) => {
29
31
return TargetComponent ;
30
32
} ;
31
33
34
+ const runInRequireQueue = createQueue ( ) ;
35
+ const runInRenderQueue = createQueue ( cb => {
36
+ if ( ReactDOM . unstable_batchedUpdates ) {
37
+ ReactDOM . unstable_batchedUpdates ( cb ) ;
38
+ } else {
39
+ cb ( ) ;
40
+ }
41
+ } ) ;
42
+
32
43
const makeHotExport = ( sourceModule , moduleId ) => {
33
44
const updateInstances = possibleError => {
34
45
if ( possibleError && possibleError instanceof Error ) {
35
46
console . error ( possibleError ) ;
36
47
return ;
37
48
}
38
49
const module = hotModule ( moduleId ) ;
39
- clearTimeout ( module . updateTimeout ) ;
40
- module . updateTimeout = setTimeout ( ( ) => {
50
+
51
+ // require all modules
52
+ runInRequireQueue ( ( ) => {
41
53
try {
42
54
requireIndirect ( moduleId ) ;
43
55
} catch ( e ) {
44
56
console . error ( 'React-Hot-Loader: error detected while loading' , moduleId ) ;
45
57
console . error ( e ) ;
46
58
}
47
- module . instances . forEach ( inst => inst . forceUpdate ( ) ) ;
59
+ } ) . then ( ( ) => {
60
+ // force flush all updates
61
+ runInRenderQueue ( ( ) => {
62
+ module . instances . forEach ( inst => inst . forceUpdate ( ) ) ;
63
+ } ) ;
48
64
} ) ;
49
65
} ;
50
66
0 commit comments