-
-
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
[Bug] Router service transitionTo adds unspecified query params (with their default values) #19493
Comments
Just to clarify, what I mean is that the end state (at the end of the transition, not any intermediate state) includes the query params with default values added to the URL. E.g., a plain call like |
Yes, this came as a surprise to me as well. When moving from the deprecated Any clean way to work around this? |
Just ran into this as well. The only way I see around this (which may help someone) to call const url = this.router.urlFor(
'routeName',
{
someModel: 'hello'
},
{
queryParams: { qpOne: 'valueOne', qpTwo: 'valueTwo' }
}
);
this.router.transitionTo(url); However for my case at least, this is still problematic due to some other issues (potentially bugs). |
Update: This does not seem to be an issue anymore for me when running |
Whoa, the issue is just this line:
|
Here's a workaround if you're on Ember < 4.4 // app/services/router.js
import { default as EmberRouterService } from '@ember/-internals/routing/lib/services/router';
export default class RouterService extends EmberRouterService {
transitionTo(...args) {
const transition = super.transitionTo(...args);
transition._keepDefaultQueryParamValues = false;
return transition;
}
} |
@dwickern what version are you on? Do we need to backport? |
I'm on 3.28.9, trying to upgrade. I don't think a backport is needed since routing.transition-methods are supported until version 5. It's not a blocker for me. |
@wagenet too late for a backport to 3.28? |
@wagenet we would still love a backport to 3.28 here. |
@RobbieTheWagner 3.28 hasn't been supported for bug fixes since May 2022, and security fixes since September 2022. I'm not going to say never, but we're unlikely to backport this, at this point, especially since it affected back to 3.11 and so most projects will have compensated by now. |
🐞 Describe the Bug
When using the
transitionTo
andreplaceWith
methods on theRouterService
, query params that are specified on the controller for the new route, and which have default values with are non-null, are added to the resulting URL, even though they are not specified in thetransitionTo
orreplaceWith
call.🔬 Minimal Reproduction
A small reproduction (with a failing test) is here: https://ember-twiddle.com/a796bad00bded99fa45bfbaab159b485?openFiles=tests.acceptance.transition-to-query-params-test%5C.js
😕 Actual Behavior
Using
RouterService#transitionTo
adds query parameters that have non-null default values on the controller but were not specified in thetransitionTo
call.🤔 Expected Behavior
Using
RouterService#transitionTo
should not add unspecified query parameters to the URL (it should match the (now-deprecated)Controller#transitionToRoute
andRoute#transitionTo
methods.)🌍 Environment
➕ Additional Context
I know there have been a few issues about
RouterService#transitionTo
not pruning query parameters that have default values (e.g., #19492), but this is different in that it is added query parameters, with their default values. That makes sense given the Router Service RFC's note that "default values will not be stripped from generated URLs."I think the behavior described here is a bug it's adding query params that weren't specified, and it's behavior which contravenes the RFC's rationale for not pruning default-valued query params.
The RFC notes that
However, in this case, in order to 1) discover the query params, and 2) discover their default values in order to add them to the URL, the controller had to be instantiated anyway.
The text was updated successfully, but these errors were encountered: