Next.js Discord

Discord Forum

Managing shared workers and their versions in the NextJS app

Unanswered
Barbary Lion posted this in #help-forum
Open in Discord
Barbary LionOP
Hello there! Has anyone used shared workers with the next app? I am currently working on a project in the next 12.0.3. We are using a shared worker to do some heavy computation, to be shared across all the tabs/windows of the browser instance. I create the shared worker using new SharedWorker(new URL('/util/calc.worker.js', import.meta.url))
I am facing an issue here. After each build with updates on the worker script, NextJS creates a new chunk filename for the worker script. Any new tab that opens the app thereafter connects to the new shared worker instance. This is causing an issue for me since the browser tab/window which was open before the latest build connects to an old worker script and the the latest tab connects to the new worker script. How can I manage this? Has anyone faced this issue before?

0 Replies