parcel icon indicating copy to clipboard operation
parcel copied to clipboard

Parcel HMR reloads all tabs when one is reloaded/closed/navigates

Open foxt opened this issue 1 year ago • 2 comments

See also #9605

🐛 bug report

When using Parcel to develop a web extension, if you have HMR enabled, as soon as one tab unloads (closed/reload/navigation) all the other tabs are reloaded.

🎛 Configuration (.babelrc, package.json, cli command)

{
  "extends": "@parcel/config-webextension"
}

🤔 Expected Behavior

HMR only reloads pages when an actual change is made.

😯 Current Behavior

HMR reloads all pages when any is unloaded

💁 Possible Solution

https://github.com/parcel-bundler/parcel/blob/v2/packages/transformers/webextension/src/runtime/autoreload.js#L5

Seems like it was introduced in #9068

🔦 Context

If you're using an extension that was built in dev mode (with HMR enabled), and trying to use the website that the extension is active on, its annoying that when you close/navigate in one tab, all the others immediately reload. This is quite annoying given the site I'm currently working on an extension for is quite slow to initially load, and would be especially annoying if you were working on an extension that loads on many/all sites.

💻 Code Sample

🌍 Your Environment

Software Version(s)
Parcel 2.13.3
Node 23.7.0
npm/Yarn 10.9.2
Operating System Ubuntu 22.04.5 LTS (WSL2)

foxt avatar Feb 20 '25 09:02 foxt

managed to work around it with

let origAddEventListener = globalThis.addEventListener;
globalThis.addEventListener = (type, listener, options) => {
    if (type == "beforeunload") return;
    origAddEventListener(type, listener, options);
};

i am not sure if this causes any unintended side effects but seems to work for me

foxt avatar Feb 20 '25 09:02 foxt

I'm running into this as well I believe. @101arrowz or @mischnic can you explain more about what this beforeunload listener is doing? I am not quite following the logic here.

snowystinger avatar Jun 17 '25 22:06 snowystinger

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs.

github-actions[bot] avatar Dec 15 '25 00:12 github-actions[bot]