turbolinks / turbolinks-classic

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

Unexpected behavior with 'back' after anchor #584

Closed stefankroes closed 9 years ago

stefankroes commented 9 years ago

I'm experiencing some incorrect behavior regarding the back button after clicking an anchor. I'm not sure if this is considered a bug because this behavior seems deliberate (after inspecting the source). If it's not a bug, perhaps I'm doing something wrong.

To reproduce:

  1. Visit a page with anchors (for the first time after a hard refresh), this page is currently not in cachedPages.
  2. Visit an anchor on the same page (the page is not cached because !click._validForTurbolinks because link.shouldIgnore because link._anchored)
  3. Click the 'back' button, this pops the url and restored the scroll position (the browser does this and this is the expected behavior)
  4. Turbolinks popstate callback triggers. It does not find the new url in cache and decides to visit it. This triggers a request to the server (unexpected/incorrect) and replaces the page body which resets any expanded/collapsed content etc. (unexpected/incorrect)

My solution for now:

Possible solutions in Turbolinks (which may have unintended side effects, but I leave that to you):

Thibaut commented 9 years ago

Thanks for the detailed bug report. I'll look into this soon.