react-scroll-section icon indicating copy to clipboard operation
react-scroll-section copied to clipboard

Refs problems with React Router

Open alexis78i opened this issue 5 years ago • 6 comments

Hi, First, thank you for this package.

I'm using it in dynamic mode with React Router, and it's always crashed when I'm moving back and forward in the browser.

TypeError: null is not an object (evaluating 'REFS[id].current.getBoundingClientRect') src/ScrollingProvider.tsx:37 var registerRef = function (id) { var ref = React.createRef(); REFS[id] = ref; return ref;

And I also found this pull request is very useful. https://github.com/EmaSuriano/react-scroll-section/pull/97

alexis78i avatar Oct 23 '20 10:10 alexis78i

Hello, can you provide a code sandbox example to reproduce the issue? I didn't try the library with react-router but I don't know how that can cause problems :/

EmaSuriano avatar Oct 23 '20 14:10 EmaSuriano

@EmaSuriano it's here https://codesandbox.io/s/young-bush-bli99 You need to go URL /page2 first (in browser), and then go to the main page and you have to get null is not an object (evaluating 'REFS[id].current.getBoundingClientRect')

alexis78i avatar Oct 24 '20 10:10 alexis78i

Hello @alexis78i, I don't see the exception in the code sandbox you shared. Also, I am supposed to click between the sections in the second page?

EmaSuriano avatar Oct 27 '20 08:10 EmaSuriano

I have the same error when I enter a page containing ScrollingProvider and as section it returns this same error on the screen × TypeError: Cannot read property 'getBoundingClientRect' of null sending a screen print to show the error, when I update the screen it works again https://ibb.co/jw395Gx

cesarsousa3 avatar Nov 10 '20 14:11 cesarsousa3

Hello @cesarsousa3, thanks for the log. Can you reproduce the issue in the example from above?

EmaSuriano avatar Nov 15 '20 18:11 EmaSuriano

I made a PR to do a check. I also commented that this lib is probably not the one we need.

In reality I think this lib was thought for a single page, which makes sense that it stores everything in the context. If you have a more complex page where the stuff changes problems start. specially with SSR, which basically stores the status of the previous pages.so if you load a page SSR you will see wrong data in the sections until client side kicks in.

DevAlien avatar Nov 23 '20 12:11 DevAlien

Hello, I updated this library, and now it looks this issue is solved, in the latest version :)

Check out the codesandbox using the latest version --> https://codesandbox.io/s/quirky-parm-yeh8wc

I will proceed to close this issue for now. Feel free to open it again, in case there is something unresolved.

EmaSuriano avatar Oct 16 '22 09:10 EmaSuriano