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

Infinite loop if effect schedules an update and then throws #468

Closed
cristinecula opened this issue Mar 22, 2023 · 0 comments · Fixed by Neovici/haunted#23 · May be fixed by #469
Closed

Infinite loop if effect schedules an update and then throws #468

cristinecula opened this issue Mar 22, 2023 · 0 comments · Fixed by Neovici/haunted#23 · May be fixed by #469

Comments

@cristinecula
Copy link
Contributor

This code will cause an infinite loop. The effect hook will fail to update the lastValues, because of the error stopping the execution of call. This means that on the next render, the effect will run again, even though the deps array is still [], thus scheduling another update, causing the infinite loop.

  function App() {
      const [state, setState] = useState(0);

      useEffect(() => {
        // an update is scheduled
        setState((state) => state! + 1);
        // an error is thrown
        throw new Error("Unexpected error");
      }, []);

      return state;
    }

I will submit a potential fix momentarily.

cristinecula added a commit to Neovici/haunted that referenced this issue Mar 22, 2023
Update lastValues before running the callback.

Fixes matthewp#468
cristinecula added a commit to Neovici/haunted that referenced this issue Mar 22, 2023
Update lastValues before running the callback.

Fixes matthewp#468
cristinecula added a commit to Neovici/haunted that referenced this issue May 15, 2023
Update lastValues before running the callback.

Fixes matthewp#468
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant