turbolinks / turbolinks-classic

Classic version of Turbolinks. Now deprecated in favor of Turbolinks 5.
MIT License
3.54k stars 428 forks source link

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

Open terracatta opened 8 years ago

terracatta commented 8 years ago

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.