-
Notifications
You must be signed in to change notification settings - Fork 94
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
Suspense does not suspend on first render #242
Comments
This is the part why the current Suspense support is marked experimental. It works, but it's not optimized. If you can provide a PR that fixes this I'll happily merge it. |
i think tests like these describe the behavior accurately // Skip when testing for backwards-compatibility with React 16.3
const testSuspense = Suspense ? test : test
testSuspense("supports Suspense", async () => {
const promiseFn = () => resolveIn(150)("done")
const log = []
render(
<Suspense fallback={<div>fallback</div>}>
<Async suspense promiseFn={promiseFn}>
{({ data, isPending, isResolved, status }) => {
expect(status).toBe("resolved")
expect(data).toBe("done")
expect(isResolved).toBe(true)
expect(isPending).toBe(false)
return null
}}
</Async>
</Suspense>
)
})
testSuspense("supports Error Boundaries", async () => {
const promiseFn = () => rejectIn(150)(new Error("error"))
const log = []
render(
<ErrorBoundary fallback={<div>fallback</div>}>
<Async suspense promiseFn={promiseFn}>
{({ error, isPending, isRejected, status }) => {
expect(status).toBe("rejected")
expect(error).toBe("error")
expect(isRejected).toBe(true)
expect(isPending).toBe(false)
return null
}}
</Async>
</ErrorBoundary>
)
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,
It looks like there is an issue with the current suspense implementation.
Considering this snippet
But we get the following output
One of the most important purpose of suspense is to make asynchronous code feel like if it were synchronous so you don't have to deal with "data is not here yet" headaches.
By quickly looking at the implementation, this may be due to this condition
If
lastPromise.current
equalsneverSettle
during the first render, then it won't throw and the first render will not be suspended.Regards
The text was updated successfully, but these errors were encountered: