stencil icon indicating copy to clipboard operation
stencil copied to clipboard

fix(compiler): try to create web worker with the workerPath before falling back to blob

Open jeski-bright opened this issue 3 years ago • 0 comments

Pull request checklist

Please check if your PR fulfills the following requirements:

  • [ ] Tests for the changes have been added (for bug fixes / features)
  • [ ] Docs have been reviewed and added / updated if needed (for bug fixes / features)
  • [x] Build (npm run build) was run locally and any changes were pushed
  • [x] Unit tests (npm test) were run locally and passed
  • [x] E2E Tests (npm run test.karma.prod) were run locally and passed
  • [x] Prettier (npm run prettier) was run locally and passed

Pull request type

Please check the type of change your PR introduces:

  • [x] Bugfix
  • [ ] Feature
  • [ ] Refactoring (no functional changes, no api changes)
  • [ ] Build related changes
  • [ ] Documentation content changes
  • [ ] Other (please describe):

What is the current behavior?

GitHub Issue Number: #3512

Currently the worker plugin creates the Web Worker by first creating a blob of a script which loads the actual script via importScripts. However the path to the script is calculated via new URL(<file_name>, import.meta.url), which generates a relative path for some frameworks (as Nextjs mentioned in the issue). I would expect most SSR frameworks to do this to avoid mismatches between the server and client. The importScripts method fails on loading a relative path however.

What is the new behavior?

Before loading the worker in the current way, try to create it with the resolved script path directly. In case of error, fall back to the current implementation. This is in line with src/compiler/sys/worker/web-worker-main.ts

Does this introduce a breaking change?

  • [ ] Yes
  • [x] No

Testing

Clone the reproduction repo from the issue & apply this patch to stencil. The web worker should start now.

Other information

jeski-bright avatar Aug 05 '22 13:08 jeski-bright