Skip to content

Commit

Permalink
Fixed envs without location global
Browse files Browse the repository at this point in the history
  • Loading branch information
KrysKruk committed Jul 8, 2019
1 parent 352ac07 commit 646db05
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions src/builtins/hmr-runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,16 @@ if (typeof WebSocket === 'undefined') {

var parent = module.bundle.parent;
if ((!parent || !parent.isParcelRequire) && typeof WebSocket !== 'undefined') {
var hostname = process.env.HMR_HOSTNAME || location.hostname;
var protocol = location.protocol === 'https:' ? 'wss' : 'ws';
var hostname = process.env.HMR_HOSTNAME;
var protocol = 'ws';
if (typeof location !== 'undefined') {
if (!hostname) {
hostname = location.hostname;
}
if (location.protocol === 'https:') {
protocol = 'wss';
}
}
var ws = new WebSocket(protocol + '://' + hostname + ':' + process.env.HMR_PORT + '/');
ws.onmessage = function(event) {
checkedAssets = {};
Expand Down Expand Up @@ -66,14 +74,22 @@ if ((!parent || !parent.isParcelRequire) && typeof WebSocket !== 'undefined') {
hmrAcceptRun(v[0], v[1]);
});
} else {
window.location.reload();
if (typeof location === 'object') {
location.reload();
} else {
console.log('[parcel] Reload needed');
}
}
}

if (data.type === 'reload') {
ws.close();
ws.onclose = function () {
location.reload();
if (typeof location === 'object') {
location.reload();
} else {
console.log('[parcel] Reload needed');
}
}
}

Expand Down

0 comments on commit 646db05

Please sign in to comment.