machty / ember-concurrency

ember-concurrency is an Ember Addon that enables you to write concise, worry-free, cancelable, restartable, asynchronous tasks.
http://ember-concurrency.com
MIT License
691 stars 157 forks source link

You attempted to update `numRunning` on `<Task:[TASK_NAME]>`, but it had already been used previously in the same computation. #378

Open yoavfranco opened 3 years ago

yoavfranco commented 3 years ago

Hey there, I'm getting some strange error when trying to use the isRunning property on the Task (not the TaskInstance)

This is the full error:

backburner.js:352 Error: Assertion Failed: You attempted to update `numRunning` on `<Task:renderStructure>`, but it had already been used previously in the same computation.  Attempting to update a value after using it in a computation can cause logical errors, infinite revalidation bugs, and performance issues, and is not supported.

numRunning` was first used:

- While rendering:

  application
    brands
      brands.brand-version
        brands.brand-version.print-store
          application
            designs
              business-card-sample
                this.renderStructure.isRunning

Stack trace for the update:
    at dirtyTagFor (validator.js:541)
    at markObjectAsDirty (index.js:546)
    at notifyPropertyChange (index.js:584)
    at Object.set (index.js:1530)
    at Class._startTaskInstance (-scheduler.js:106)
    at Class._flushQueues (-scheduler.js:81)
    at Class.schedule (-scheduler.js:63) undefined

My code looks like this:

{{#if this.renderStructure.isRunning}}
   // ... Do stuff
{{/if}}
<ChildComponent @renderStructure={{this.renderStructure}}/>
<ChildComponent @renderStructure={{this.renderStructure}}/>

I have a parent component that passes the task renderStructure to two identical child components. I want to able to tell once all child component finish processing.

My env: ember-cli: "3.20.0" ember-source: "3.20.5" ember-concurrency: "1.3.0", ember-concurrency-decorators: "2.0.1",

yoavfranco commented 3 years ago

In the meantime I've done a very poor workaround (that works) by replacing this:

{{#if this.renderStructure.isRunning}}
   // ... Do stuff
{{/if}}

With this:

{{#if (not (eq this.renderStructure.performCount 2))}}
   // ... Do stuff
{{/if}}
maxfierke commented 3 years ago

@yoavfranco how are you performing the tasks? can you post a snippet for that?

yoavfranco commented 3 years ago

@maxfierke sure thing πŸ‘

This is the child component.js:

  constructor() {
    super(...arguments);
    this.renderStructureSide.perform();
  }

  @action
  onThemeColorUpdate() {
    next(this, function () {
      this.renderStructureSide.perform();
    });
  }

(Please note that I've removed the next, and it still reproduces)

This is the component.hbs:

<div  {{did-update this.onThemeColorUpdate this.themeColor}}>
  <div class="w-full h-full" style="{{backgroundImageData}}"/>
</div>
maxfierke commented 3 years ago

@yoavfranco can you verify that there are no other versions of ember-concurrency in your lockfile that might be getting loaded instead of 1.3.0?

yoavfranco commented 3 years ago

@maxfierke I see this when I npm ls ember-concurrency:

β”œβ”€β”€ ember-concurrency@1.3.0 
└─┬ ember-power-select@4.0.3
  └── ember-concurrency@1.2.1 

Update: I've updated ember-power-select to 4.0.5 and installed everything.

The issue still persists :(

maxfierke commented 3 years ago

hmmm... nothing stands out as problematic there. If you could put together an Ember Twiddle, a failing test, or a GitHub repo that reproduces it, that would be aces! Otherwise, I can try to put something together in the next week or so to see if I can reproduce it and dig into it.

yoavfranco commented 3 years ago

@maxfierke I'll try to get to it, if possible, in the next couple of days Thanks 😊

maxfierke commented 3 years ago

Heyo, just updating this issue to point out that the state-tracking has been rewritten and is much more robust in ember-concurrency 2.0.0, especially with regards to avoiding re-computation during state updates. Please give that a try and let me know if this is still an issue in ember-concurrency 2.0.0+.

yoavfranco commented 3 years ago

Heyo, just updating this issue to point out that the state-tracking has been rewritten and is much more robust in ember-concurrency 2.0.0, especially with regards to avoiding re-computation during state updates. Please give that a try and let me know if this is still an issue in ember-concurrency 2.0.0+.

Awesome news! Thanks for the update. We'll give it a try πŸ™