Rodrigo
Rodrigo
SSolidJS
Created by Rodrigo on 7/9/2024 in #support
Is createAsync supposed to work with Suspense?
My Suspense component is not working well with createAsync. Basically, anything iside the Suspense block is running even though the promise from createAsync hasn't finished. I've got a fairly simple setup that's failing and I'd love to understand if this is by design and expected, or something that I'm doing wrong, or a bug: Simple SolidJS app with Solid Router. No SSR, no SolidStart. Classic component routing. The result is an uncaught error stating result() is undefined...
const remoteCall = cache(async () => {
return new Promise(resolve => setTimeout(() => resolve({ foo: '1' }), 2000))
}, 'remote')

const TestComponent = () => {
const result = createAsync(() => remoteCall())

return (
<Suspense fallback={<div>Loading...</div>}>
<div>Foo is {result().foo}</div>
</Suspense>
)
}
const remoteCall = cache(async () => {
return new Promise(resolve => setTimeout(() => resolve({ foo: '1' }), 2000))
}, 'remote')

const TestComponent = () => {
const result = createAsync(() => remoteCall())

return (
<Suspense fallback={<div>Loading...</div>}>
<div>Foo is {result().foo}</div>
</Suspense>
)
}
Any ideas?
7 replies