ember.js icon indicating copy to clipboard operation
ember.js copied to clipboard

[Bug] Unexpected aborted transitions following call to RouterService.transitionTo()

Open mgallag opened this issue 2 years ago • 4 comments

🐞 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

  1. Visit /parent/child-a/
  2. Click on Transition: "via Service" button
  3. Click on any of the other transition buttons or links.

😕 Actual Behavior

  • App transitions between parent.child-a, parent.child-b, and parent.child-c
  • The transition between parent.child-b and parent.child-c is aborted and a full route transition of parent.child-c is performed.
  • The parent route's model hook is called twice

🤔 Expected Behavior

  • App transitions between parent.child-a, parent.child-b, and parent.child-c
  • Transitions are between child routes only.
  • The parent route'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

mgallag avatar Mar 19 '22 02:03 mgallag

Potentially related issues: https://github.com/emberjs/ember.js/issues/19611, https://github.com/emberjs/ember.js/issues/16349

mgallag avatar Mar 21 '22 19:03 mgallag

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

RobbieTheWagner avatar Jul 14 '22 17:07 RobbieTheWagner

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.

dwickern avatar Aug 31 '22 17:08 dwickern

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.

nickschot avatar Feb 29 '24 14:02 nickschot