Giter Club home page Giter Club logo

restore-scroll's People

Contributors

kentcdodds avatar na2hiro avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

restore-scroll's Issues

Doesn't work with MUI v5 / React Router Dom 6.21.1

As title says.
I'm trying to restore the scroll within a MUI table but it doesn't seem to work with the package versions mentioned in the title.
The ScrollRestoration from React Router Dom would work for the window.body but i did need this feature for tables as well.
Trying to play around with query selector didn't work, nor did trying to select different components to restore the scroll to.
Besides this, I see in the session storage that the library does save scrolling position ( stacking them instead of re-using them however ), but browsing back to / directly to a page doesn't restore my scrolls.
Is there a working example available for React Rouer Dom 6.21.xxx ? As this feature is not supported by React Router Dom in its current state this library would have helped a lot.

I don't know what's wrong

I tried to use it, with React router v6

so, i have router config with createBrowserRouter:

  const router = createBrowserRouter([
    {
      path: '/',
      element: <Layout />,
      children: [
        {
          path: '/',
          element: <Home />,
        },
        {
          path: '/dashboard',
          element: <Dashboard />,
        },
      ],
    },
  ]);

then in the Home component i'm rendering a chat:

<div>
   <div
          id="chatContainer"
          className="h-full flex flex-col gap-3 overflow-y-scroll scroll-smooth"
          ref={ref}
        >
          {renderHelper}
   </div>
   <ElementScrollRestoration elementQuery="#chatContainer" />
</div>      

The renderHelper only makes some validating, and insert prompts and answers, it scrolls, cool, but when i nav to Dashboard, and comeback to Home, the scroll position is not saved, it at top

I will provide a Codesandbox later, but i don't know if i can recreate the exact thing, because it's a bigger project, with many things rappening on the chat.

But i think the scroll part is this, the #chatContainer, render on page load, and stays there forever, even if has no messages, so the reference to the ElementScrollRestoration exists

It doesn't work

I tried this package and it doesn't work. Can you show a working example? (CodeSandbox or Stackblitz)

Issues with `useBeforeUnload` on iOS Safari

I've been noticing that ElementScrollRestoration does not work on iOS Safari, or at least not reliably. I could pinpoint the issue to useBeforeUnload not being triggered due to window.onbeforeunload not being supported. There have been similar reports for react-router-dom (remix-run/react-router#9463), which have been fixed by switching to listening to window.pagehide (remix-run/react-router#9945). Monkey patching or rather just forking ElementScrollRestoration and adding and using the usePageHide hook fixes these problems for me. If this is a known bug that does not only affect me for some reason, I'd be happy to help out with a pull request.

Usage with Remix

When I use in my Remix app, I get an error saying it's not wrapped with data router. If I copy paste ElementScrollRestoration and modify import from react-router-dom to @remix-run/react, it works.

useNavigation must be used within a data router. See https://reactrouter.com/routers/picking-a-router.

Can this library cover Remix usage as well?

Versions and setup

  • Remix: 2.3.0, 2.9.1
  • react-router-dom: 6.21.0
  • Vite
  • Custom express server

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.