Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support scrollable non-body containers. #51

Open
ivan-kleshnin opened this issue Feb 29, 2024 · 2 comments
Open

Support scrollable non-body containers. #51

ivan-kleshnin opened this issue Feb 29, 2024 · 2 comments

Comments

@ivan-kleshnin
Copy link

ivan-kleshnin commented Feb 29, 2024

Hello! This library works fine for default (body) scrollable container. Hovewer, it's often necessary to have a combination of scrollable container and a sticky header. Or something else for that matter. Unless I messed up, the following does not work with next-scroll-restorer:

export function Shell() {
  // using Tailwind classes, hopefully it's clear
  return <div className="overflow-auto max-h-screen">
  ...
  </div>
}

Here's the same problem discussed in Remix framework community and some yet unofficial solutions to it.

Context

I'm trying to auto-restore scroll position on a user search page with an infinite scroll (powered by React-Query).
I'm clicking on a Profile Detail link, then I'm clicking on the native Back button in Chrome. My own ad-hoc restorer works fine so there's no structural issue that would block the desired behavior.

@l-you
Copy link
Member

l-you commented Mar 3, 2024

Hello! I have some ideas on how to implement it but will do so later.
If you'd like to speed up the process, feel free to open a pull request. However, please ensure that you include tests for this particular case.

@javascripter
Copy link

https://github.com/javascripter/next-scroll-restoration
I ended up not using custom scrolling elements for our website so I'm not using it yet in production but here's my attempt at it when I was trying to solve it (feel free to take implementation ideas from my library if applicable).
Using scroll events to discover custom scrolling elements automatically seems to be reliable in dynamic websites.

Current known problem in my implementation is when navigating to the same href in different history stacks it wrongly restores scrolls, since my implementation uses location.pathname as the history state key.

next-scroll-restorer seems to cover lots of edge cases quite well so if non-body container scroll restoration gets implemented in this library it'd be pretty awesome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants