mauricevancooten / react-anchor-link-smooth-scroll

React component for anchor links using the smooth scroll polyfill.
243 stars 31 forks source link

Cannot read property 'getBoundingClientRect' of null #36

Open saadaouad opened 3 years ago

saadaouad commented 3 years ago

First of all I'd like to thank you for this package,

I'm getting this error raised on Sentry:

TypeError apply(react-anchor-link-smooth-scroll/lib/anchor-link) error 
Cannot read property 'getBoundingClientRect' of null
Screen Shot 2020-11-10 at 1 18 41 PM

And I think it would be great to silent it by providing $anchor var with something like this:

var $anchor = document.getElementById(id);
var offsetTop = $anchor && $anchor.getBoundingClientRect().top + window.pageYOffset;

Or use optional chaining:

var $anchor = document?.getElementById(id);
var offsetTop = $anchor?.getBoundingClientRect().top + window.pageYOffset;
jorgearturonh commented 3 years ago

Hi, im currently having the exact same issue

sampreet-chawla commented 3 years ago

Thanks for the package.. but getting a similar issue. It would be nice to have the fix.

LOGANLEEE commented 3 years ago

having same issue...

this anchor want to find #id but if component that contain #id is not rendered yet

then this error will occur.

thus I hope you guys can get help

MartinDawson commented 2 years ago

The fix is to remove this library from your codebase. It's been abandoned, don't expect any fix.