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
I tried to use it, with React router v6
so, i have router config with createBrowserRouter:
then in the Home component i'm rendering a chat:
The
renderHelperonly 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 topI 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
ElementScrollRestorationexists