3
3
import hotEmitter from "webpack/hot/emitter.js" ;
4
4
import { log } from "./log.js" ;
5
5
6
- function reloadApp ( { hot, liveReload } , { isUnloading , currentHash } ) {
7
- if ( isUnloading ) {
6
+ function reloadApp ( { hot, liveReload } , status ) {
7
+ if ( status . isUnloading ) {
8
8
return ;
9
9
}
10
10
11
- const isInitial = currentHash . indexOf ( __webpack_hash__ ) === 0 ;
11
+ // TODO Workaround for webpack v4, `__webpack_hash__` is not replaced without HotModuleReplacement plugin
12
+ const webpackHash =
13
+ // eslint-disable-next-line camelcase
14
+ typeof __webpack_hash__ !== "undefined"
15
+ ? // eslint-disable-next-line camelcase
16
+ __webpack_hash__
17
+ : status . previousHash || "" ;
18
+ const isInitial = status . currentHash . indexOf ( webpackHash ) === 0 ;
12
19
13
20
if ( isInitial ) {
21
+ const isLegacyInitial =
22
+ webpackHash === "" && hot === false && liveReload === true ;
23
+
24
+ if ( isLegacyInitial ) {
25
+ status . previousHash = status . currentHash ;
26
+ }
27
+
14
28
return ;
15
29
}
16
30
@@ -30,11 +44,11 @@ function reloadApp({ hot, liveReload }, { isUnloading, currentHash }) {
30
44
if ( hot && allowToHot ) {
31
45
log . info ( "App hot update..." ) ;
32
46
33
- hotEmitter . emit ( "webpackHotUpdate" , currentHash ) ;
47
+ hotEmitter . emit ( "webpackHotUpdate" , status . currentHash ) ;
34
48
35
49
if ( typeof self !== "undefined" && self . window ) {
36
50
// broadcast update to window
37
- self . postMessage ( `webpackHotUpdate${ currentHash } ` , "*" ) ;
51
+ self . postMessage ( `webpackHotUpdate${ status . currentHash } ` , "*" ) ;
38
52
}
39
53
}
40
54
// allow refreshing the page only if liveReload isn't disabled
0 commit comments