You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I stumbled upon an interesting edge case that I think could be valuable to document. It's not a bug in lottie-react or lottie-web, but rather a gotcha when using Lottie in a specific setup.
Setup
Project structure: Monorepo
Multiple applications/packages using lottie-react
Two Lottie animations on the same page, coming from different packages
Problem
The animations had clipPath elements with identical identifiers (__lottie_element_X). This caused the latter animation to be "cut off" as its clipPath was overwritten by the first one.
Luckily, lottie-web provides a method to customize the prefix (and lottie-react exports LottiePlayer from lottie-web), which solves this issue. Here's a quick example:
I think this piece of code would be better placed in an index.ts, given that IDPrefix is a global variable, but this is an example. This would avoid duplicating the code and having multiple identifiers that could conflict in the same package.
Could the documentation be improved in this direction? If so, I could make a PR.
Thank you in advance!
The text was updated successfully, but these errors were encountered:
First off, thanks for this awesome library.
Issue
I stumbled upon an interesting edge case that I think could be valuable to document. It's not a bug in
lottie-react
orlottie-web
, but rather a gotcha when using Lottie in a specific setup.Setup
lottie-react
Problem
The animations had
clipPath
elements with identical identifiers (__lottie_element_X
). This caused the latter animation to be "cut off" as itsclipPath
was overwritten by the first one.Investigation
Digging into the
lottie-web
source, I found that unique identifiers are generated using a simple increment:https://github.com/airbnb/lottie-web/blob/0d658b34c40d4e81eafdccbf698815346454a899/player/js/utils/common.js#L117-L123
Solution
Luckily,
lottie-web
provides a method to customize the prefix (andlottie-react
exportsLottiePlayer
fromlottie-web
), which solves this issue. Here's a quick example:I think this piece of code would be better placed in an
index.ts
, given thatIDPrefix
is a global variable, but this is an example. This would avoid duplicating the code and having multiple identifiers that could conflict in the same package.Could the documentation be improved in this direction? If so, I could make a PR.
Thank you in advance!
The text was updated successfully, but these errors were encountered: