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

Detect infinite renders #4769

Open
nolanlawson opened this issue Nov 1, 2024 · 0 comments
Open

Detect infinite renders #4769

nolanlawson opened this issue Nov 1, 2024 · 0 comments

Comments

@nolanlawson
Copy link
Collaborator

If you do something like:

<template>
  {count}
</template>
export default class extends LightningElement {
  count = 0
  renderedCallback() {
    this.count++
  }
}

Then you will cause an infinite loop of microtasks (Promise.resolve()s) which is really tricky to debug. The browser will freeze, but you won't get much feedback unless you click the "pause" button in DevTools and debug yourself.

I don't know exactly how we would detect infinite loops, since there are some valid cases where you want to loop a set number of times:

  renderedCallback() {
    if (count < 5) {
      this.count++
    }
  }

Maybe we can be conservative and just detect some fixed number of re-renders (1,000? 10,000?) and throw an error (in dev mode only? maybe?).

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

No branches or pull requests

1 participant