-
-
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
Don't refresh a parent route's model when the query param doesn't change #19453
Conversation
f07bf26
to
1918f84
Compare
@misterbyrne Thank you :). I'm trying to figure out how the router works these days, and I discovered https://github.com/emberjs/rfcs/blob/master/text/0095-router-service.md#query-parameter-semantics which I think is what you describe. So I would say the behavior is intented. That beeing said I find that inconsistent behavior may be error prone. cc/ @rwjblue |
|
||
await this.visit('/?parentParam=parentParamDefaultValue'); | ||
assert.equal(parentModelHookCallCount, 1); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm curious what is the this.routerService.currentURL at this point and if it would be the same as the actual url that would appear in the browser location.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting question! I just checked, and it's /?parentParam=parentParamDefaultValue
.
I think this is because it's the result of this.visit
. If I transition to the same URL using the transitionTo
then default value is stripped out of the URL, e.g.
await this.visit('/');
assert.equal(this.routerService.currentURL, '/'); // passes
await this.routerService.transitionTo('/?parentParam=parentParamDefaultValue');
assert.equal(this.routerService.currentURL, '/'); // passes
await this.visit('/?parentParam=parentParamDefaultValue');
assert.equal(this.routerService.currentURL, '/'); // fails
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems intentional because visit
ends up calling handleURL
which has a comment that explains...
// Perform a URL-based transition, but don't change
// the URL afterward, since it already happened.
d91adf2
to
3675eef
Compare
…he model hook for parent routes
3675eef
to
b45baa7
Compare
As we plan to rework the router for Polaris, we're hesitant to touch existing router code (every bug we fix is one someone else relies upon). |
Test case for #17494
Plus a potential (if a bit messy) fix.
Routes that have a query param with a default value and
refreshModel: true
, will be refreshed each time a transition happens - but only if that transition is invoke from the router service.This works as expected if you invoke the transition using the internal router. This is because a some of the internal router's related behaviour is explicitly bimodal - there's a boolean parameter named
_fromRouterService
that controls this.The root of the problem seems to be in the
_pruneDefaultQueryParamValues
method. If a transition is invoked from the router service, this currently strips default query params. This means that when later compared to the current state, the query params appear unequal, resulting in a refresh.I've added a fix which prevents the default param values from being stripped for this specific invocation - with yet another boolean param (named
_pruneDefaultQueryParamValues
). Not ideal.