Inconsistent Loading sub-state behavior
When transitioning between routes, there are (at least?) two ways to inject a promise:
- Pass the promise to the source route's
transitionTo()method (as a model argument). - Return the promise from one of the destination route's "model hooks".
From my reading of the Asynchronous Routing and the Loading / Error Substates pages of the routing guide, these two should be interchangeable. They are not, though: depending on the method used, you can get a different loading substate.
Here is a JSBin that demonstrates the issue: http://emberjs.jsbin.com/yitan/4/
A little further investigation (using specific route names from the example JSBin):
It seems that in case (1), both the "thingy" and the "thingy.purchase" handler-infos in the transition state are unresolved, and in case (2) only the "thingy.purchase" handler-info is unresolved. That makes sense, because in case (2), the actual model object was given to the "thingy" route.
Because of this difference, in case (1), the transition's pivotHandler is the "application" route, and in case (2) it is the "thingy" route. And because of this difference, in case (1), we get the application loading substate, and in case (2) we get the thingy loading substate.
(BTW, I hope it's OK that I used "emberjs.jsbin.com" for the example JSBin...)
@nonsensery and I had a chance to talk about this at EmberConf; it's definitely not a bug, though the confusion's understandable. Basically, if you pass in a promise as a model to X route, it's going to look for a sibling loading route to enter, regardless of whether you're transitioning into X route or if you're already in one of its children. If you're in one of its children, this does imply leaving X for the sake of displaying its sibling loading route.
I'll let you close this or leave it open if there's something actionable to do here, but what you're seeing definitely isn't a bug.
Yes, definitely not a bug. Something about the way it's working still seems unintuitive, though. I'll have to think on it a bit more to crystallize my thoughts. If you're ok leaving this issue open, I'll comment again when I figure things out.
This would get more eyes on it in discuss.emberjs.com; @nonsensery would you mind starting a thread? We can reopen this or open a new issue once we have something more actionable.
Yeah, that sounds like a great idea. Will do.
@matchy I got my thoughts together, and posted a discussion topic. Thanks for giving me a reason to finally sit down and think things through.