Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Server): disable page reload when hot is not specified (options.hot) #1276

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 18 additions & 14 deletions client-src/default/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ if (!urlParts.port || urlParts.port === '0') {
}

let hot = false;
let hotOnly = false;
let initial = true;
let currentHash = '';
let useWarningOverlay = false;
Expand Down Expand Up @@ -72,8 +73,9 @@ function sendMsg(type, data) {
}

const onSocketMsg = {
hot() {
hot(isHotOnly) {
hot = true;
hotOnly = isHotOnly;
log.info('[WDS] Hot Module Replacement enabled.');
},
invalid() {
Expand Down Expand Up @@ -217,21 +219,23 @@ function reloadApp() {
// broadcast update to window
self.postMessage(`webpackHotUpdate${currentHash}`, '*');
}
} else {
let rootWindow = self;
// use parent window for reload (in case we're in an iframe with no valid src)
const intervalId = self.setInterval(() => {
if (rootWindow.location.protocol !== 'about:') {
// reload immediately if protocol is valid
applyReload(rootWindow, intervalId);
} else {
rootWindow = rootWindow.parent;
if (rootWindow.parent === rootWindow) {
// if parent equals current window we've reached the root which would continue forever, so trigger a reload anyways

if (!hotOnly) {
let rootWindow = self;
// use parent window for reload (in case we're in an iframe with no valid src)
const intervalId = self.setInterval(() => {
if (rootWindow.location.protocol !== 'about:') {
// reload immediately if protocol is valid
applyReload(rootWindow, intervalId);
} else {
rootWindow = rootWindow.parent;
if (rootWindow.parent === rootWindow) {
// if parent equals current window we've reached the root which would continue forever, so trigger a reload anyways
applyReload(rootWindow, intervalId);
}
}
}
});
});
}
}

function applyReload(rootWindow, intervalId) {
Expand Down
5 changes: 3 additions & 2 deletions lib/Server.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ function Server(compiler, options) {
throw new Error("'filename' option must be set in lazy mode.");
}

this.hot = options.hot || options.hotOnly;
this.hot = options.hot;
this.hotOnly = options.hotOnly;
this.headers = options.headers;
this.clientLogLevel = options.clientLogLevel;
this.clientOverlay = options.overlay;
Expand Down Expand Up @@ -601,7 +602,7 @@ Server.prototype.listen = function (port, hostname, fn) {

if (this.clientOverlay) { this.sockWrite([conn], 'overlay', this.clientOverlay); }

if (this.hot) this.sockWrite([conn], 'hot');
if (this.hot || this.hotOnly) { this.sockWrite([conn], 'hot', this.hotOnly); }

if (!this._stats) return;
this._sendStats([conn], this._stats.toJson(clientStats), true);
Expand Down