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

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

Closed
dai-shi opened this issue Sep 3, 2022 · 1 comment

Comments

@dai-shi
Copy link
Contributor

dai-shi commented Sep 3, 2022

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.

@dai-shi dai-shi added the Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug label Sep 3, 2022
@sammy-SC
Copy link
Contributor

sammy-SC commented Sep 9, 2022

Resolved in #25203

thank you for the report!

@sammy-SC sammy-SC closed this as completed Sep 9, 2022
@sammy-SC sammy-SC added Type: Bug and removed Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug labels Sep 9, 2022
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

2 participants