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

Add lint for protecting people from accidental infinite loops / infinite revalidation errors #1413

Open
NullVoxPopuli opened this issue Jan 10, 2022 · 5 comments

Comments

@NullVoxPopuli
Copy link
Contributor

Coming out of:

I think we should add a lint rule in certain places known to cause issues with infinite looping

For example, in ember-concurrency tasks, if you don't yield Promise.resolve() or await Promise.resolve() (depending on your ember-concurrency syntax), you'll get the infinite revalidation error (or infinite loop).

This only happens when using concurrency tasks as derived data, such as what ember-resources encourages.

But concurrency tasks aren't the only place where this can happen -- could be in plain functions, helpers, or modifiers as well. Esp as emberjs/rfcs#756 and emberjs/rfcs#757 are implemented.

Maybe it's something we need to work with the typed-ember folks to figure out, because some of this depends on how stuff is used in the template.
Like, eslint can't possible know if a function is going to be a helper or modifier

@NullVoxPopuli
Copy link
Contributor Author

cc @dfreeman @chriskrycho ?

@NullVoxPopuli
Copy link
Contributor Author

I think maybe this could only be possible as a type-aware lint rule, and only for types of tracked-data which are not @tracked properties (as, to TS, they are just their value).

@velrest
Copy link

velrest commented Jan 6, 2025

Hi @NullVoxPopuli, Is this still ongoing or is this not really doable? We are still running into this occasionally when doing maintenance (ember/data 4 and reactiveweb). Especially for people who have never encountered this before, the github issue NullVoxPopuli/ember-resources#340 is not really easy to find if the problem occurs with trackedFunction and not ember-resources. Should i open a pr in reactive-web to add a note somewhere or do you plan on still implementing a linting solution?

@NullVoxPopuli
Copy link
Contributor Author

NullVoxPopuli commented Jan 6, 2025

I would love a lint, but i don't how to do it, specifically.
I could do a less than perfect 'best effort' attempt, ofc. There is an easy thing to look for, assignment. But i think it'd only be doable in gjs/gts, because the lists need to, best they can, analyze the reactive pulling on data

While ember-resources would benefit from some lints, the backtracking rerendering error isn't caused by them, it'd be the same if folks were using getters (resources and trackedFunction are kinda like getters)

Now, if you want to open issues and cross link everything for SEO purposes, i think that's a good idea. 🎉

@velrest
Copy link

velrest commented Jan 6, 2025

I'll do that 👌 . I think for me part of the confusion is that most of the issues related to this are about direct (in the sense that the dev added an assignment call) assignment in tracked context which is bad design and i think by now, most people know and understand this. What in our team sometimes still pops up is something like this example:

data = trackedFunction(async () => {
  const data = await this.store.findAll('users')
  return data.entries
})

As you wrote in your issue in ember-resources, this seems like its something on ember-data's side. Maybe we can add a linting rule for this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants