Open
Description
Hi,
It looks like there is an issue with the current suspense implementation.
Considering this snippet
const { data } = useAsync({
suspense: true,
promise: new Promise(resolve => {
setTimeout(() => resolve('hello'), 1000)
}),
})
// we should be able to safely use data here as this line
// should not be reached until promise has resolved
console.log('data', data)
But we get the following output
data undefined
data hello
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 (options.suspense && state.isPending && lastPromise.current !== neverSettle) {
// Rely on Suspense to handle the loading state
throw lastPromise.current
}
If lastPromise.current
equals neverSettle
during the first render, then it won't throw and the first render will not be suspended.
Regards
Metadata
Metadata
Assignees
Labels
No labels