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

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

Open
foxt opened this issue Feb 20, 2025 · 1 comment
Open

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

foxt opened this issue Feb 20, 2025 · 1 comment

Comments

@foxt
Copy link

foxt commented Feb 20, 2025

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
Copy link
Author

foxt commented Feb 20, 2025

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant