Skip to content

Commit

Permalink
Do not use window global in HMR runtime (#529)
Browse files Browse the repository at this point in the history
The name of the global object may differ based on the context in which the
script is running. For example, web workers use "self" instead of "window". As
location is a property of the global, it can be referenced directly as a global
variable, which avoids having to deal with this naming inconsistency.

Fixes #528
  • Loading branch information
bwrrp authored and devongovett committed Jan 14, 2018
1 parent bd9fd9f commit 6962a9a
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/builtins/hmr-runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function Module() {
module.bundle.Module = Module;

if (!module.bundle.parent && typeof WebSocket !== 'undefined') {
var ws = new WebSocket('ws://' + window.location.hostname + ':{{HMR_PORT}}/');
var ws = new WebSocket('ws://' + location.hostname + ':{{HMR_PORT}}/');
ws.onmessage = function(event) {
var data = JSON.parse(event.data);

Expand All @@ -34,7 +34,7 @@ if (!module.bundle.parent && typeof WebSocket !== 'undefined') {
if (data.type === 'reload') {
ws.close();
ws.onclose = function () {
window.location.reload();
location.reload();
}
}

Expand Down

0 comments on commit 6962a9a

Please sign in to comment.