-
Notifications
You must be signed in to change notification settings - Fork 45.8k
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 message "Uncaught Error: A component suspended while responding to synchronous input." may be misleading #25629
Comments
Please do provide a minimal example where the error would be misleading. |
Sorry for the delay - just back from holiday! I've put together a very simple replication as a sandbox here: https://codesandbox.io/s/charming-jang-y5evsf The core of this is just having a component suspend without a suspense boundary: import { Suspense } from "react";
const SuspenseTrigger = () => {
throw new Promise(() => {});
};
export default function App() {
return (
<div className="App">
<h1>Suspense example</h1>
{/* <Suspense fallback={<div>loading...</div>}> */}
<SuspenseTrigger />
{/* </Suspense> */}
</div>
);
} The sandbox seems to give slightly odd behaviour on reloading, so you'll need to do these steps in order to show the issue:
Adding So my feeling is that if the error message also suggested adding a suspense boundary, it would reinforce good practice, and in my case would also have got me much more quickly to the real issue of a misplaced |
I also ran into this error message when testing a component that uses Tanstack Query (React Query). |
@eps1lon Hi, I just wanted to check whether the example given was enough to show the issue? Just let me know if there's anything else that would be useful. |
You can wrap your component in a boundary and provide a fall back as well |
I had this issue and like @bmwebster and @fthebaud, I think the error message is misleading. In my case I was able to fix the error without using
In this case, I just removed the 2nd instance of the same state and it fixed the error. I hope this might help someone troubleshooting. The error message led me down the wrong path for a while. I first tried using |
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: 18.2.0
Steps To Reproduce
Do anything that triggers the error:
This seems to occur when a synchronous input causes a component to suspend, without a suspense boundary defined.
To create the specific situation where I saw the error:
Suspend
around either component.Link to code example:
Can provide if needed, however the issue seems to be that the wording of the error doesn't match the conditions that cause the error to be thrown in React code (see below), so a code example might not be necessary?
The current behavior
The following error message is displayed:
This implies that the only way to fix the error is to use "startTransition". While this did fix my error, looking at the code in question it seems that the more obvious problem is that there was no suspense boundary around the component in question. This problem is also much easier to fix - in my case could add transitions easily for some cases (around
navigateTo
calls to react-router), but catching every way of navigating and adding a transition seems to be quite difficult. I added aSuspense
around the suspending component, and this resolved the error. Using "startTransition" does have extra advantages of allowing the old state of the suspended component to display instead of a fallback, but this seems like it should be more of an "information" notice than an error, so I'm assuming it's only the lack of both a suspense boundary and a synchronous input that is intended to be flagged as an error?Looking at the React code seems to confirm this:
I could be reading this wrongly, but it looks like the error I'm seeing is only raised when there is no boundary found, and we have a sync update. If there is a suspense boundary, it looks like the error doesn't apply, and there is a comment specifically covering that if there is no boundary, only sync updates are an error ("Unless this is a sync update, this is OK.").
In addition, the component does not seem to re-render when data is received, the output remains empty, presumably because this is an unrecoverable error?
The expected behavior
An error is displayed which covers both options for resolving, e.g.:
This is a little wordy, so maybe it should be a link to a documentation page instead?
The text was updated successfully, but these errors were encountered: