POC Use WebWorker for reliable timers #1450
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Internal ref: OKTA-637345
Notes:
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)
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 withimport timerWorker from '../workers/TimerWorker.worker';
with webpack/rollup plugins, except CJS bundle used for Nodejs and built just with babel clinew Worker(...)
should be sync, not async.worker-src: blob:
can be unsecure. Need to add an alternative to use worker from file. Like it's done in DataDog,