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

HRM runtime calls window.location.reload(), breaks in in web worker context #3076

Closed
clintharris opened this issue May 23, 2019 · 0 comments · Fixed by #3078
Closed

HRM runtime calls window.location.reload(), breaks in in web worker context #3076

clintharris opened this issue May 23, 2019 · 0 comments · Fixed by #3078
Labels

Comments

@clintharris
Copy link
Contributor

🐛 bug report

HMR update events are currently causing ReferenceError: window does not exist in browser-targeted apps that use web workers.

This appears to be happening because hrm-runtime.js makes reference to the window global, which doesn't exist in a web worker context:

if (handled) {
  console.clear();

  data.assets.forEach(function (asset) {
    hmrApply(global.parcelRequire, asset);
  });

  assetsToAccept.forEach(function (v) {
    hmrAcceptRun(v[0], v[1]);
  });
} else {
  window.location.reload(); 👈 But window doesn't exist in web worker context! 😭
}

🤔 Expected Behavior

No error should be encountered by web worker code when an HMR update occurs.

😯 Current Behavior

ReferenceError: window does not exist

💻 Code Sample

  1. Clone https://github.com/clintharris/parcel-hrm-bug-demo
  2. npm install && npm start
  3. Load http://localhost:1234, open browser JS console.
  4. Edit src/index.js to trigger HMR update.
  5. JS console error: ReferenceError: window is not defined

🌍 Your Environment

Software Version(s)
Parcel 1.12.3
Node 12.3
npm/Yarn npm 6.4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants