alexkatz / react-tiny-popover

A simple and highly customizable popover react higher order component with no other dependencies! Typescript friendly.
MIT License
454 stars 121 forks source link

Cannot read property 'getBoundingClientRect' of null #100

Closed Valerika closed 2 years ago

Valerika commented 3 years ago

Hi! I'm getting sometimes this error in console Uncaught TypeError: Cannot read property 'getBoundingClientRect' of null

How can I fix this?

image

ttamminen commented 3 years ago

I get this after resizing the window and opening the popover after the resize

ttamminen commented 3 years ago

The problem started when I migrated from v4 to v6. I had a custom component (styled <button>) that opened the popover.

I got rid of the error by doing the React.forwardRef thing from the documentation.

Linktheoriginal commented 3 years ago

I'm using the React.forwardRef behavior, but I see this error on a re-render after closing a related modal. I see elsewhere in the code where there is a ?. check for the ref, is that needed here?

humphrey commented 3 years ago

I also receive this error.

It occurs when I resize the screen AND resizing the screen causes the component to be destroyed... For example if I have something like this (not tested), then resizing the screen past 768px breakpoint will cause this issue. Hopefully the above fix resolves this.

import React from 'react';
import { useMedia } from 'react-media';
import { Popover } from 'react-tiny-popover';

const MyComponent = () => {
  const media = useMedia({queries: {md: '(min-width: 768px)'});
  return (
    <>
      {media.md ? 
        <div>
            Large screen
            <Popover/>
        </div>
      :
        <div>
            Small screen
            <Popover/>
        </div>
    </>
  );
}
tboerc commented 3 years ago

I can confirm that @humphrey issue is correct. On my current project, even with the forwardRef solution, if the resize causes the Popover to unmount, it will throw getBoundingClientRect error.

RusovVladimir commented 3 years ago

I have the same issue.

humphrey commented 3 years ago

I originally fixed with patch-package, but the issue is fixed for me in 6.0.10

On Tue, 24 Aug 2021 at 00:35, Vladimir @.***> wrote:

I have the same issue.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/alexkatz/react-tiny-popover/issues/100#issuecomment-903831324, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABYD4SS6EUGPBQN5GURGHLT6JMCRANCNFSM4WEARZ4A .

zhangqiangcrazy commented 2 years ago

I have the same issue.

alexkatz commented 2 years ago

Closing this issue, as it's been fixed!