-
-
Notifications
You must be signed in to change notification settings - Fork 10.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]: Rejected promise in deferred data does not bubble up to the closest error boundary #11069
Comments
This looks like a small bug because you're throwing |
Oh, I see! Those are two separate issues then. Rejecting with a truthy value still results in a similar undesired console error message, but does indeed show the error boundary. ❤️ Should I create a separate issue for that? |
That console error is logged by React when an error is thrown to the nearest error boundary. If you'd like to avoid it, you can specify an <Await resolve={data} errorElement={<p>oops</p>}> Otherwise, there is no choice but to throw it so it bubbles up the route hierarchy - so the log is unavoidable in that case. |
Both React and React Router log the error. react-router/packages/react-router/lib/hooks.tsx Lines 604 to 610 in 7a2e9f6
Indeed the error is gone if I add an I wish there was a way to prevent automatically logging errors when there's an error boundary, so that I can control whether to log them or not. Thanks for you help! I guess I have some more learning to do. |
Sorry - the error in the description above is logged by React 😉 . React Router also logs the error afterwards - but at that point the console is already dirtied. Generally speaking, I don't think swallowing error logs is advisable since it allows things to go wrong without being noticed. This seems to be the stance of the React team as well: facebook/react#15069.
If this is only a test concern - can't you use a spy on jest.spyOn(console, "warn").mockImplementation(() => {}); |
Good idea, thanks! |
Yeah, after several hours of thinking about this I started seeing it as a good thing. |
This is resolved by #11071 and will be available in the next release |
🤖 Hello there, We just published version Thanks! |
🤖 Hello there, We just published version Thanks! |
What version of React Router are you using?
6.20.0
Steps to Reproduce
Expected Behavior
Deferred data failed, so I expected to see the contents of
errorElement
, i.e. the error boundary.Actual Behavior
Instead I don't see anything, and see the following stack trace in my browser console:
The text was updated successfully, but these errors were encountered: