Description
This is not urgent; it's a minor inconvenience. Scroll position works as expected on forward navigations.
In #1248 I patched React Router to allow us to use an element other than window as the target of scroll restoration. This worked both on new navigations (making sure any new page loads at the top rather than staying wherever you already were on the previous page) and on back button navigation, restoring the scroll position you were on before you navigated away. I confirmed now that it worked on that commit and that it stopped working the next and last time the patch was changed, in #1322.
I checked by adding a console.log
right at the spot where it should be doing the restore that it does in fact have a scroll position on hand to restore as well as the scroll target element, so the problem is not a cache miss. The target element scrollTo
is failing. I thought maybe it had zero height at the time of scroll (unlikely) and that was also not true: offsetHeight
appears to be correct at time of scrollTo
.
Changes to useScrollRestoration
between RR 6.4.2 and 6.6.1 (the version we were upgrading to when it broke) can be viewed here: remix-run/react-router@react-router-dom@6.4.2...react-router-dom@6.6.1#diff-4cdcfae34c14653226bf132d981bb026891ef456aaf8d88805be82d741a83771R1120
I don't see anything there that indicates why it would have stopped working, and like I said, it appears to be trying to scroll at the appropriate time. It is probably best to wait for the official solution (which we may ourselves be contributing). See discussion in remix-run/react-router#9495 and my first attempt remix-run/react-router#9573.