Skip to content

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

@dai-shi

Description

@dai-shi

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions