question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[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:closed
  • Created 2 years ago
  • Reactions:4
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
nag5000commented, Oct 26, 2021

Update: This does not seem to be an issue anymore for me when running ember-source: 3.28.4.

Just tried, it still reproduces on clean ember application with ember-source: 3.28.4.

image

1reaction
johanrdcommented, Sep 6, 2021

Yes, this came as a surprise to me as well. When moving from the deprecated this.replaceWith to this.router.replaceWith the URL now gets clogged with a lot of ugly default queryParams.

Any clean way to work around this?

Read more comments on GitHub >

github_iconTop Results From Across the Web

[Bug] No way to reset query parameters when transitioning to ...
resetController hook to set query param values back to their defaults before exiting the route or changing the route's model. However, when ...
Read more >
Changing query params in transitionTo doesn't seem work
Here is an example from the doc: Query Parameters - Routing ... and that I have specified their default values to be an...
Read more >
ember.js - Query-params-new nested routes strange error
This strange error only happens when I first clicked a Category so the queryParam category is changed, and then fire a transitionTo to...
Read more >
Routing: Query Parameters - Ember.js - GitHub Pages
Specifying Query Parameters. Query params are baked right into your routes. This is essential so that the router and helpers can know what...
Read more >
RouterLink - Angular
Note that a value of undefined here will use the routerLink default. ... The following link adds a query parameter and a fragment...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found