ember-cli / ember-cli/eslint-plugin-ember

`no-assignment-of-untracked-properties-used-in-tracking-contexts` Breaks Code

Open
#1,391 4 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
JavaScript
Stars
263
Forks
214
Avg merge
30m
Merged PRs (30d)
5

Description

Consider this code:

```js
import EmberObject, { computed } from '@ember/object';

class Foo extends EmberObject {
_bar = null;
@computed()
get bar() {
if (this._bar) {
return this._bar * 2;
}
this._bar = 1;
return 2;
}
set bar(value) {
this._bar = value / 2;
}
}
```

The rule `no-assignment-of-untracked-properties-used-in-tracking-contexts` will transform this into:

```js
import EmberObject, { computed, set } from '@ember/object';

class Foo extends EmberObject {
_bar = null;
@computed('_bar')
get bar() {
if (this._bar) {
return this._bar * 2;
}
set(this, '_bar', 1);
return 2;
}
set bar(value) {
set(this, '_bar', value / 2);
}
}
```

which immediately causes an infinite loop if anything observes `bar` and you try to set the value, because the getter causes the observers on `_bar` to fire, which causes the observers on `bar` to fire, etc.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.