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

SharedWorkers are not actually shared across tabs #9931

Open
krpatter-intc opened this issue Aug 27, 2024 · 3 comments
Open

SharedWorkers are not actually shared across tabs #9931

krpatter-intc opened this issue Aug 27, 2024 · 3 comments
Labels

Comments

@krpatter-intc
Copy link

🐛 bug report

SharedWorkers do not work. The code below appears to work in the fact that you get a worker, but parcel's adding of ?<timestamp> prevents multiple tabs from getting the same worker.

this.worker = new SharedWorker(new URL("worker.ts", import.meta.url), {type: "module"})

I can't find anyway to make this code not add the ?<timestamp> during the fetch.

The docs explicitly mention that SharedWorker is supported, but there's no recipe given like the other workers, so I suspect maybe this wasn't tested with multiple tabs (since it does appear to work like the new Worker code).

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

CLI:

start": "parcel serve src/demo-app/index.html --dist-dir build

🤔 Expected Behavior

The ?timestamp can't be added for sharedworkers so that each web page gets the same worker

😯 Current Behavior

Each tab gets a new worker. This can be seen using: chrome://inspect/#workers to view the workers when new tabs are open.

💁 Possible Solution

...

🔦 Context

Trying to use SharedWorkers in a web app to help communicate data amongst multiple tabs.

💻 Code Sample

🌍 Your Environment

Software Version(s)
Parcel 2.12.0
Node 10.8.2
npm/Yarn
Operating System Windows
@devongovett
Copy link
Member

That's added here:

if (options.hmrOptions) {
res += ' + "?" + Date.now()';
}

Perhaps SharedWorkers could be detected and skip this

@krpatter-intc
Copy link
Author

I searched through the docs, but didn't see a way to disable HMR as a workaround for now.

@krpatter-intc
Copy link
Author

krpatter-intc commented Aug 27, 2024

Searching the code I found the --no-hmr parameter after your hint (thanks!), and I can confirm that running with --no-hmr works

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

No branches or pull requests

2 participants