Buffer connect events in ESM worker bootstrap to fix SharedWorker race
The async `await Promise.all(...)` in the ESM bootstrap creates a task
checkpoint where the browser event loop can dispatch `connect` events
before the user module has registered its `addEventListener('connect', ...)`
handler. For SharedWorkers, this causes the connect event to be silently
dropped.
Fix by buffering connect events synchronously before the await, then
replaying them after initialization completes. The SharedWorkerGlobalScope
check is runtime-only so regular Workers are unaffected.
Also removes the unnecessary foreign-origin check in the import map callback
(the chunks are always same-origin, and import() enforces CORS itself).
Co-Authored-By:
Claude <noreply@anthropic.com>
Showing
Please
register
or
sign in
to comment