You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Module Unification] Routes can only be nested two levels deep #17217
Defining routes nested more than two levels deep or even just providing a callback does not work MU applications and triggers the error below.
requirejs.js:74 Uncaught TypeError: Cannot read property 'defaultType' of undefined
at RequireJSRegistry._checkDefaultType (requirejs.js:74)
at RequireJSRegistry._detectModule (requirejs.js:63)
at RequireJSRegistry.has (requirejs.js:85)
at Resolver._serializeAndVerify (resolver.js:118)
at Resolver.identify (resolver.js:94)
at Resolver.resolve (resolver.js:104)
at Class.resolve (index.js:149)
at Class.resolve (index.js:15)
at Class.superWrapper [as resolve] (utils.js:308)
at _resolve (container.js:807)
Exemplary failing router:
Router.map(function(){// this failsthis.route('foo',function(){this.route('bar',function(){// You don't even need to register a third-level route. Just providing the// callback triggers the error, likely because of the implicit `index` route.// this.route('qux');});});// this works just finethis.route('one',function(){this.route('two');});});
The problem seems to be somewhere in glimmer-resolver/resolver.ts#identify. Routes generate non-sensical specifiers with an IMO incorrect rootName property:
@NullVoxPopuli I am already using the fallback resolver, as can be seen here. But that is actually a very good point to make. I'll give the glimmer-wrapper a try instead. Thanks a lot!
Ha! I just found out that this only happens, if the third-level Route or Controller are auto-generated. If the app actually provides a route.js and controller.js, there's no error. I've updated the reproduction repo to show this as well.
The resolver cannot find the Controller, as it is not explicitly defined and thus should be auto-generated. But before resorting to auto-generation, the resolver tries as to find a fitting addon first in L92-L100.
However this does not fix the inconsistent de-/serialization. But is this actually a problem we need to worry about? The input specifier already looks off to me.
In any case, I'll prep a PR for the above fix and test it.
Activity
buschtoens commentedon Nov 20, 2018
The problem seems to be somewhere in
glimmer-resolver/resolver.ts#identify. Routes generate non-sensical specifiers with an IMO incorrectrootNameproperty:I think it should rather look like this:
Or maybe?
buschtoens commentedon Nov 20, 2018
I assume the
glimmer-wrapperinember-resolveris the correct place to submit a failing test case to.NullVoxPopuli commentedon Nov 20, 2018
@buschtoens have you tried the fallback resolver?
the fallback resolver is currently what https://emberclear.io uses
buschtoens commentedon Nov 20, 2018
@NullVoxPopuli I am already using the fallback resolver, as can be seen here. But that is actually a very good point to make. I'll give the
glimmer-wrappera try instead. Thanks a lot!buschtoens commentedon Nov 20, 2018
@NullVoxPopuli No luck here. Apparently
fallbackandglimmer-wrapperuse the same buggy code paths.fallbackfirst tries theglimmer-wrapperresolver, and if that one cannot find a result, will fall back to the classic resolver:https://github.com/ember-cli/ember-resolver/blob/7647d14d242b08d40305dfdbef2e028f1a19b4de/mu-trees/addon/resolvers/fallback/index.js#L6-L15
NullVoxPopuli commentedon Nov 20, 2018
excellent! (one less thing to fix)
buschtoens commentedon Nov 20, 2018
Ha! I just found out that this only happens, if the third-level
RouteorControllerare auto-generated. If the app actually provides aroute.jsandcontroller.js, there's no error. I've updated the reproduction repo to show this as well.buschtoens commentedon Nov 20, 2018
I think I've pinned down the issue. So in L90
slooks like this:The resolver cannot find the
Controller, as it is not explicitly defined and thus should be auto-generated. But before resorting to auto-generation, the resolver tries as to find a fitting addon first inL92-L100.sthen looks like this:This is then serialized as
controller:/foo/bar/routes/indexin_serializeAndVerifybyserializeSpecifier. It is then deserialized inhasas:Notice how this differs from the prior specifier:
{ type: "controller", name: "index", - namespace: undefined, + namespace: "routes", - collection: "routes", + collection: "bar", - rootName: "foo/bar" + rootName: "foo" }What ultimately causes the
TypeErrorthen is that that_checkDefaultTypeexpects the specified collection to always exist:A simple fix to make this safer would be:
However this does not fix the inconsistent de-/serialization. But is this actually a problem we need to worry about? The input specifier already looks off to me.
In any case, I'll prep a PR for the above fix and test it.
test(module-registries/requirejs): regression test for emberjs/ember.…
test(module-registries/requirejs): regression test for emberjs/ember.…
gossi commentedon Dec 29, 2018
This can be marked as closed 😃 Maybe cut a release for ember-resolver that contains the fix (it's already on master)
locks commentedon May 30, 2019
Closing, thanks!