Transition.abort() with query-params does not abort transition

When I change a query-parameter in my controller, it causes willTransition to fire in the corresponding route. However, say I want to abort that transition by calling transition.abort() in the willTransition method. After calling abort(), the willTransition method is fired again - so if I always call abort(), this causes an infinite loop.

Is there a way to abort the transition in which willTransition will not keep firing?

I looked in the source code and found out why this was happening, but haven’t found a solution for it. Even though I call transition.abort(), in the source code the function getTransitionByIntent looks to see if the query-params have changed, and if they do it sets off the process of calling willTransition. So essentially transition.abort() does not reset the query params.

Here’s some extra info that might be too much information, so I’m putting this at the bottom:

I can’t even do something hacky where I manually reset the query-params on the transition object myself, because what happens in getTransitionByIntent is that the method creates an internal variable called queryParamsChangedList, then it sets off a chain reaction in which it calls willTransition. In willTransition, there is no way for me to have access to the queryParamsChangedList variable. After this chain reaction is done, and we are back in getTransitionByIntent, and it calls fireQueryParamDidChange, in which it sets off another chain reaciton in which getTransitionByIntent is called again. And because I tried to abort the transition, the method thinks the query params are still out of sync, so the queryParamsChangedList is never empty.

1 Like

I have just encountered exactly this issue, and looking at the source code this issue actually arises in the router library Ember uses: https://github.com/tildeio/router.js/blob/master/lib/router/router.js#L33 . Not sure what to do about that, but hoping I can find some way to hack a solution. This seems to me a pretty nasty bug so it would be worth raising an issue on Ember about it.

Edit: Issue here Infinite loop when aborting query param transition opting in for refreshModel · Issue #12473 · emberjs/ember.js · GitHub

Js bin here JS Bin - Collaborative JavaScript Debugging

See this alternative implementation using the beforeModel hook: JS Bin - Collaborative JavaScript Debugging