machty / ember-concurrency

ember-concurrency is an Ember Addon that enables you to write concise, worry-free, cancelable, restartable, asynchronous tasks.
http://ember-concurrency.com
MIT License
688 stars 157 forks source link

transitionTo called by route task immediately transitions back #233

Open bgentry opened 6 years ago

bgentry commented 6 years ago

I just ran into a scenario where a route task was calling a function inside my route that itself called .transitionTo() on the route. I was randomly seeing failures with the transition. After doing some debugging on route transitions, it turned out that I was seeing my app transition to the new route and then immediately transition back to the previous one. I didn't have any hooks on the routes in question that might be aborting the transition or anything like that.

Eventually I figured out that if I enqueue that function call w/ the transitionTo inside a runloop, everything works 100% of the time.

Is this expected?

tylerturdenpants commented 6 years ago

@bgentry code you show a snippet of your workaround? I think I'm facing this same issue

bgentry commented 6 years ago

I believe this was:

// broken route.js
...
  myTask: task(function*() {
    this.transitionTo("otherRoute");
  }),
// working route.js
...
  myTask: task(function*() {
    Ember.run(() => this.transitionTo("otherRoute"));
  }),

In my own code I had myTask calling another function that contained the transitionTo, but I don't think that's relevant to the issue.

esbanarango commented 2 years ago

Same issue when doing:

  myTask: task(function*() {
    this.router.transitionTo("otherRoute");
  }),