[Bug] Router service transitionTo adds unspecified query params (with their default values)
See original GitHub issue🐞 Describe the Bug
When using the transitionTo
and replaceWith
methods on the RouterService
, 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 the transitionTo
or replaceWith
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\.js
😕 Actual Behavior
Using RouterService#transitionTo
adds query parameters that have non-null default values on the controller but were not specified in the transitionTo
call.
🤔 Expected Behavior
Using RouterService#transitionTo
should not add unspecified query parameters to the URL (it should match the (now-deprecated) Controller#transitionToRoute
and Route#transitionTo
methods.)
🌍 Environment
- Ember: - from at least 3.11.1 (earliest version the ember-twiddle example runs with) through at least 3.26.0
➕ 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
Determining their default values is expensive, because it involves instantiating the corresponding controller, even in cases where we will never visit its route.
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.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:4
- Comments:9 (3 by maintainers)
Top GitHub Comments
Just tried, it still reproduces on clean ember application with
ember-source: 3.28.4
.Yes, this came as a surprise to me as well. When moving from the deprecated
this.replaceWith
tothis.router.replaceWith
the URL now gets clogged with a lot of ugly default queryParams.Any clean way to work around this?