#Issue with Suspense

3 messages · Page 1 of 1 (latest)

silver wren
#

I have an issue with Suspense not suspending evaluation of a resource:

⁨```typescript
import { render } from "solid-js/web";
import { createResource, Suspense } from "solid-js";

const getFoo = (): Promise<FooData> => Promise.resolve({ name: "name" });

const App = () => {
const [foo] = createResource(() => getFoo());

return (
<div>
<Suspense fallback={<div>loading</div>}>
<FooView data={foo()} />
</Suspense>
</div>
);
};

type FooData = {
name: string;
};

const FooView = (props: { data: FooData }) => {
return <div>{props.data.name}</div>;
};

render(() => <App />, document.getElementById("app")!);


Playground: https://playground.solidjs.com/anonymous/97dd60ce-6c09-4d89-8368-22401e1c62e2

The error is:  ⁨`Uncaught TypeError: Cannot read properties of undefined (reading 'name')`⁩

I would have expected ⁨`Suspense`⁩ to detect that the resource has not been loaded yet.

Am i doing something wrong here?
fair otter
#

in solid 1.x resources are initially undefined

#

suspense is a mechanism for displaying fallbacks (and it has utility for SSR), but everything still is being passed through and the components underneath the suspense are mounted