ember.js icon indicating copy to clipboard operation
ember.js copied to clipboard

RouterService forces model to refresh when queryParams unchanged

Open ro0gr opened this issue 7 years ago • 16 comments
trafficstars

I have a query param defined in the controller and set it up to refreshModel in the route.

Then I inject the router service to the component and trigger a transition just with a sub-route name(no passing query params).

Expected: Transition is complete. Parent route's model is not reloaded.

Actual: Query param treated as changed which causes a parent route to reload.

Reproduction: https://ember-twiddle.com/efda3c9e57835c987404a8f5968c7579?openFiles=routes.application.js%2C&route=%2Fin

ro0gr avatar Mar 09 '18 17:03 ro0gr

The other interesting thing which appears in the twiddle is that default queryParams are reflected in the URL only after the second router.transitionTo() invocation.

While the Router RFC sheds some light on the default query params semantics it's still unclear how the transtitionTo should behave when no query params are passed in.

ro0gr avatar Mar 10 '18 20:03 ro0gr

This issue is very similar to https://github.com/emberjs/ember.js/issues/15801. It may have the same root cause. However this issue is reproducible without passing any query params to the router.transtionTo()

ro0gr avatar Mar 12 '18 21:03 ro0gr

I've got the similar issue right now. And I found a problem. If your QP default is a null it's always visible as a change for the router which triggers the model reloading. Try to change it to undefined or other, then it should not reload the model.

I know this is just a temporary fix. We need to find the source of the problem

Exelord avatar Mar 15 '18 12:03 Exelord

@Exelord actually in the twiddle I have a non-empty string as a default QP value.

ro0gr avatar Mar 15 '18 14:03 ro0gr

I believe that this is addressed now, @chadhietala may be able to confirm.

rwjblue avatar Dec 08 '18 03:12 rwjblue

I've just verified it against [email protected](cause its release notes say: Final stage of the router service RFC (see emberjs/rfcs#95) and the issue seems to be persited.

Here is a repo with reproduction for [email protected] if helpful.

ro0gr avatar Dec 10 '18 09:12 ro0gr

I believe this all stems back to the fact that QPs are mutable in Router.js. I haven't had the time to get back around to doing the big refactor around how QPs are treated. Right now there is a great deal of implicit behavior due to this issue. I'm going to try and get back around to soon, just been busy at work trying to wrap up some things before the end of the year.

chadhietala avatar Dec 10 '18 14:12 chadhietala

is there a work around for this? other than reloading the window.

arun-jerry avatar Nov 08 '19 08:11 arun-jerry

i tried chasing this down (making sense of the various special cases for transitions originating from the router service) and all i got were some failing tests: https://github.com/emberjs/ember.js/pull/18579

aaxelb avatar Nov 25 '19 21:11 aaxelb

Still facing this issue when using QPs (refreshModel) with router service's transitionTo API. Any help on this?

Using Ember source and CLI: 3.22

gokatz avatar Dec 15 '20 06:12 gokatz

Still facing this issue when using QPs (refreshModel) with router service's transitionTo API. Any help on this?

Using Ember source and CLI: 3.22

Same issue here

algodave avatar May 08 '21 09:05 algodave

We also ran into this issue. The workaround we are using in the meantime is not to use the QP's default value and always set it to a different value (with the drawback that it always appears in the url).

eodb avatar Jul 09 '21 09:07 eodb

Still an issue on Ember 4.4.4 and Ember 4.9.2 :cry:

Techn1x avatar Dec 21 '22 09:12 Techn1x

This is terrible, why is this not fixed yet.

PowerP avatar Aug 15 '23 07:08 PowerP

@PowerP could you submit a fix? I'll make sure to get it reviewed as soon as possible!

locks avatar Aug 15 '23 08:08 locks

Still an issue on Ember 5.4.1 😭

mkszepp avatar Feb 08 '24 14:02 mkszepp