react-scroll-section
react-scroll-section copied to clipboard
Refs problems with React Router
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
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 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')
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?
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
Hello @cesarsousa3, thanks for the log. Can you reproduce the issue in the example from above?
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.
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.