MCPcopy
hub / github.com/webpack/webpack-dev-server / reloadApp

Function reloadApp

client-src/index.js:288–363  ·  view source on GitHub ↗
({ hot, liveReload }, currentStatus)

Source from the content-addressed store, hash-verified

286 * @param {Status} currentStatus current status
287 */
288const 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} */

Callers 2

okFunction · 0.85
warningsFunction · 0.85

Calls 2

applyReloadFunction · 0.85
infoMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…