Skip to content

Improve worker build for replays #6371

Closed
@mydea

Description

@mydea

Currently, the web worker for replay is built via yarn build:worker. This builds the worker script and stores it as a string in src/worker.js, which is then actually used.

While this works, it has some downsides:

  1. Since this is built & checked in, it is possible to have a different version of this locally/on CI/when building.
  2. You need to remember to run this every now and then locally & check the generated file in (if it changed)
  3. It is not ideal to have a two-step build process inside of replay (this is a bit custom and requires a bunch of custom/duplicate build stuff in there).

Some notes on what doesn't work

Sadly, just using something like https://github.com/darionco/rollup-plugin-web-worker-loader does not work as easily as expected.
While it is possible to get it to work, jest & jsdom do not like this. Basically, jsdom-worker only works with string-based workers, not with an actual js file reference. And it's also not really possible to do something like fs.readFileSync('worker.js') as that would not include all the dependencies etc.

Proposed solution

After some experimentation, we believe the best approach is to move the worker into a private sub-package, e.g. @sentry/replay-compression-worker. This package would build the worker into a single worker.js file, similar to what we have now, but:

  1. in a standalone package
  2. In a .js file, not a string

Then, replay can depend on this (and internally inline it at build time), and we can make it work with rollup-plugin-web-worker-loader (because there exists a fully built file that we can read from disk & inline).

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions