More robustly fully scope query params#14040
More robustly fully scope query params#14040alisdair wants to merge 3 commits intoemberjs:masterfrom
Conversation
|
This may be correct (it is somewhat hard to reason about), but I'm hesitant to land this without a regression test. |
|
@rwjblue Thanks for the poke. I've added a test that I hope makes sense. |
|
Tried this fix on our project using 2.7 and it worked! |
|
|
||
| App.FooRoute = Route.extend({ | ||
| beforeModel() { | ||
| this.transitionTo('bar', { queryParams: undefined }); |
There was a problem hiding this comment.
Does this error only occur when explicitly passing undefined? Would the following also fail:
this.transitionTo('bar');
// or
this.transitionTo('bar', {});?
There was a problem hiding this comment.
Yes, the error only seems to occur when passing undefined. I still don't know what elsewhere in the system is causing something to call transitionTo('…', { queryParams: undefined }), but that's the cause of all the app errors.
Here's the code which is trying to guess if we have queryParams or not:
let possibleQueryParams = args[args.length - 1];
if (possibleQueryParams && possibleQueryParams.hasOwnProperty('queryParams')) {
queryParams = args.pop().queryParams;
} else {
queryParams = {};
}So:
this.transitionTo('bar')works fine without my change, becausepossibleQueryParamsis falsy and so we hit the second block of theifthis.transitionTo('bar', {})also hits the second block of theif, because{}fails the second condition, but then (for unrelated reasons) then results in "Error: More context objects were passed than there are dynamic segments for the route: bar".
There was a problem hiding this comment.
Hmm. I would really like to understand what is actually causing the queryParams object to be undefined....
There was a problem hiding this comment.
Me too, but I have no idea how I can possibly find that out. I've looked through the router code as closely as I can, and haven't found any possible explanation. Nor have I found any reproduction in development. Any suggestions?
Is understanding the root cause a blocker to getting this merged? I know it's a band-aid for the underlying problem, but the code-path causing this crash still seems like incorrect behaviour to me, even if we don't know what's triggering it.
|
Digging through a few stack traces a little further, it looks like the invalid In let queryParams = get(this, 'queryParams.values');But in I have no idea what is happening in the internals here. I don't know what |
|
replaced by #14068 |
Fixes #14010.
Unfortunately I can't add a test for this change, as I don't have a reliable reproduction for the bug. But in production I'm seeing exceptions indicating that
queryParamsis undefined in some cases, and it seems reasonable for this function to be robust to that case by shortcut-return.