mifi / react-lottie-player

Fully declarative React Lottie player
MIT License
494 stars 52 forks source link

react-lottie-player is not working in production mode but it is working fine in localhost #87

Open vijeeth-pro opened 1 year ago

vijeeth-pro commented 1 year ago

I'm working in next js and I user react-lottie-player. it is working fine in local host but is not working in production mode.. please help me.. here is production link

import React, { useEffect } from "react";
import Lottie from "react-lottie-player";
import LottieImage1 from "../../public/static/1.json";
import LottieImage2 from "../../public/static/2.json";
import LottieImage3 from "../../public/static/3.json";

function AnimationFile({ file }) {
  const [windowScreen, setWindowScreen] = React.useState(0);
  const [responsive, setResponsive] = React.useState(0):
  const [defaultOptions, setDefaultOptions] = React.useState({
    loop: true,
    autoplay: true,
    animationData: LottieImage1,
    rendererSettings: {
      preserveAspectRatio: "xMidYMid slice",
    },
  });

  useEffect(() => {
    setWindowScreen(window.innerWidth);
    setResponsive(window.innerWidth - 50);
  }, []);

  useEffect(() => {
    if (file === "1") {
      setDefaultOptions((prev) => ({
        ...prev,
        animationData: LottieImage1,
      }));
    } else if (file === "2") {
      setDefaultOptions((prev) => ({
        ...prev,
        animationData: LottieImage2,
      }));
    } else if (file === "3") {
      setDefaultOptions((prev) => ({
        ...prev,
        animationData: LottieImage3,
      }));
    }
  }, [file]);

  return (

    <Lottie
      loop
      animationData={defaultOptions.animationData}
      play
      style={{
        width: windowScreen < 500 ? responsive - 50 : 600,
        height: windowScreen < 500 ? responsive - 50 : 600,
      }}
    />
  );
}

export default  #AnimationFile;
mifi commented 1 year ago

Does it work with 1.5.0?

mifi commented 1 year ago

I think related:

vijeeth-pro commented 1 year ago

I'm using current version "react-lottie-player": "^1.5.0", but it's not working

mifi commented 1 year ago

I think it’s a bug with lottie-web. Can you try to use lottie-web directly and see if you get this problem? Other workaround is to disable minify for lottie-web, or I think use lottie-light instead

hernandemonteiro commented 1 year ago

I have this problem too, i'm using nextJS and in local is fine but in production it breaks

mifi commented 1 year ago

what's the error?

hernandemonteiro commented 1 year ago

the animation hide in production, but in localhost i can see the animation.

mifi commented 1 year ago

does it work with lottie-web? also, try lottie light instead, does that work?

hernandemonteiro commented 1 year ago

yes, lottie-web work... thanks...

mifi commented 1 year ago

But react lottie player wirh lottie light does not?

willydavid1 commented 1 year ago

I have the same problem image

willydavid1 commented 1 year ago

If you are using nextjs you have to update to the next version

next@13.0.5

pnpm install next@13.0.5