React version: 18.2.0
Steps To Reproduce
function App() {
const [isShow, setIsShow] = React.useState(true);
function setError() {
setIsShow(false);
}
return (
<div>
{isShow && <PageWrapper />}
<div onClick={setError}>setError</div>
</div>
);
}
class PageWrapper extends React.Component {
static getDerivedStateFromError() {}
componentDidCatch(err) {
console.log("catch err: ", err);
}
render() {
return <Page />;
}
}
function Page() {
React.useEffect(() => {
return () => {
throw new Error("sorry!");
};
});
return <div>I m page</div>;
}
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(<App />)
- click setError.Unmount
<PageWrapper> along with <Page>, then <Page> threw an error in useEffect callback.
The current behavior
ErrorBoundary <PageWrapper> won't caught error thrown by <Page> useEffect callback.So all the React Tree is dropped.
But in React 17, <PageWrapper> caught the error.And the React Tree remain exists.
The expected behavior
Catch the error like React 17.
So, is that React18 new behavior? Or is a bug?
React version: 18.2.0
Steps To Reproduce
<PageWrapper>along with<Page>, then<Page>threw an error in useEffect callback.The current behavior
ErrorBoundary
<PageWrapper>won't caught error thrown by<Page>useEffect callback.So all the React Tree is dropped.But in React 17,
<PageWrapper>caught the error.And the React Tree remain exists.The expected behavior
Catch the error like React 17.
So, is that React18 new behavior? Or is a bug?