1
1
const log = console ;
2
- const refresh = 'Please refresh the page .' ;
2
+ const refresh = 'Please restart the application .' ;
3
3
const hotOptions = {
4
4
ignoreUnaccepted : true ,
5
5
ignoreDeclined : true ,
@@ -73,7 +73,7 @@ function check(options) {
73
73
. then ( ( modules ) => {
74
74
if ( ! modules ) {
75
75
log . warn (
76
- `Cannot find update. The server may have been restarted. ${ refresh } `
76
+ `Cannot find update. ${ refresh } `
77
77
) ;
78
78
return null ;
79
79
}
@@ -82,8 +82,7 @@ function check(options) {
82
82
. apply ( hotOptions )
83
83
. then ( ( appliedModules ) => {
84
84
if ( ! upToDate ( ) ) {
85
- log . warn ( "Hashes don't match. Ignoring second update..." ) ;
86
- // check(options);
85
+ check ( options ) ;
87
86
}
88
87
89
88
result ( modules , appliedModules ) ;
@@ -122,7 +121,7 @@ if (module.hot) {
122
121
console . error ( 'Hot Module Replacement is disabled.' ) ;
123
122
}
124
123
125
- module . exports = function update ( currentHash , options ) {
124
+ function update ( currentHash , options ) {
126
125
lastHash = currentHash ;
127
126
if ( ! upToDate ( ) ) {
128
127
const status = module . hot . status ( ) ;
@@ -138,3 +137,24 @@ module.exports = function update(currentHash, options) {
138
137
}
139
138
} ;
140
139
140
+ function getCurrentHash ( currentHash , getFileContent ) {
141
+ const file = getFileContent ( `${ currentHash } .hot-update.json` ) ;
142
+ return file . readText ( ) . then ( hotUpdateContent => {
143
+ if ( hotUpdateContent ) {
144
+ const manifest = JSON . parse ( hotUpdateContent ) ;
145
+ const newHash = manifest . h ;
146
+ return getCurrentHash ( newHash , getFileContent ) ;
147
+ } else {
148
+ return Promise . resolve ( currentHash ) ;
149
+ }
150
+ } ) . catch ( error => Promise . reject ( error ) ) ;
151
+ }
152
+
153
+ module . exports = function checkState ( initialHash , getFileContent ) {
154
+ getCurrentHash ( initialHash , getFileContent ) . then ( currentHash => {
155
+ if ( currentHash != initialHash ) {
156
+ update ( currentHash , { } ) ;
157
+ }
158
+ } )
159
+ }
160
+
0 commit comments