Skip to content

Commit

Permalink
fix error when import meta in webworker (#1408) (#1896)
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterPanZH authored Dec 11, 2020
1 parent b6339ac commit b944753
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions snowpack/assets/hmr-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,21 @@
* A client-side implementation of the ESM-HMR spec, for reference.
*/

const isWindowDefined = typeof window !== 'undefined';

function log(...args) {
console.log('[ESM-HMR]', ...args);
}
function reload() {
location.reload(true);
isWindowDefined && location.reload(true);
}
/** Clear all error overlays from the page */
function clearErrorOverlay() {
document.querySelectorAll('hmr-error-overlay').forEach((el) => el.remove());
isWindowDefined && document.querySelectorAll('hmr-error-overlay').forEach((el) => el.remove());
}
/** Create an error overlay (if custom element exists on the page). */
function createNewErrorOverlay(data) {
const HmrErrorOverlay = customElements.get('hmr-error-overlay');
const HmrErrorOverlay = isWindowDefined && customElements.get('hmr-error-overlay');
if (HmrErrorOverlay) {
const overlay = new HmrErrorOverlay(data);
clearErrorOverlay();
Expand Down Expand Up @@ -223,7 +225,7 @@ socket.addEventListener('message', ({data: _data}) => {
log('listening for file changes...');

/** Runtime error reporting: If a runtime error occurs, show it in an overlay. */
window.addEventListener('error', function (event) {
isWindowDefined && window.addEventListener('error', function (event) {
// Generate an "error location" string
let fileLoc;
if (event.filename) {
Expand Down

1 comment on commit b944753

@vercel
Copy link

@vercel vercel bot commented on b944753 Dec 11, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.