You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was using vanilla web workers just fine using app directory.
hook.ts
constworker=React.useMemo(()=>newWorker(newURL('main.worker',import.meta.url)),[]);worker.onmessage=(event: MessageEvent<Data>)=>{setLoading(false);// Handle data after worker completes};worker.onerror=(event)=>{setLoading(false);// Handle errorconsole.error('Error event occurred in sorting worker',event);throwevent;};consttriggerCalc=()=>{worker.postMessage(workerMessageOpts);setLoading(true);};React.useEffect(()=>{triggerCalc();},triggeringDeps);React.useEffect(()=>{return()=>worker.terminate();},[]);
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Summary
I was using vanilla web workers just fine using app directory.
hook.ts
main.worker.ts
However, after the changes that seems introduced in
v13.5related to<Script strategy="worker" />and https://nextjs.org/docs/app/building-your-application/optimizing/scripts#offloading-scripts-to-a-web-worker-experimental, the above implementation doesn't work anymore.From what I can see,
triggerCalc()is executed, butonMessagein the worker is not ran/caught/triggered.Additional information
No response
Example
No response
All reactions