emberjs / emberjs/ember.js

`RouteInfo` fails on its promise of immutability

Open
#17,867 1 comment 0 reactions 1 assignee Claimed by @chadhietala View on GitHub
bug Routing
Dominant language
TypeScript
Stars
22.6k
Forks
4.2k
Avg merge
3d 12h
Merged PRs (30d)
15

Description

Given the following route definition:

**router.js**
```javascript
Router.map(function() {
this.route('foo');
});
```

The following application template:

**application/template.hbs**
```handlebars
{{#link-to "foo" (query-params someParam="someValue")}}Click me{{/link-to}}
```

And the following application controller:

**application/controller.js**
```javascript
export default Controller.extend({
router: inject(),
init(...args) {
this._super(...args);

this.router.one('routeWillChange', ({ to: routeInfo }) => {
const parent = routeInfo.parent;

this.router.recognize('/foo?someParam=someOtherValue');

console.log(routeInfo.parent === parent);
// result: false
// expectation: true

console.log(routeInfo.parent.queryParams);
// result: {someParam: "someOtherValue"}
// expectation: {someParam: "someValue"}
});
}
});
```

According to the API doc for `RouteInfo`:

> A RouteInfo is an object that contains metadata about a specific route within a Transition. It is read-only and internally immutable. It is also not observable, because a Transition instance is never changed after creation.

I was expecting all attributes of a `RouteInfo` object to be immutable. However the `RouteInfo` object that I'm getting on `Transition.to` is adversely mutated as a side effect of `RouterService.recognize()`.

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.