-
Notifications
You must be signed in to change notification settings - Fork 47.5k
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: Error in useEffect is caught in ErrorBoundary, but still logs uncaught error to console in tests #18841
Comments
Is there some way to get some eyes on this? I don't want to be that Dev that tags a bunch of people, but this is the second issue I've raised here that has gone unnoticed (or at least unacknowledged) which is frustrating because I've tried my best to give a detailed and thorough report when raising it. |
Not sure if this is the same issue, but using useEffect in a function with try/catch will also produce this. The catch will record the error, then throw an Uncaught Error: anyway. Here is an example
results in;
it prevents the take out the useEffect and the catch returns as expected |
@davidcheal Edit: sorry, I got confused about which repo/issue I was looking at. It might be the same issue, but I'm not any kind of authority to say that. |
This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. We are sorry that we haven't been able to prioritize it yet. If you have any new additional information, please include it with your comment! |
Bump |
This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. We are sorry that we haven't been able to prioritize it yet. If you have any new additional information, please include it with your comment! |
Bump 😞 |
Bump, please. |
This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. We are sorry that we haven't been able to prioritize it yet. If you have any new additional information, please include it with your comment! |
Bump |
I'm having the same issue. I implemented a top-level ErrorBoundary component just as described in the docs, and when I throw an error during rendering, the component that the ErrorBoundary should render is actually rendered, but for some reason the error is still logged as an |
Bump |
In case it is helpful, more error stack traces and code it("Should throw and catch error", async () => {
render(
<ReallyAnErrorBoundary fallback={({ error }) => <h1>{error.message}</h1>}>
<Component error="Hello, I want to error" />
</ReallyAnErrorBoundary>
);
await screen.findByText("Loading");
await screen.findByText("Hello, I want to error");
}); export interface ReallyAnErrorBoundaryProps {
fallback: (options: { error: Error }) => ReactElement;
children: ReactNode;
}
interface ReallyAnErrorBoundaryState {
error: Error | null;
}
export class ReallyAnErrorBoundary extends Component<
ReallyAnErrorBoundaryProps,
ReallyAnErrorBoundaryState
> {
constructor(props: ReallyAnErrorBoundaryProps) {
super(props);
this.state = { error: null };
}
static getDerivedStateFromError(error: Error) {
return { error };
}
render() {
const E = this.props.fallback;
if (this.state.error) return <E error={this.state.error} />;
else return this.props.children;
}
}
|
This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. We are sorry that we haven't been able to prioritize it yet. If you have any new additional information, please include it with your comment! |
Bump. Still is a thing on 18.2.0 |
This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. We are sorry that we haven't been able to prioritize it yet. If you have any new additional information, please include it with your comment! |
Closing this issue after a prolonged period of inactivity. If this issue is still present in the latest release, please create a new issue with up-to-date information. Thank you! |
React version: 16.13.1
Steps To Reproduce
react-test-renderer
Link to code example: https://github.com/mpeyper/error-boundary-error-repro
The current behavior
Given the following two components, the way in which the error is being handled is inconsistent when using
react-test-renderer
vs.react-dom
(via@testing-library/react
in my example):When rendering with
react-dom
, both the following tests pass, and produce the same output in the console:The output they produce is:
This is somewhat expected when using
react-dom
and reflects the output one would see in the browser console if the some components were rendered in an app (you can runnpm start
in the example repo if you would like to observe this).However, where things start to get a bit strange is when the renderer is replaced with
react-test-renderer
and the same tests are run:Again both tests here do pass, but the output they produce is not the same. When the first test (error in the
render
function) is run, it only produces the following output:As you can see, the frustratingly difficult to suppress error log from the error boundary is present, but the long stack trace from the uncaught error that is present in the
react-dom
output is not.When the second test (error in the
useEffect
callback) is run, the output is:Now, the uncaught error message is back, which is not what I would have expected. Even more confusingly, when inspecting the stacktrace of the uncaught error, it has references to
jsdom
which I was of the belief was not a dependency ofreact-test-renderer
. I suspect that there is somejest
and/orjsdom
trickery going on to report the uncaught error, rather thanreact-test-renderer
using it in some way, but I'm not familiar enough with any of them to know for certain.The part that's has me the most perplexed is how the error boundary can intercept the error to pass into it's handler callbacks (surfaced in my example in
react-error-boundary
'sFallbackComponent
) without catching the error, unless it is throwing it again after catching it, but then both tests would be producing the uncaught error output, right?The expected behavior
My expected (and preferred) behaviour here would be for the the
react-test-renderer
test to only produce the error boundary error log and not have any additional uncaught error output.The text was updated successfully, but these errors were encountered: