@dlindquist-egistix wrote:
I’m encountering a “You’ve modified xxx twice in a single render” error when using ember-concurrency tasks inside computed properties.
Here’s an extremely minimal example of a component that demonstrates the problem:
double-render-bug.js:
import Ember from 'ember'; import { task, timeout } from 'ember-concurrency'; export default Ember.Component.extend({ task: task(function * () { yield timeout(1000); return 'done'; }), taskInstance: Ember.computed(function() { return this.get('task').perform(); }), resultValue: Ember.computed.alias('taskInstance.value'), isRunning: Ember.computed.alias('task.isRunning'), });
double-render-bug.hbs:
{{isRunning}} / {{resultValue}}
The main purpose behind the real version of this is to use computed properties to have my data automatically loaded (and then transformed and rendered) when parameters (for example ‘month’ or something) are changed. The methodology works beautifully, except when I try to use the ‘isRunning’ value to determine whether my data is currently loading or not.
It appears that what happens is:
- The getter for
isRunning
is fired, and ember-concurrency returns ‘false’, since no task instance has yet been created.- Then the getter for
resultValue
is fired, which in turn causes the task to be performed. Internally, ember-concurrency then sets the ‘isRunning’ value totrue
, which in turn causes myEmber.computed.alias
to be re-evaluated.- Everything blows up, since the
isRunning
is being “modified twice”.Is this a bug in ember? Is this a bug in ember-concurrency? Do I have any practical recourse, other than some complicated ‘debounce’ on the isRunning flag?
(NOTE - to see this work successfully, simply change the
isRunning
to a hard-coded value, likefalse
.)Thanks in advance!
Posts: 1
Participants: 1