Bug: useReducer bail-out w/ useEffect + Suspense causes infinite loop (StrictMode error with next/experimental builds)

This issue has been tracked since 2022-09-03.

I just found our lib doesn't pass tests with latest build (unreleased ones). pmndrs/jotai#1370

React version: 18.3.0-next-3d443cad7-20220823

Steps To Reproduce

const Component = () => {
  const [count, dispatch] = useReducer((prev) => prev, 0);
  useEffect(() => {
    dispatch();
  }, []);
  return <>{count}</>;
};

const App = () => (
  <Suspense>
    <Component />
  </Suspense>
);

Maximum update depth exceeded. This can happen when a component repeatedly calls setState inside componentWillUpdate or componentDidUpdate. React limits the number of nested updates to prevent infinite loops.

Link to code example: https://codesandbox.io/s/focused-andras-p9qyxu?file=/src/App.js

The current behavior

Warning in StrictMode.

The expected behavior

No warning in StrictMode.

#25049 seems related. I'm not sure if it's a bug or a misusage.

sammy-SC wrote this answer on 2022-09-09

Resolved in #25203

thank you for the report!

More Details About Repo
Owner Name facebook
Repo Name react
Full Name facebook/react
Language JavaScript
Created Date 2013-05-24
Updated Date 2022-10-03
Star Count 195549
Watcher Count 6650
Fork Count 40505
Issue Count 1119

YOU MAY BE INTERESTED

Issue Title Created Date Updated Date