33import hotEmitter from "webpack/hot/emitter.js" ;
44import { log } from "./log.js" ;
55
6- function reloadApp ( { hot, liveReload } , { isUnloading , currentHash } ) {
7- if ( isUnloading ) {
6+ function reloadApp ( { hot, liveReload } , status ) {
7+ if ( status . isUnloading ) {
88 return ;
99 }
1010
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 ;
1219
1320 if ( isInitial ) {
21+ const isLegacyInitial =
22+ webpackHash === "" && hot === false && liveReload === true ;
23+
24+ if ( isLegacyInitial ) {
25+ status . previousHash = status . currentHash ;
26+ }
27+
1428 return ;
1529 }
1630
@@ -30,11 +44,11 @@ function reloadApp({ hot, liveReload }, { isUnloading, currentHash }) {
3044 if ( hot && allowToHot ) {
3145 log . info ( "App hot update..." ) ;
3246
33- hotEmitter . emit ( "webpackHotUpdate" , currentHash ) ;
47+ hotEmitter . emit ( "webpackHotUpdate" , status . currentHash ) ;
3448
3549 if ( typeof self !== "undefined" && self . window ) {
3650 // broadcast update to window
37- self . postMessage ( `webpackHotUpdate${ currentHash } ` , "*" ) ;
51+ self . postMessage ( `webpackHotUpdate${ status . currentHash } ` , "*" ) ;
3852 }
3953 }
4054 // allow refreshing the page only if liveReload isn't disabled
0 commit comments