-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Closed as not planned
Closed as not planned
Copy link
Labels
feat: web workersp2-edge-caseBug, but has workaround or limited in scope (priority)Bug, but has workaround or limited in scope (priority)
Description
Describe the bug
When a worker script is initialized like
const worker = new window.SharedWorker(new URL('worker.js', import.meta.url));it will be inlined as base64, which breaks things like WorkerGlobalScope.location inside it during the prod build (but not during dev build, as dev build never inlines). By removing the window, e.g.
const worker = new SharedWorker(new URL('worker.js', import.meta.url));it works again and the script is exempt from inlining as expected. I would expect both variants to work the same way as it's pretty common to feature-detect via window.SharedWorker and then use the same expression when instantiating it:
if (window.SharedWorker) {
new window.SharedWorker(...)
}Specifically this code does not properly check for window, globalThis, or other prefixes that could be used before globals like Worker, SharedWorker or URL.
Reproduction
https://github.com/silverwind/vite-sharedworker
System Info
not relevantUsed Package Manager
npm
Logs
No response
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Make sure this is a Vite issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to vuejs/core instead.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
feat: web workersp2-edge-caseBug, but has workaround or limited in scope (priority)Bug, but has workaround or limited in scope (priority)
Type
Projects
Status
Rejected