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

TypeError: null is not an object (evaluating 'O.current.clientHeight') #83

Open
5starkarma opened this issue Jun 26, 2023 · 0 comments
Open

Comments

@5starkarma
Copy link

5starkarma commented Jun 26, 2023

Hello,

Our Sentry logs keep getting a type error pointing to this library. It seems that it is saying that an object (html) doesn't exist. Wondering what the cause of this could be. We are using create-react-app, no SSR. The only thing I can think is that there are several of these sections and the images are lazy loaded - but why would that affect it? Any thoughts?

Sentry Logs Screenshot

image

Usage

      <section className={styles.systemFeaturesFrame} id="systemFeaturesFrame">
        <div className={styles.headerContainer}>
          <AnimationOnScroll animateIn="animate__flipInX" offset={-300}>
            <h1 className={styles.systemFeaturesText}>
              System{" "}
              <span className={styles.systemFeaturesTextBold}>Features</span>
            </h1>
          </AnimationOnScroll>
        </div>
        <div className={styles.dashboardImgContainer}>
          <div className={styles.dashboardGlow} />
          <picture className={styles.dashboardImgPic}>
            <source srcSet={dashboardImg} type="image/avif" />
            <img
              loading="lazy"
              src={dashboardImgFallback}
              className={styles.dashboardImg}
              alt="Dashboard"
            />
          </picture>
        </div>

Problem Description

It looks like there's a TypeError in the react-animation-on-scroll library. The error message says that O.current.clientHeight is null and cannot be accessed. The error happened on line 159 of ../node_modules/react-animation-on-scroll/src/components/AnimationOnScroll.tsx.

Proposed Solution

To fix this issue, you need to make sure that the O.current object is not null before trying to access its clientHeight property. One way to do this is by adding a null check before accessing the property. Here's an example of what the fixed code could look like:

const elementBottom = O.current ? elementTop + O.current.clientHeight : 0;
You should add this change directly to the AnimationOnScroll.tsx file, at line 159.

To prevent this issue from happening in the future, make sure to always check for null or undefined values before accessing their properties. You can also use TypeScript or other static type checkers to catch these errors before runtime.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant