-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot read property 'name' of undefined when trying to set queryParams in beforeModel #17118
Comments
@ohcibi well if creating an example reproduction of the issue in a twiddle is not working out, perhaps create an example project and share the link to clone the repository. |
I was able to do that in the meantime... I pushed it to https://github.com/ohcibi/erstifahrt and pushed the |
Any update on this? |
@dodeja do you have another example that differs from mine? If yes, please provide it as this issue seems to be more complicated than expected. |
@pixelhandler have you been able looking into the example yet? Is it a valid example or is anything else needed? |
I stumbled with this too, I'm using Facts I know: login(credentials).then( () =>
this.router.transitionTo('route.name', { queryParams: { userId: 5 } )
) But I if I wrap the transitionTo with a login(credentials).then( () =>
setTimeout( () => //maybe a { next } from @ember/runloop might do it.
this.router.transitionTo('route.name', { queryParams: { userId: 5 } ),
1000 )
) It works... I know maybe the |
It seems, But at the same time I'm also triggering a transition to the same route but with queryParams (my app is served as an iframe, so external consumers send actions down to my ember app via postMessage API, and I can't control when they do it), and that's when I get this error. If I instead try transitionTo another route, (not the same one) it works, without issue, as expected, it's like I need to wait to the router/transition to settle down, before I can attempt a new transition, to the same route. I truly don't know about internals here, but it comes to my mind something like
Or maybe its something that can be handled internally? |
I ran into this issue as well. The solution I came up with is to do a full transition.abort then retry inside a run.next block.
|
You probably don't want to do what I posted since it will trigger the transition.to's model hooks before retrying. I can confirm that this is only an issue when trying to transitionTo the same route but with different query params. It does look like it is supported per the docs: https://guides.emberjs.com/release/routing/query-params/#toc_transitionto
Is exactly what I am trying to do. I'm on 3.7.x for ember. |
I can only replicate this actually when running tests. Calling |
So this error only occurs when doing a query param only transition during the initial visit? |
@rwjblue when I created the issue the tasks I wanted to solve involved exactly that. If I recall correctly I even found out that this doesn’t happened when the page was loaded initially before that route was hit. |
Here is a twiddle that shows the error: https://ember-twiddle.com/7515eb58d0e64666b27bcb9fe9b3adfc/faba6dcc7af61662e0b201b3833571a155cd90d0?openFiles=routes.application.js%2C&route=%2F%3Fsome%3Dthing |
You can avoid the error by using |
I'm getting this error as well when trying to |
FWIW this issue is still present in @rwjblue re your question:
Yes, that is correct. |
@rwjblue Rob - My solution here: #14875 (comment) Wanted to tag others in here because I ran into the solution. |
@ohcibi In case you are still interrested, I've taken your example and updated it to run against ember.js and the router.js both on master branch. The app appears loading correctly, and the query params also seems correctly updated. But there was still an error in the console. cc/ @rwjblue |
@sly7-7 so from your testing it looks like tildeio/router.js#303 may fix the issue here if/when it gets merged? |
I would say 'maybe' actually, because there is an other similar issue here (with the same symptoms): #11563 in which it seems like tildeio/router.js#303 is not enough :( |
This is mostly a mechanical replacement of transitionTo/transitionToRoute with this.router.transitionTo. There’s a new test helper in web-client called visitWithQueryFix to bypass failures described in this issue: emberjs/ember.js#17118
I'm getting the error
TypeError: Cannot read property 'name' of undefined
when trying tothis.transitionTo({ queryParams: { somParam: 'someValue' } })
in this very line:ember.js/packages/@ember/-internals/routing/lib/system/router.ts
Line 1083 in bef8602
I debugged it and it appears that
routeInfos
is an empty array and therefore that line must throw naturally. As I am unable to reproduce it in a twiddle and have no clue how to debug this further, I'd like to know what an emptyrouteInfos
array actually means here and if this is an error after all or rather a bug? When looking at my app, it works as expected, i.e. the query parameter does get set and the URL in the browser is updated accordingly. So this is not an issue about the query parameter not being set.For the matter of this issue, I'd say a check if that array is empty and a better error message should be added. I can't PR this as I don't understand the internals here, otherwise I would.
The text was updated successfully, but these errors were encountered: