-
-
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] <RouterService>#transitionTo incorrectly re-runs the the model hook when query params do not change #19497
Comments
I came across a behavior which may be related to this bug. The context is as follows: parent route The parent route's controller has a To work around the issue I now call |
I'm running into this issue as well. Seems to be happening when migrating to the new |
We actually had this come up. I accidentally use this as a behavior to refresh a route without realizing this was going on until I called it twice... 🤦🏽 This is documented in the |
This is one of the aged issues #16349 |
I think I came across the same issue while migrating to ember 3.24 with native class syntax:
The component was using the router service to update query params of the child route: this.router.transitionTo({ queryParams: {} }) Or even simply the route: this.router.transitionTo(newRoute) But the parent route model's hook was re-run. Delegating the update to the child route's controller using |
We're also running into this issue when refactoring the deprecated As this issue causes a lot of extra unnecessary model calls and slows down our app it's a critical issue. A temporary workaround seems to be returning the previous model state like so: model(params, transition) {
super.model(...arguments);
// Reuse the previous model state when redirecting to, or redirected back from a child route
if (isRedirectFromOrToChildRoute(transition)) {
return this.modelFor(this.routeName);
}
// Redacted ...
}
// With isRedirectFromOrToChildRoute e.g.
isRedirectFromOrToChildRoute(transition) {
const routeNameFromStripped = transition.from?.name?.replace('.index', ''); // Can be undefined when it's the first page accessed
if (routeNameFromStripped) {
const routeNameToStripped = transition.to.name.replace('.index', '');
const isChildRoute = routeNameFromStripped.startsWith(routeNameToStripped);
const isParentRoute = routeNameToStripped.startsWith(routeNameFromStripped);
const isSameRoute = routeNameFromStripped === routeNameToStripped;
return !isSameRoute && (isChildRoute || isParentRoute);
}
return false;
} But as it's such a core functionality of routing this seems like a hacky approach ... |
I'm experiencing the same issue on ember 4.6.0 I've confirmed that if I remove the |
Also experiencing this issue on Ember 3.28.11, Ember 4.4.4 and Ember 4.9.2 Having to stick with Controller.transitionToRoute for certain calls to avoid slow page transitions |
I have confirmed the router.transitionTo problem still exists with Ember 4.12 This is now actually a problem as |
In the process of moving toward ember 5 (at least trying), the fact that The fix suggested by IgnaceMaes do not take around for redirection between siblings route (parent.childa -> parent.childb) that produces the bug too. I'm also afraid of skipping a required model update 🤷🏻 |
There are unfortunate differences between As a workaround, I suggest getting to that original |
@kategengler Thanks for your suggestion! I went with the following workaround: RouterService.reopen({
legacyTransitionTo: function () {
return getOwner(this)
.lookup('router:main')
.transitionTo(...arguments);
}, This way I can use the router service where needed with export default class MyComponent extends Component {
@service router;
@action
doX() {
this.router.legacyTransitionTo(/* ... */);
}
} Once that bug is resolved I'll just have to swap & replace |
🐞 Describe the Bug
refeshModel: true
🔬 Minimal Reproduction
Twiddle
😕 Actual Behavior
the parent model hook is re-running (in the application route in the repro)
🤔 Expected Behavior
the parent model hook should not run (as with the transitionToRoute behavior)
🌍 Environment
The text was updated successfully, but these errors were encountered: