({ hot, liveReload }, currentStatus)
| 286 | * @param {Status} currentStatus current status |
| 287 | */ |
| 288 | const reloadApp = ({ hot, liveReload }, currentStatus) => { |
| 289 | if (currentStatus.isUnloading) { |
| 290 | return; |
| 291 | } |
| 292 | |
| 293 | const { currentHash, previousHash } = currentStatus; |
| 294 | const isInitial = |
| 295 | currentHash.indexOf(/** @type {string} */ (previousHash)) >= 0; |
| 296 | |
| 297 | if (isInitial) { |
| 298 | return; |
| 299 | } |
| 300 | |
| 301 | /** |
| 302 | * @param {Window} rootWindow root window |
| 303 | * @param {number} intervalId interval id |
| 304 | */ |
| 305 | function applyReload(rootWindow, intervalId) { |
| 306 | clearInterval(intervalId); |
| 307 | |
| 308 | log.info("App updated. Reloading..."); |
| 309 | |
| 310 | rootWindow.location.reload(); |
| 311 | } |
| 312 | |
| 313 | const search = self.location.search.toLowerCase(); |
| 314 | const allowToHot = search.indexOf("webpack-dev-server-hot=false") === -1; |
| 315 | const allowToLiveReload = |
| 316 | search.indexOf("webpack-dev-server-live-reload=false") === -1; |
| 317 | |
| 318 | if (hot && allowToHot) { |
| 319 | log.info("App hot update..."); |
| 320 | |
| 321 | if ( |
| 322 | typeof EventTarget !== "undefined" && |
| 323 | hotEmitter instanceof EventTarget |
| 324 | ) { |
| 325 | const event = new CustomEvent("webpackHotUpdate", { |
| 326 | detail: { |
| 327 | currentHash: currentStatus.currentHash, |
| 328 | }, |
| 329 | bubbles: true, |
| 330 | cancelable: false, |
| 331 | }); |
| 332 | |
| 333 | hotEmitter.dispatchEvent(event); |
| 334 | } else { |
| 335 | hotEmitter.emit("webpackHotUpdate", currentStatus.currentHash); |
| 336 | } |
| 337 | |
| 338 | if (typeof self !== "undefined" && self.window) { |
| 339 | // broadcast update to window |
| 340 | self.postMessage(`webpackHotUpdate${currentStatus.currentHash}`, "*"); |
| 341 | } |
| 342 | } |
| 343 | // allow refreshing the page only if liveReload isn't disabled |
| 344 | else if (liveReload && allowToLiveReload) { |
| 345 | /** @type {Window} */ |
no test coverage detected
searching dependent graphs…