Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUGFIX release] Prevents observer re-entry #18462

Merged
merged 1 commit into from
Oct 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/@ember/-internals/metal/lib/observer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,9 @@ export function flushSyncObservers() {
observer.suspended = true;
sendEvent(target, eventName, [target, observer.path]);
} finally {
observer.suspended = false;
observer.tag = combine(getChainTagsForKey(target, observer.path));
observer.lastRevision = value(observer.tag);
observer.suspended = false;
}
}
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { run } from '@ember/runloop';
import { observer, get, set } from '@ember/-internals/metal';
import { alias, observer, get, set } from '@ember/-internals/metal';
import EmberObject from '../../../lib/system/object';
import { moduleFor, AbstractTestCase, runLoopSettled } from 'internal-test-helpers';

Expand Down Expand Up @@ -261,5 +261,36 @@ moduleFor(

assert.equal(changed, true, 'child should have been notified of change to path');
}

async ['@test cannot re-enter observer while it is flushing'](assert) {
let changed = false;

let Class = EmberObject.extend({
bar: 0,

get foo() {
// side effects during creation, setting a value and running through
// sync observers for a second time.
return this.incrementProperty('bar');
},

// Ensures we get `foo` eagerly when attempting to observe it
fooAlias: alias('foo'),

parentOneTwoDidChange: observer({
dependentKeys: ['fooAlias'],
fn() {
changed = true;
},
sync: true,
}),
});

let obj = Class.create();

obj.notifyPropertyChange('foo');

assert.equal(changed, true, 'observer fired successfully');
}
}
);