|  | 
| 1 | 1 | /* global __resourceQuery, __webpack_hash__ */ | 
| 2 | 2 | /// <reference types="webpack/module" /> | 
| 3 | 3 | import webpackHotLog from "webpack/hot/log.js"; | 
|  | 4 | +import hotEmitter from "webpack/hot/emitter.js"; | 
| 4 | 5 | import socket from "./socket.js"; | 
| 5 | 6 | import { formatProblem, createOverlay } from "./overlay.js"; | 
| 6 | 7 | import { log, setLogLevel } from "./utils/log.js"; | 
| 7 | 8 | import sendMessage from "./utils/sendMessage.js"; | 
| 8 |  | -import reloadApp from "./utils/reloadApp.js"; | 
| 9 | 9 | import { isProgressSupported, defineProgressElement } from "./progress.js"; | 
| 10 | 10 | 
 | 
| 11 | 11 | /** | 
| @@ -249,6 +249,71 @@ const overlay = | 
| 249 | 249 |       ) | 
| 250 | 250 |     : { send: () => {} }; | 
| 251 | 251 | 
 | 
|  | 252 | +/** | 
|  | 253 | + * @param {Options} options | 
|  | 254 | + * @param {Status} currentStatus | 
|  | 255 | + */ | 
|  | 256 | +const reloadApp = ({ hot, liveReload }, currentStatus) => { | 
|  | 257 | +  if (currentStatus.isUnloading) { | 
|  | 258 | +    return; | 
|  | 259 | +  } | 
|  | 260 | + | 
|  | 261 | +  const { currentHash, previousHash } = currentStatus; | 
|  | 262 | +  const isInitial = | 
|  | 263 | +    currentHash.indexOf(/** @type {string} */ (previousHash)) >= 0; | 
|  | 264 | + | 
|  | 265 | +  if (isInitial) { | 
|  | 266 | +    return; | 
|  | 267 | +  } | 
|  | 268 | + | 
|  | 269 | +  /** | 
|  | 270 | +   * @param {Window} rootWindow | 
|  | 271 | +   * @param {number} intervalId | 
|  | 272 | +   */ | 
|  | 273 | +  function applyReload(rootWindow, intervalId) { | 
|  | 274 | +    clearInterval(intervalId); | 
|  | 275 | + | 
|  | 276 | +    log.info("App updated. Reloading..."); | 
|  | 277 | + | 
|  | 278 | +    rootWindow.location.reload(); | 
|  | 279 | +  } | 
|  | 280 | + | 
|  | 281 | +  const search = self.location.search.toLowerCase(); | 
|  | 282 | +  const allowToHot = search.indexOf("webpack-dev-server-hot=false") === -1; | 
|  | 283 | +  const allowToLiveReload = | 
|  | 284 | +    search.indexOf("webpack-dev-server-live-reload=false") === -1; | 
|  | 285 | + | 
|  | 286 | +  if (hot && allowToHot) { | 
|  | 287 | +    log.info("App hot update..."); | 
|  | 288 | + | 
|  | 289 | +    hotEmitter.emit("webpackHotUpdate", currentStatus.currentHash); | 
|  | 290 | + | 
|  | 291 | +    if (typeof self !== "undefined" && self.window) { | 
|  | 292 | +      // broadcast update to window | 
|  | 293 | +      self.postMessage(`webpackHotUpdate${currentStatus.currentHash}`, "*"); | 
|  | 294 | +    } | 
|  | 295 | +  } | 
|  | 296 | +  // allow refreshing the page only if liveReload isn't disabled | 
|  | 297 | +  else if (liveReload && allowToLiveReload) { | 
|  | 298 | +    let rootWindow = self; | 
|  | 299 | + | 
|  | 300 | +    // use parent window for reload (in case we're in an iframe with no valid src) | 
|  | 301 | +    const intervalId = self.setInterval(() => { | 
|  | 302 | +      if (rootWindow.location.protocol !== "about:") { | 
|  | 303 | +        // reload immediately if protocol is valid | 
|  | 304 | +        applyReload(rootWindow, intervalId); | 
|  | 305 | +      } else { | 
|  | 306 | +        rootWindow = rootWindow.parent; | 
|  | 307 | + | 
|  | 308 | +        if (rootWindow.parent === rootWindow) { | 
|  | 309 | +          // if parent equals current window we've reached the root which would continue forever, so trigger a reload anyways | 
|  | 310 | +          applyReload(rootWindow, intervalId); | 
|  | 311 | +        } | 
|  | 312 | +      } | 
|  | 313 | +    }); | 
|  | 314 | +  } | 
|  | 315 | +}; | 
|  | 316 | + | 
| 252 | 317 | const ansiRegex = new RegExp( | 
| 253 | 318 |   [ | 
| 254 | 319 |     "[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)", | 
|  | 
0 commit comments