-
Notifications
You must be signed in to change notification settings - Fork 37
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
Infinite loop with ember-data query and ember-concurrency #340
Comments
what happens if you add |
@NullVoxPopuli Hmm, that fixes the issue completely, why though? |
There is some discussion here: emberjs/rfcs#769 but regarding ember-resources, what this allows is that before any personally, I think we need a lint rule for this kinda stuff -- but I haven't had time to PR to eslint-plugin-ember. maybe @bmish has cycles ;)
|
@NullVoxPopuli can you file a ticket with that lint rule idea? |
sure thing! |
Thanks for reporting @anehx ! We'll hopefully / eventually be able to come up with something to help guide developers towards not running in to this problem in the future <3 |
Now it makes sense. I think a linter rule is a good compromise for now to help people with that issue since that behaviour is not really well known. Thanks for looking into it @NullVoxPopuli ! |
@NullVoxPopuli first of great work with this addon I really like it! |
eee <3 thanks!
To talk about why it can be needed, it's helpful to talk about what you can do without it. class Demo {
@tracked firstName;
@tracked appName
getName = useTask(this, this._getName);
@task
*_getName() {
let { firstName } = this;
return yield getFullName(firstName);
}
} Hello, {{this.getName.value}} so, what happens then So, what happens if we set data after the yield? @task
*_getName() {
let { firstName } = this;
let result = yield getFullName(firstName);
this.firstName = result.split(' ')[0];
return result;
} Things "just work as expected" because _auto tracking is synchronous. the tldr: is that, synchrnously, auto-tracking works like this:
And because new now know about those other references, we know that when one of those references changes, the reference in template should be called again. (in this case the tldr as code (super tldr): openFrame();
// ... ✂️ (no await)
this.getName.value;
// record every encountered tracked thing
closeFrame(); So, then what happens when we assign firstName before the await/yield? @task
*_getName() {
this.firstName = this.firstName.split().reverse().join('');
return yield getFullName(this.firstName);
} When that assignment happens, we're instructing the renderer / VM to queue an update.
Or said in a framework-agnostic way (this problem exists in every framework)
So how does @task
*_getName() {
await Promise.resolve();
this.firstName = this.firstName.split().reverse().join('');
return yield getFullName(this.firstName);
} Looking back out our super tldr auto-tracking implementation: openFrame();
// ... ✂️ (no await)
this.getName.value;
// record every encountered tracked thing
closeFrame(); anything asynchronous that occurs during It's this classic example of async timing: async function doWork() {
await Promise.resolve();
console.log('a')
}
console.log('b');
doWork();
console.log('c'); spoileroutput is:
so any interaction with tracked data here in this last example evades the infinite invalidation assertion. So does does this come in to play with the problem from the original issue report? (thanks again for the repro-repo, @anehx ) @task
*fetchUsers() {
return yield this.store.query('user', {});
} It's a bit dubious, because all the details are hidden.
There must be something going inside
which thing are you referencing? the |
@NullVoxPopuli that explanation makes total sense, I had previously read https://www.pzuraq.com/how-autotracking-works/ but guess I didn't fully understand it before. |
I was using the additional |
Hi
First of all, thanks for this awesome addon - I'm using it a lot. Sadly, I've run into a bug with a very common use case: I have a task that fetches some data via
ember-data
.query
method. This task is triggered byuseTask
. However, this results in an infinite loop of fetching. Somehow the query triggers a tracking update which then causes the task to be run again and so on.I prepared an app that reproduces the problem: https://github.com/anehx/ember-resources-bug
The text was updated successfully, but these errors were encountered: