emberjs / emberjs/ember.js

TransitionTo with queryParams refreshModel triggers model calls on other routes

Open
#15,801 14 comments 24 reactions 0 assignees View on GitHub
Has Reproduction Query Params Routing
Dominant language
TypeScript
Stars
22.6k
Forks
4.2k
Avg merge
3d 12h
Merged PRs (30d)
15

Description

# Description

It appears that calling `transitionTo` with queryParams on a nested route can trigger calls to the lower route if that route has a `refreshModel: true` on an unchanged queryParam. [Reproduction](https://github.com/Boudewijn26/ember-transition)

So I have this setup:
somewhere -> `somewhereParam` with `refreshModel: true` with default null
somewhere.nested -> `nestedParam`

In somewhere.nested I have a component which triggers a transition on the router service where nestedParam is changed. This trigger the model on somewhere to be called and then transitioning through the controller then triggers another call.

# Cause

I did some digging and it appears that the call to [`route#finalizeQueryParamChange`](https://github.com/emberjs/ember.js/blob/d487061228a966d8aac6fa94a8d69abfc3f1f257/packages/ember-routing/lib/system/route.js#L818) returns the incorrect values, because the `transition._keepDefaultQueryParams` isn't set. This is set in [`router#transitionTo`](https://github.com/emberjs/ember.js/blob/master/packages/ember-routing/lib/services/router.js#L157), but only after the call. The call does return a promise, so `transition._keepDefaultQueryParams = true` may actually be executed in time, but I found this to be very flaky.

I'm more than willing to help fix this, however it is embedded so deeply that I find it difficult to pick the right approach.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.