React version: 18.0.0
Steps To Reproduce
componentWillUnmount is called twice upon toggling the rendered component. Even when StrictMode is disabled
Link 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
React version: 18.0.0
Steps To Reproduce
componentWillUnmountis 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