-
Notifications
You must be signed in to change notification settings - Fork 47.2k
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: componentWillUnmount is called twice #24280
Comments
Woah. |
I believe that this is a similar problem that I am having with the useEffect hook. |
@Kramb, no, the duplicate matching useEffect setup+cleanup calls are expected in 18 when Strict Mode is on. This issue is about an unrelated bug where |
@gaearon Okay, I see now. I appreciate the clarification. I've been running in circles with this one and I think I jumped at the first thing that resembled my issue. |
No problem! Did you miss it in the upgrade post, or did you update without reading in detail? We’re trying to figure out how to surface this more prominently so it would be helpful to know more about how people run into this. |
I did not even notice there was an update to react because I used CRA to start a new project. When I made a call to my API I noticed that it was making the call twice in the "Network" tab of the developer's console. |
The For future googlers, I want to reiterate that double-firing effects is not related to this issue. See #24280 (comment) for explanation of that behavior. |
Thanks 🚀 |
Thank you for reporting this. This should be fixed in 18.1.0. |
Yep can confirm, that after upgrading to 18.1.0 we're no longer able to reproduce the problem. Thanks again 🙏 |
unfortunately, the problem exists. Here is my package.json
|
Please read #24280 (comment). I suspect the problem you’re facing is not related to this issue which has been fixed. If you found some different problem from either of these two please file a new issue. I will lock this issue because I expect more people to be confused in a similar way. |
React version: 18.0.0
Steps To Reproduce
componentWillUnmount
is called twice upon toggling the rendered component. Even when StrictMode is disabledLink to code example: https://codesandbox.io/s/componentwillunmount-called-twice-hrpzy5?file=/src/App.js
The current behavior
After upgrading to react 18 we've seen some different behavior in a conditionally rendered, lazy class component.
In the provided code example the class component is rendered first. After the first toggle, the class component's componentWillUnmount is called twice.
Subsequent toggle calls correctly lead to a single componentWillUnmount invocation.
This does only seem to affect the class component when its rendered first. If the condition is changed to initially show the other function component the class component unmounts just fine
The expected behavior
The class component's componentWillUnmount is only called once
The text was updated successfully, but these errors were encountered: