Suspense: add messaging when suspense promise neither resolves nor rejects
See original GitHub issueDo you want to request a feature or report a bug? Request a feature
What is the current behavior? If you throw a promise that neither resolves nor rejects, you hit the suspense fallback UI indefinitely and receive no console messaging that helps you debug this.
Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React? All versions that allow for suspense
Proposed feature Log a warning to the console if a suspense promise takes longer than a certain amount of time to settle. Here is some code demonstrating what that could look like inside of the react codebase:
try {
renderComponent(...);
} catch (err) {
if (err && err.then) {
const timeoutId = setTimeout(() => {
console.warn(`A suspense promise triggered in component <Foo /> did not resolve nor reject after 3 seconds. If the promise never settles, the suspense fallback UI will be shown forever.`)
}, 3000)
err.finally(() => {
clearTimeout(timeoutId);
})
// Now actually do all the suspense magicks...
}
}
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
How to Improve Data Fetching in React With Suspense?
When a promise is thrown, a Suspense component catches it to render a loading state as long as the promise is not resolved....
Read more >Experimental React: Using Suspense for data fetching
We defined a function, wrapPromise , that takes in a Promise and, based on the status of that Promise, either throws the rejected...
Read more >The Complete Guide to Suspense in Vue3 - CODE Magazine
Use Suspense in Vue3 to create an execution context or a boundary around ... The moment the promise is resolved successfully, the Suspense...
Read more >How does React.Suspense know that a promise has resolved?
With React 18 we can use Suspense to conditionally render a component once a promise has been fulfilled. This example works as expected....
Read more >React Suspense for data fetching - Ovie Okeh
By wrapping both components with Suspense, you're effectively telling React not to render either one until both operations are resolved.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I agree that it was a mistake to expose it in the first place (even if it’s undocumented) but I think the solution would that will rather be to completely deprecate the confusing API and replace it with the higher level one.
I do think that relying on undocumented behavior is a bad pattern that we as an industry need to start moving away from. It puts unreasonable expectations on library authors.
The reason it is strongly worded is because there are a number of issues all related to misusing this undocumented API. I understand that it’s ultimately our problem but it’s a bit annoying. That’s not your fault tho.
👍 for me the important thing is that Suspense can be used directly. Making a higher level API for it could help with that.
Fair enough. Myself and 2-3 developers I’ve been working with on this project have definitely entered the waters of experimental and undocumented APIs. We have enjoyed learning (reverse engineering?) the behavior of the Suspense API as we’ve gone, even though it’s taken us a while and we’ve had some surprises along the way. We have known we’re in uncharted territory a bit and understand the costs and pains of that. I do not think it is your fault that we’ve spent a few days figuring it out. We’re the kind of developers who enjoying getting into the nitty gritty 😄