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

Failed to construct 'ImageData': The source width is zero or not a number. #260

Open
sulram opened this issue Jun 21, 2024 · 5 comments
Open
Assignees
Labels
question Further information is requested react

Comments

@sulram
Copy link

sulram commented Jun 21, 2024

Overview

Error that's occuring wrapper with display:none and framer motion of a <DotLottieReact /> component

Failed to construct 'ImageData': The source width is zero or not a number.

Sometimes

Consuming repo

What repo were you working in when this issue occurred?

@lottiefiles/dotlottie-react

@theashraf
Copy link
Member

Hi @sulram, when using display: none, the width and height of the DotLottieReact canvas are set to zero, causing the error.

You can use the hidden prop directly on the DotLottieReact component. This keeps the component in the DOM without rendering it visibly:

<DotLottieReact hidden ... />

also you can use other CSS properties like visibility or opacity:

<DotLottieReact style={{ visibility: 'hidden' }} ... />
<DotLottieReact style={{ opacity: 0 }} ... />

@theashraf theashraf added question Further information is requested react labels Jun 22, 2024
Copy link
Contributor

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs.

@github-actions github-actions bot added the stale label Aug 22, 2024
@Idowu-Adelekee
Copy link

I experience this issue with Web using vanilla JS, but the parent element also need to be set to display none because I'm working on a mobile nav which at the desktop screen should be hidden. Is there any other workaround to it?

@github-actions github-actions bot removed the stale label Sep 7, 2024
@steven-tey
Copy link

steven-tey commented Oct 13, 2024

Still getting this issue with the following code:

import { Wordmark } from "@dub/ui";
import { DotLottieReact } from "@lottiefiles/dotlottie-react";

export default function AnimatedWordmark() {
  return (
    <div className="group relative h-6">
      <Wordmark className="absolute h-6 group-hover:opacity-0" />
      <DotLottieReact
        src="https://lottie.host/f53c93bf-8ae7-4f55-a73e-fbdf36e5c062/4KoxyK0Ruc.json"
        playOnHover
        loop
        className="absolute h-6 opacity-0 group-hover:opacity-100"
      />
    </div>
  );
}

@theashraf
Copy link
Member

Thanks @steven-tey for the code, I'll investigate it further

@theashraf theashraf self-assigned this Oct 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested react
Projects
None yet
Development

No branches or pull requests

4 participants