Skip to content

Commit

Permalink
Make client worker safe
Browse files Browse the repository at this point in the history
  • Loading branch information
marvinhagemeister committed Sep 2, 2021
1 parent c347dda commit 5f89737
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/wmr/src/lib/plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export function getPlugins(options) {
// Nested workers are not supported at the moment
!isWorker && workerPlugin(options),
htmPlugin({ production, sourcemap: options.sourcemap }),
!isWorker && wmrPlugin({ hot: !production, sourcemap: options.sourcemap }),
wmrPlugin({ hot: !production, sourcemap: options.sourcemap }),
fastCjsPlugin({
// Only transpile CommonJS in node_modules and explicit .cjs files:
include: /(^npm\/|[/\\]node_modules[/\\]|\.cjs$)/
Expand Down
9 changes: 7 additions & 2 deletions packages/wmr/src/plugins/wmr/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ function handleMessage(e) {
const data = JSON.parse(e.data);
switch (data.type) {
case 'reload':
location.reload();
if (HAS_DOM) {
location.reload();
}
break;
case 'update':
if (errorOverlay) {
Expand All @@ -64,7 +66,10 @@ function handleMessage(e) {
return;
}
} else if (url.replace(URL_SUFFIX, '') === resolve(location.pathname).replace(URL_SUFFIX, '')) {
return location.reload();
if (HAS_DOM) {
location.reload();
}
return;
} else {
if (!HAS_DOM) return;
for (const el of document.querySelectorAll('[src],[href]')) {
Expand Down

0 comments on commit 5f89737

Please sign in to comment.