Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

SC.routes popState() handler invokes window.history.pushState() #719

wemrysi opened this Issue Feb 22, 2012 · 3 comments


None yet
3 participants

wemrysi commented Feb 22, 2012

In the current implementation of SC.routes, when the popState() handler is called it uses this.set('location', ...) internally which calls window.history.pushState() and causes the state/location at the top of the history stack to be pushed onto the stack again. i.e.

History = []
History = [A]
History = [A,B]
BACK --> popState()
History = [A,A]

the same thing happens in hashChange() but since it just sets the location hash in that case, the effect is innocuous.


publickeating commented Jun 15, 2012

I'm terribly sorry for the slow response on this. Are you able to provide a reduced test case to reproduce this? I don't have much (any?) time to delve into figuring this one out currently. Thanks.


dcporter commented Feb 16, 2014

Confirmed this issue. Repro:

  • Take any app using hashy routes (most of them, probably) and add SC.routes.wantsHistory = YES in core.js.
  • Within the app, go forward a couple of states.
  • Use the back button to go backwards. Each back state is now doubled up, requiring two clicks to get back through.

Per @wemrysi, the duplicate set behavior is triggered with hash histories too, but since it uses window.location.hash (which I believe doesn't trigger anything if it doesn't change) instead of window.history.pushState, there's no consequence.

@dcporter dcporter closed this in ba90943 Feb 16, 2014


dcporter commented Feb 16, 2014

I'm assuming that all invocations of SC.routes.popState and SC.routes.hashChange are triggered by (or in response to) an exogenous history change, and the location change should therefore not trigger a history update.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment