ember.js
ember.js copied to clipboard
create and (trying to) fix async loading of Routes
This is a follow up of https://github.com/emberjs/ember.js/pull/19266
Chatted a bit with @sly7-7 about this in discord this morning, the conclusion we came to was that Ember should never attempt to enter into a loading or error route that itself is not loaded.
I believe that @sly7-7 is going to update this code:
https://github.com/emberjs/ember.js/blob/b945e5c963fc75950186bd2c4213614ea253e8b0/packages/%40ember/-internals/routing/lib/system/router.ts#L1411-L1416
Check that getRoute returns a non-promise before returning true.
Something like:
function routeHasBeenDefined(owner: Owner, router: any, localName: string, fullName: string) {
let routerHasRoute = router.hasRoute(fullName);
if (routeHasRoute && !isPromise(router.getRoute(fullName))) {
let ownerHasRoute =
owner.hasRegistration(`template:${localName}`) || owner.hasRegistration(`route:${localName}`);
return ownerHasRoute;
}
return false;
}
@rwjblue Hi, so I've played with that PR, and I'm blocked, mainly because I miss knowledge on the testing infrastructure, and also when it comes to engines. It seems to me that I need some waiters helpers (in order to check the loading states), but I couldn't find a way to make them work. Also, I noted this test: https://github.com/emberjs/ember.js/blob/master/packages/@ember/-internals/glimmer/tests/integration/application/engine-test.js#L26 use quite but not the same routerOptions() as in the 'helper' I created. I was wondering if their purposes are the same or not. Let me know when we can eventually schedule a chat to talk about that, or if you see what I mean here, you could also help me with tiny snippets here. As you prefer :)
Is this still relevant?
@kategengler I'm sorry I didn't notice your question until now 😞 I don't know if this is still relevant, as far as I remember, an error could happen when a route is loaded by an engine. There was also a PR in the router https://github.com/tildeio/router.js/pull/322 and quickly looking at the code this one may be still relevant (but lack of tests that I failed to write). I don't know if the router in ember has been touched sinced 3 years now, but if nothing has changed, then maybe this PR also could be relevant. I've never encountered this use-case in prod app, so I couldn't tell if the bug mentioned could really occur.