11import React , { Component } from 'react' ;
2+ import ReactDOM from 'react-dom' ;
23import hoistNonReactStatic from 'hoist-non-react-statics' ;
34import { getComponentDisplayName } from './internal/reactUtils' ;
45import AppContainer from './AppContainer.dev' ;
56import reactHotLoader from './reactHotLoader' ;
67import { isOpened as isModuleOpened , hotModule , getLastModuleOpened } from './global/modules' ;
78import logger from './logger' ;
89import { clearExceptions , logException } from './errorReporter' ;
10+ import { createQueue } from './utils/runQueue' ;
911
1012/* eslint-disable camelcase, no-undef */
1113const requireIndirect = typeof __webpack_require__ !== 'undefined' ? __webpack_require__ : require ;
@@ -29,22 +31,36 @@ const createHoc = (SourceComponent, TargetComponent) => {
2931 return TargetComponent ;
3032} ;
3133
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+
3243const makeHotExport = ( sourceModule , moduleId ) => {
3344 const updateInstances = possibleError => {
3445 if ( possibleError && possibleError instanceof Error ) {
3546 console . error ( possibleError ) ;
3647 return ;
3748 }
3849 const module = hotModule ( moduleId ) ;
39- clearTimeout ( module . updateTimeout ) ;
40- module . updateTimeout = setTimeout ( ( ) => {
50+
51+ // require all modules
52+ runInRequireQueue ( ( ) => {
4153 try {
4254 requireIndirect ( moduleId ) ;
4355 } catch ( e ) {
4456 console . error ( 'React-Hot-Loader: error detected while loading' , moduleId ) ;
4557 console . error ( e ) ;
4658 }
47- module . instances . forEach ( inst => inst . forceUpdate ( ) ) ;
59+ } ) . then ( ( ) => {
60+ // force flush all updates
61+ runInRenderQueue ( ( ) => {
62+ module . instances . forEach ( inst => inst . forceUpdate ( ) ) ;
63+ } ) ;
4864 } ) ;
4965 } ;
5066
0 commit comments