Skip to content

[3.13] [REGRESSION] Observers are not always triggered #18564

Open
@kanongil

Description

@kanongil

I have found a critical issue in ember 3.13+, where observers are sometimes not triggered! I have reduced this to a somewhat simple test component:

import Component from '@ember/component';
import { observer, defineProperty } from '@ember/object';

export default Component.extend({
    init() {
        this._super(...arguments);

        this.obj = { a: 0, b: 0 };
        setTimeout(() => this.updateObj(), 1);
    },

    updateObj() {
        this.beginPropertyChanges();
        this.incrementProperty('obj.a');
        this.incrementProperty('obj.b');
        this.endPropertyChanges();
    },

    objAObserver: observer('obj.a', function (target, key) {
        console.log('changed:', key, this.get(key));

        defineProperty(this, 'value', null);
    }),

    objBObserver: observer('obj.b', function (target, key) {
        console.log('changed:', key, this.get(key));
    }),
});

Expected v3.12 behaviour

Inserting the component logs:

changed: – "obj.a" – 1
changed: – "obj.b" – 1

Faulty v3.13 & v3.14.1 behaviour

Inserting the component logs:

changed: – "obj.a" – 1

Bonus info

Removing the begin/endPropertyChanges() restores the 3.12 behaviour, as well as removing the defineProperty() call.

The faulty behaviour seems tied to performing a revalidateObservers() (triggered by the defineProperty()) during a flushSyncObservers().

It is also worth to note that if the observed values are rendered into a template, it is rendered correctly.

Edit: split into two separate observers to more clearly illustrate the issue.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions