Bug: React 18 + useEffect cleanup runs immediately after render #24431
Labels
Resolution: Expected Behavior
Status: Unconfirmed
A potential issue that we haven't yet confirmed as a bug
React version: 19
Steps To Reproduce
Here is a bare-bones react app with one
useEffect
: https://github.com/tianhuil/use-effect-demo/In this one, we log the cleanup side effect to console in v18, which you can verify by running
pnpm dev
and inspecting the console.In the next commit we do the same thing in v17, which does not print the same log statement in the console.
Impact
This is pretty important. The cleanup function is used for unsubscribing from listeners and DB subscriptions. This behavior kills those listeners and subscriptions before the first fetch completes!
The current behavior
I expect v18
useEffect
cleanup runs immediately (not at unmount)The expected behavior
I expect v18 to behave as v17.
The text was updated successfully, but these errors were encountered: