solid-router icon indicating copy to clipboard operation
solid-router copied to clipboard

Scroll Restoration / History API

Open Abiti-936 opened this issue 2 years ago • 8 comments

First of All, I would like to say Thanks for an Awesome Work in solid-app-router & it's integration with Solid Start. I have seen Scroll Restoration or History API in Vue, Remix, Next.js, but Coming to Solid Start & solid-app-router I can't get it working. Every time when routing happens the page losts the Scroll Position.

Can You make Scroll Restoration in Solid App Router?

Abiti-936 avatar Apr 12 '22 13:04 Abiti-936

Today we just rely on what the browser provides for scroll restoration which does work with both the default path/history integration and hash integration; however it seems limited to work within the next frame. So if you have to wait for resources or the rendering is expensive and the scrolling height isn't there yet, it will not work. Ideally going back and forward should used cached data but it looks like we need to do better here.

rturnq avatar Apr 15 '22 16:04 rturnq

For reference: https://reactrouter.com/en/main/components/scroll-restoration

orenelbaum avatar Dec 27 '22 00:12 orenelbaum

The response to this react router issue seems relevant for lazy loaded data/components.

Essentially it suggests the user would need to add a router-provided hook/component into each lazy loaded page so it will only attempt to restore scroll after the page is fully rendered. On that basis, it might as well just be a router provided function the app-code called at an appropriate time after the page has finished loading (eg restoreScrollPosition).

Brendan-csel avatar Dec 27 '22 02:12 Brendan-csel

The fact we use Suspense might make this different. We don't finish until all async is done (including lazy components). That being said Im seeing stuff to suggest that isn't the case but that's the intention.

ryansolid avatar Dec 27 '22 02:12 ryansolid

I'm not 100% sure it is related, but when I do:

onMount(() => {
  window.scrollTo(0, 500);
})

it works only when I open or refresh the page. Every time the route is changed through the router, this is ignored. Any idea how I can make this work on route change?

ilyador avatar Mar 24 '23 10:03 ilyador

I'm not 100% sure it is related, but when I do:

onMount(() => {
  window.scrollTo(0, 500);
})

it works only when I open or refresh the page. Every time the route is changed through the router, this is ignored. Any idea how I can make this work on route change?

I have the same problem, for some reason the scroll event is not working when i work with pages that share the same layout

Eifhen avatar Jun 11 '23 01:06 Eifhen