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
690 stars 157 forks source link

"Assertion Failed: You attempted to update `lastStarted` ..." #350

Closed Subaku closed 4 years ago

Subaku commented 4 years ago

Hi,

I think this belongs here and not elsewhere. I've poked at updating my version of ember from pre 3.15.0 to 3.16.x. Seems 3.15.0 has a breaking bug fix that's affected this addon. I'm essentially getting the above assertion error on page load trying to use tasks to load my data. I've set up a repo of a minimal reproduction here.

I simply set it up based on how I'm using it in my app which is in a controller kicking off a task on page load based on query params. Then accessing one of those tasks for giving options to ember-power-select I get the error.

Note that trying out what's suggested in #343 seems to help. Using things like lastSuccessful and lastRunning instead of last works.

Let me know if you need more info.

Subaku commented 4 years ago

I forgot to mention something important I noticed about this. When you build for production this doesn't seem to happen...

maxfierke commented 4 years ago

@Subaku

I'll try it out later tonight, but my best guess is that this might be due to calling the task within a computed property. I think 3.15 added a number of assertions to prevent mutations inside of things like computed or tracked properties:

https://github.com/Subaku/ember-render-assertion/blob/f05f952173efabe570d729ffae472b8179c6b696/app/controllers/index.js#L13-L18

Subaku commented 4 years ago

Thanks mate, I appreciate you looking at it. Let me know what you find!

maxfierke commented 4 years ago

@Subaku yeah, I think what's happening here is correct. Because both computed properties are getting calculated during initial render, there's a computed property that depends on task.last (so it gets read) and task.last is getting set (mutated) by the call to testTask.perform in selectedParam. Mutating other properties or calling tasks within computed properties has always been somewhat unsafe, but is now pretty strictly disallowed in 3.15 and up. You'll need to find a different way to do what you want without having the task called inside a computed property.

I'm going to close this as an issue, but feel free to join us in the #e-concurrency channel on the Ember Community Discord chat if you want to discuss your specific case with others and solicit ideas.