Open apoorvparijat opened 4 years ago
Thank you for reporting with so many details! I do think we should fix this (having the URL be mismatched with what is currently rendered is definitely not good), but it isn't obvious to me what the best way to fix would be.
Ember uses the History API's pushState method whenever there is an application triggered URL change (e.g. clicking the "Contact Us" link in your demo).
Ember also listens for the popstate event to know when the user clicked the back/forward buttons to create in application transitions to navigate to corresponding URL. It is important to realize that at the point the event is fired, the history state has already been popped and the current URL in the browser has already been updated.
The issue here is that the callback we register with onUpdateURL
there initiates a transition, but does nothing to ensure that transition is successful. This means that if that transition is .abort()
ed the UI will now be out of sync with the URL.
I think the best way to fix this, is to ensure that the URL matches after the transition completes.
Hey! I also encountered this bug and I wonder how people deal with the issue
transition.abort()
is not currently working as expected. In some circumstances, when the user hits the back button, we prompt the user for unsaved changes. We handle this scenario in a lot of places by doing something like the following (This is the suggested approach in the tutorial here)The above doesn't appear to work 100% of the time. While the route has not changed, the browser URL points to something else.
Code for the above example I created a test ember app to replicate this. The code in this repo follows "Create your first ember app" tutorial guidelines. https://github.com/apoorvparijat/test-ember-app
Steps to reproduce
Contact
link/contact
What does happen: The URL has already changed to the/about
page before accepting the dialogGIF demonstrating the same