router icon indicating copy to clipboard operation
router copied to clipboard

Hashed link not scrolling with lazy file routes

Open patatoes1235 opened this issue 1 year ago • 2 comments

Describe the bug

Urls with hashes not scrolling to correct section when using lazy file routes. This occurs any time the page is fully rerendered (e.g. on reload and when accessing a link with a hash in a new tab). Works as expected with normal (non-lazy) file routing.

Your Example Website or App

https://stackblitz.com/edit/github-4rybtq

Steps to Reproduce the Bug or Issue

  1. Run the stackblitz example
  2. Paste https://stackblitz.com/edit/github-4rybtq/#section into a new tab
  3. Click "connect" if needed
  4. Notice how even though the #section tag is appended to the url, the section is not scrolled to.

Expected behavior

Regardless of whether the route is lazy loaded or not, I would expect that when accessing a url with a section, the DOM element with the corresponding id is scrolled to.

Screenshots or Videos

No response

Platform

  • OS: Windows
  • Browser: Chrome

Additional context

No response

patatoes1235 avatar Jul 23 '24 04:07 patatoes1235

This also doesn't seem to work every with the <ScrollRestoration /> component.

SeanCassiere avatar Jul 26 '24 02:07 SeanCassiere

My best guess is that the browser is trying to scroll down before the lazily loaded component is fully rendered.

patatoes1235 avatar Jul 26 '24 21:07 patatoes1235

Completed with https://github.com/TanStack/router/releases/tag/v1.98.1

SeanCassiere avatar Jan 31 '25 02:01 SeanCassiere

Closing once again, after confirming that this issue is indeed fixed.

There was an issue with the original reproduction, whereby the div used a my-[100px] which in turn moved the start of the element much higher than where the actual content was placed.

SeanCassiere avatar Jan 31 '25 07:01 SeanCassiere