ember.js
ember.js copied to clipboard
[Bug] Unexpected aborted transitions following call to RouterService.transitionTo()
🐞 Describe the Bug
Initiating a transition using <LinkTo> or any deprecated transition method after calling RouterService.transitionTo() causes an aborted transition which triggers a full route refresh.
Precondition:
- Parent/child routes with navigation between child routes.
- Parent route must define a queryParams object. The actual query param value is left undefined.
🔬 Minimal Reproduction
Repro with tests: https://github.com/mgallag/repro-transition-abort
- Visit
/parent/child-a/ - Click on Transition: "via Service" button
- Click on any of the other transition buttons or links.
😕 Actual Behavior
- App transitions between
parent.child-a,parent.child-b, andparent.child-c - The transition between
parent.child-bandparent.child-cis aborted and a full route transition ofparent.child-cis performed. - The
parentroute's model hook is called twice
🤔 Expected Behavior
- App transitions between
parent.child-a,parent.child-b, andparent.child-c - Transitions are between child routes only.
- The
parentroute's model hook is only ever called once
🌍 Environment
- Ember: 4.2.0
- Node.js/npm: 14.19.1
- OS: Mac OS 11.6.4
- Browser: Chrome 99.0.4844.74
➕ Additional Context
- This issue requires that a queryParams object is defined on a router but the query param value is left undefined.
- If a query param value is specified in the URL the issue does not occur
- This issue requires that a RouterService initiated transition is followed by any other method of transitioning between child routes.
- If transitions are exclusively initiated by RouterService the issue does not occur
- If transitions are never initiated by the RouterService the issue does not occur
Potentially related issues: https://github.com/emberjs/ember.js/issues/19611, https://github.com/emberjs/ember.js/issues/16349
Would it be possible to introduce a param to stop this behavior? The refresh method allows us to pass a route name in and only refresh that model and descendants, not parents. https://api.emberjs.com/ember/4.4/classes/RouterService/methods/transitionTo?anchor=refresh
This is caused by https://github.com/emberjs/ember.js/issues/19493. The router redirects to the new query params which aborts the original transition.
I applied my workaround to your repro and all tests pass. Upgrading to ember 4.4 should also fix it.
I don't know when this came back (or if it was ever truly fixed), but I just ran into this issue with ember-source 5.6, also related to https://github.com/emberjs/ember.js/issues/20512 . Either using a LinkTo, the private -routing service's transitionTo method or removing the default query parameter value appears to "fix" the issue. None are true solutions I think.