emberjs / emberjs/ember.js

Template does not get updated with tracked (computed) getter

Open
#18,988 13 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
22.6k
Forks
4.2k
Avg merge
3d 12h
Merged PRs (30d)
15

Description

I have a pretty weird bug which only happens on production build.

This is the component

```js
import { tracked } from '@glimmer/tracking';
import classic from 'ember-classic-decorator';
import ModalBase from 'open-event-frontend/components/modals/modal-base';

@classic
export default class EventDeleteModal extends ModalBase {
isSmall = true;
@tracked confirmName = '';

get isNameDifferent() {
return this.eventName ? this.confirmName !== this.eventName : true;
}
}
```

This is the template:

```hbs


{{t 'Are you sure you would like to delete this event?'}}

{{t 'Deleting the event will delete all the data associated with it.'}}






{{t 'Please enter the full name of the event to continue'}}







{{t 'Cancel'}}


{{t 'Delete Event'}}


```

As you can see, the delete button should get enabled only when confirmName == eventName, which it does on debug build, in production build, it doesn't. I used ember devtools to check if tracked property `isNameDifferent` is being recomputed and it is, it changes to `false` when I type event name, but the button is not enabled. Now comes the weirdest part, when I added a console log statement in the getter:

```js
get isNameDifferent() {
console.log(this.eventName, this.confirmName, this.eventName ? this.confirmName !== this.eventName : true);
return this.eventName ? this.confirmName !== this.eventName : true;
}
```

It starts working correctly, I tried multiple times and it only starts working in production build when I add this console.log statement. I thought this was a bug in autotracking but the computed property is recalculated anyway even when it doesn't update the template/HTML, so I have no idea why it is not working.

This started happening right after I migrated to tracked properties https://github.com/fossasia/open-event-frontend/commit/28015051bdc71425e66e8a5734096cb592d4439a

Upstream Issue: https://github.com/fossasia/open-event-frontend/issues/4383

Ember Versions:

```
"ember-cli": "~3.18.0",
"ember-source": "~3.18.1",
```

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.