turbolinks/turbolinks-classic

Page does not always scroll to the top when DOM loads too fast

terracatta opened this issue · 0 comments

I believe there is a race condition in Turbolinks where it attempts to change the scroll position to the top of the page before the DOM has been fully replaced, and as a result, the page is not scrolled to the top successfully.

Steps to reproduce.

  1. Start on page A (which should have a lot of content) and scroll to the bottom
  2. Click a link on page A that goes to page B (which should also have a lot of content that requires a scroll bar)
  3. You will be on the top of page B (as expected) now press back
  4. You will be in your former position on page A (as expected) now re-click the link to page B

Expected Result: page B loads and my scroll position is at the top of page B just like before
Actual Result: page B loads but my scroll position remains unchanged from page A

Again, I believe this is a race condition, if you add a simple <100ms timeout to this call then the problem is completely mitigated.