emberjs / emberjs/ember.js

Using `controllerName` with a parent controller that has a query-param causes assertion on Ember 2.10-beta.2.

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

Description

Our ember-try tests alerted us to a possible regression. After investigation I discovered that if a route declares a `controllerName` that matches a parent controller and that parent controller has query-params it will cause an assertion to be thrown when using a `link-to` or `this.transitionTo`.

This assertion only occurs on Ember-2.10-beta, it does not occur on Ember-2.9.

Here is a twiddle: https://ember-twiddle.com/515fb727fe1e8b39b2520ec3fae23bff

In this scenario we have an "invite key" for a user. Redeeming an invite is a multi-step [multi-route] process similar to most SaaS apps. The namespaced controller (`controllers/invite`) houses the application state for all steps in this process, including the query-param (`key`). Each of the route classes declare `controllerName: 'invite'` so their templates can interface with the `invite` controller directly.

The problem is that now two handlers (`invite` and `invite.verify`) are both using the same controller. When `transitionTo` calls into the router's `_prepareQueryParams` function, a newly added check throws this exception because both handlers are using the same query-params (https://github.com/emberjs/ember.js/commit/d1124fa8424ee71125f801bf93e361de29df8a86). The exception is also a bit non-obvious:

> Assertion Failed: You're not allowed to have more than one controller property map to the same query param key, but both `invite:key` and `invite:key` map to `key`. You can fix this by mapping one of the controller properties to a different query param key via the `as` config option, e.g. `key: { as: 'other-key' }

So why use `controllerName` at all? Why not just use an invite service to house the state from each phase of the invite process? The answer is two parts: 1) It's old code and we haven't touched it in a long long time :stuck_out_tongue_winking_eye:, but 2) there is not a clean way for a service to access query-params on the router.

--------

So yea, I know this is just another one of the crazy query-param issues that has come up. If you guys want to just ¯\\\_(ツ)_/¯, I'm happy with that. I can probably find my own work around. But as always I'm just reporting the issues I see.

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.