-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
Fix pthread worker options usage with Vite bundler #22834
base: main
Are you sure you want to change the base?
Fix pthread worker options usage with Vite bundler #22834
Conversation
src/library_pthread.js
Outdated
@@ -426,14 +407,14 @@ var LibraryPThread = { | |||
createScriptURL: (ignored) => new URL("{{{ TARGET_JS_NAME }}}", import.meta.url) | |||
} | |||
); | |||
worker = new Worker(p.createScriptURL('ignored'), workerOptions); | |||
worker = new Worker(p.createScriptURL('ignored'), {{{ WORKER_OPTIONS }}}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I simpler way to do this would be to define a new macro here at the top of this file. e.g.
{{{
globalThis.WORKER_OPTIONS = {
...
};
null;
}}}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you so much! I wasn't too sure how the templating works in these files 😅 . I'll update the PR with this approach when I get a chance.
Edit: I do wonder if we can work with Vite to allow dynamic values and only require the worker Edit 2: Proposed changes to Vite are likely to be accepted that would allow us support dynamic name fields (See: vitejs/vite#19010). I'll update this merge request with this in mind. |
Overview
An attempt at solving #22394.
When code using threads is compiled with Emscripten and then bundled with Vite it does not bundle and throws an error.
This is due to a variable reference for worker options being used during worker construction. Vite needs static worker options to bundle the code successfully.
As discussed in the issue, the easiest solution would be to switch to using an object literal for each worker construction.