parcel icon indicating copy to clipboard operation
parcel copied to clipboard

SharedWorkers are not actually shared across tabs

Open krpatter-intc opened this issue 5 months ago • 3 comments

🐛 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

krpatter-intc avatar Aug 27 '24 14:08 krpatter-intc