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;
}
This code will cause an infinite loop. The effect hook will fail to update the
lastValues
, because of the error stopping the execution ofcall
. 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.I will submit a potential fix momentarily.