Description
Overview 1 - dotlottie-react workerOptions
After testing various lottie animations for the web during this month, I decided to try different player options to see the pros and cons between them. I ended up running into dotlottie-web
and the web worker feature (which prevents CPU overload), tested the worker in crhome/opera/edge (crhomiun based browsers) and firefox, and it works well. CPU looks pretty well!
NOTE: Altough I am using React^19.0.0 I decided to use dotlottie-web
instead of dotlottie-react
because dotlottie-react presents a very high CPU usage (even with simple animations) which slows down the performance of my browser/my PC overall and thus it is not a good option for my use case.
Here is a comparison table between the two options when hovering over a lottie animation, using Chrome Performance Monitor:
dotlottie-react | dotlottie-web + worker | |
---|---|---|
CPU Usage | ![]() |
![]() |
Question 1
- Reading dotlottie-react docs and also following past issues DotLottie worker #203 I was not able to find a prop which enables the usage of a web worker to prevent the CPU overload. Am I missing something? or is this feature not implemented for the
dotlottie-react
wrapper?
It would be great to have a prop like workerOptions
to enable it's usage and customization with dotlottie-react
:
<DotLottieReact
src={src}
className={className}
speed={speed}
loop={loop}
autoplay={autoplay}
dotLottieRefCallback={dotLottieRefCallback}
layout={layout}
useFrameInterpolation={false}
workerOptions={{
enable: true,
absoluteUrlPath: 'someUrl',
...otherOptions
}}
/>
Overview 2 - worker issue in safari
The web worker works like a charm in chromium based browsers and also works for firefox, however for safari, dotlottie-web custom components break on the initial load due to the following error:
[Error] Unhandled Promise Rejection: TypeError: this._canvas.transferControlToOffscreen is not a function. (In 'this._canvas.transferControlToOffscreen()', 'this._canvas.transferControlToOffscreen' is undefined)
(anonymous function) (@lottiefiles_dotlottie-web.js:38)
Promise
E (@lottiefiles_dotlottie-web.js:24)
Y2 (@lottiefiles_dotlottie-web.js:2150:191)
(anonymous function) (DotLottieWorkerComp.tsx:91)
react-stack-bottom-frame (react-dom_client.js:17478)
runWithFiberInDEV (react-dom_client.js:1487)
commitHookEffectListMount (react-dom_client.js:8460:140)
commitHookPassiveMountEffects (react-dom_client.js:8518:86)
commitPassiveMountOnFiber (react-dom_client.js:9887)
recursivelyTraversePassiveMountEffects (react-dom_client.js:9868)
commitPassiveMountOnFiber (react-dom_client.js:9984)
recursivelyTraversePassiveMountEffects (react-dom_client.js:9868)
commitPassiveMountOnFiber (react-dom_client.js:9881)
recursivelyTraversePassiveMountEffects (react-dom_client.js:9868)
commitPassiveMountOnFiber (react-dom_client.js:9984)
recursivelyTraversePassiveMountEffects (react-dom_client.js:9868)
commitPassiveMountOnFiber (react-dom_client.js:9881)
recursivelyTraversePassiveMountEffects (react-dom_client.js:9868)
commitPassiveMountOnFiber (react-dom_client.js:9984)
recursivelyTraversePassiveMountEffects (react-dom_client.js:9868)
commitPassiveMountOnFiber (react-dom_client.js:9881)
recursivelyTraversePassiveMountEffects (react-dom_client.js:9868)
commitPassiveMountOnFiber (react-dom_client.js:9984)
recursivelyTraversePassiveMountEffects (react-dom_client.js:9868)
commitPassiveMountOnFiber (react-dom_client.js:9881)
recursivelyTraversePassiveMountEffects (react-dom_client.js:9868)
commitPassiveMountOnFiber (react-dom_client.js:9881)
recursivelyTraversePassiveMountEffects (react-dom_client.js:9868)
commitPassiveMountOnFiber (react-dom_client.js:9984)
recursivelyTraversePassiveMountEffects (react-dom_client.js:9868)
commitPassiveMountOnFiber (react-dom_client.js:9881)
recursivelyTraversePassiveMountEffects (react-dom_client.js:9868)
commitPassiveMountOnFiber (react-dom_client.js:9984)
recursivelyTraversePassiveMountEffects (react-dom_client.js:9868)
commitPassiveMountOnFiber (react-dom_client.js:9881)
recursivelyTraversePassiveMountEffects (react-dom_client.js:9868)
commitPassiveMountOnFiber (react-dom_client.js:9984)
recursivelyTraversePassiveMountEffects (react-dom_client.js:9868)
commitPassiveMountOnFiber (react-dom_client.js:9984)
recursivelyTraversePassiveMountEffects (react-dom_client.js:9868)
commitPassiveMountOnFiber (react-dom_client.js:9984)
recursivelyTraversePassiveMountEffects (react-dom_client.js:9868)
commitPassiveMountOnFiber (react-dom_client.js:9881)
recursivelyTraversePassiveMountEffects (react-dom_client.js:9868)
commitPassiveMountOnFiber (react-dom_client.js:9881)
recursivelyTraversePassiveMountEffects (react-dom_client.js:9868)
commitPassiveMountOnFiber (react-dom_client.js:9881)
recursivelyTraversePassiveMountEffects (react-dom_client.js:9868)
commitPassiveMountOnFiber (react-dom_client.js:9984)
recursivelyTraversePassiveMountEffects (react-dom_client.js:9868)
commitPassiveMountOnFiber (react-dom_client.js:9881)
recursivelyTraversePassiveMountEffects (react-dom_client.js:9868)
commitPassiveMountOnFiber (react-dom_client.js:9881)
recursivelyTraversePassiveMountEffects (react-dom_client.js:9868)
commitPassiveMountOnFiber (react-dom_client.js:9881)
recursivelyTraversePassiveMountEffects (react-dom_client.js:9868)
commitPassiveMountOnFiber (react-dom_client.js:9984)
recursivelyTraversePassiveMountEffects (react-dom_client.js:9868)
commitPassiveMountOnFiber (react-dom_client.js:9984)
recursivelyTraversePassiveMountEffects (react-dom_client.js:9868)
commitPassiveMountOnFiber (react-dom_client.js:9984)
recursivelyTraversePassiveMountEffects (react-dom_client.js:9868)
commitPassiveMountOnFiber (react-dom_client.js:9881)
recursivelyTraversePassiveMountEffects (react-dom_client.js:9868)
commitPassiveMountOnFiber (react-dom_client.js:9881)
recursivelyTraversePassiveMountEffects (react-dom_client.js:9868)
commitPassiveMountOnFiber (react-dom_client.js:9984)
recursivelyTraversePassiveMountEffects (react-dom_client.js:9868)
commitPassiveMountOnFiber (react-dom_client.js:9881)
recursivelyTraversePassiveMountEffects (react-dom_client.js:9868)
commitPassiveMountOnFiber (react-dom_client.js:9899)
flushPassiveEffects (react-dom_client.js:11302)
performSyncWorkOnRoot (react-dom_client.js:11632)
flushSyncWorkAcrossRoots_impl (react-dom_client.js:11536:144)
flushSpawnedWork (react-dom_client.js:11254)
commitRoot (react-dom_client.js:11081)
commitRootWhenReady (react-dom_client.js:10512)
performWorkOnRoot (react-dom_client.js:10457)
performWorkOnRootViaSchedulerTask (react-dom_client.js:11623)
performWorkUntilDeadline (react-dom_client.js:36)
NOTE: i also noticed a similar error happens in firefox when having a lot of browser tabs opened. I remember i saw a memory issue with the worker on firefox too, however i was not able to reproduce it again. It fails on firefox sometimes, not really sure if it's happening to me only.
My dotlottie-web component (using the web worker) implementation is very similar to the patch added in this comment: #326 (comment)
...
Consuming repo
- dotlottie-web -> "@lottiefiles/dotlottie-web": "^0.44.0" https://github.com/LottieFiles/dotlottie-web/blob/main/packages/web/README.md
- dotlottie-react -> "@lottiefiles/dotlottie-react": "^0.13.5" https://github.com/LottieFiles/dotlottie-web/blob/main/packages/react/README.md
Browser versions
firefox - 138.0.4 (64-bit)
safari - ~16 , AppleWebKit/605.1.15 (KHTML, like Gecko)
lottie animation for testing purposes
I created this animation for testing purposes using some of the lottie web features:
- JSON VERSION generic_gears_test.json
...
Labels
- Add the
Type: Bug
label to this issue.
References
- Web worker - https://developers.lottiefiles.com/docs/dotlottie-player/dotlottie-web/worker/
- https://github.com/LottieFiles/dotlottie-web
Last but not least.... THANKS SO MUCH for the great work dotlottie-web dev team! ⭐ 💯