Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

POC Use WebWorker for reliable timers #1450

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

denysoblohin-okta
Copy link
Contributor

@denysoblohin-okta denysoblohin-okta commented Aug 29, 2023

Internal ref: OKTA-637345

Notes:

  • There are 2 approaches to load worker code - inline and from separate file
  • For libraries better approach would be to choose inline workers.
    Otherwise developer should care of hosting separate files for workers and building those files with bundler chosen by developer which may vary (webpack/rollup/vite etc)
  • Building library with inline worker is a bit tricky.
    Trick for rollup is to build worker code to separate file and stringify with renderChunk: https://github.com/okta/okta-auth-js/pull/1450/files#diff-6814bf77564b4f1c92f5861e184e28fe217c080a047fefa8b73a728f755ec45cR104-R109 . Same approach used in Sentry's replay-worker and described in article.
    For webpack5 new approach does not support creating inline worker, so using worker-loader designed for webpack 4.
    Also as Worker creating approaches are different for webpack and rollup, need to handle this at runtime with global var like BUNDLER.
    Last trick: this line import timerWorker from '../workers/TimerWorker.emptyWorker'; will be replaced with import timerWorker from '../workers/TimerWorker.worker'; with webpack/rollup plugins, except CJS bundle used for Nodejs and built just with babel cli
  • Worker inline source should be pretranspiled with Babel to work on IE11
  • For testing with Jest using jsdom-worker with fixes, see fork. Fix: Loading worker and executing it code with new Worker(...) should be sync, not async.
  • ! Adding CSP worker-src: blob: can be unsecure. Need to add an alternative to use worker from file. Like it's done in DataDog,

@denysoblohin-okta denysoblohin-okta marked this pull request as ready for review August 31, 2023 16:59
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.

1 participant