Skip to content

fix: Allow Workers to be instantiated directly via callback#206

Merged
Jarbuckle merged 1 commit intomainfrom
joel/fix-worker-instantiation
Oct 15, 2025
Merged

fix: Allow Workers to be instantiated directly via callback#206
Jarbuckle merged 1 commit intomainfrom
joel/fix-worker-instantiation

Conversation

@Jarbuckle
Copy link
Contributor

fix: Allow Workers to be instantiated directly via callback

What

When testing out Worker Pools in production builds, the Workers were not being instantiated as expected because the build system (Vite, in this case) was treating the imported worker modules as the video/mp2t MIME type. After some digging, this was apparently due to the Vite bundler expecting a worker instantiation to be done in a very specific (and not particularly flexible) way.

However, Vite did offer an alternative that gave a clue: a worker module could be imported with ?worker at the end of the filename to import it instead as a constructor that could be called, and the docs hinted at the possibility that this could then be used in contexts where the URL of the worker wasn't known.

Taking this idea one step further, this PR makes it so that the Worker Pool can accept either a URL (possibly only a temporary thing, since it may never work...) OR a Worker instantiation callback. This was tested using Vite's worker constructor within the callback, and it worked within production builds as well as locally.

How

  • Replace the URL parameter to Worker Pool instantiation with a WorkerInit object, which can be either a URL or a WorkerInstantiationCallback. A WorkerInstantiationCallback is an parameter-less function that returns a Worker.

PR Checklist

  • Is your PR title following our conventional commit naming recommendations?
  • Have you filled in the PR Description Template?
  • Is your branch up to date with the latest in main?
  • Do the CI checks pass successfully?
  • Have you smoke tested the example applications?
  • Did you check that the changes meet accessibility standards?
  • Have you tested the application on these browsers?
    • Chrome (Fully supported)
    • Firefox (Major bug fixes supported)
    • Safari (Major bug fixes supported)

@Jarbuckle Jarbuckle requested a review from a team as a code owner October 15, 2025 16:10
@Jarbuckle Jarbuckle requested review from froyo-np and suyli7 October 15, 2025 16:10
@Jarbuckle Jarbuckle merged commit 499ef99 into main Oct 15, 2025
5 checks passed
@Jarbuckle Jarbuckle deleted the joel/fix-worker-instantiation branch October 15, 2025 16:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants