S
SolidJS•11mo ago
the magic guy

createResource / Suspense blocks rendering

Im trying to understand how to handle async data fetching. Taking an example from the docs, with some modifications. This component seem to block rendering for 5 seconds, before displaying Data fetched from API, rather than showing the fallback in the Suspense element while the setTimeout is happening. I feel like im not understanding something here...
import { createResource, Suspense } from "solid-js";

async function fetchData(): Promise<string> {
return new Promise((resolve) => {
setTimeout(() => {
resolve("Data fetched from API");
}, 5000); // Simulate a 2-second delay
});
}
export default function () {
const [resource] = createResource(fetchData);

return (
<Suspense fallback={<p>loading...</p>}>
<div>HELLO WORLD</div>
{resource()}
</Suspense>
);
}
import { createResource, Suspense } from "solid-js";

async function fetchData(): Promise<string> {
return new Promise((resolve) => {
setTimeout(() => {
resolve("Data fetched from API");
}, 5000); // Simulate a 2-second delay
});
}
export default function () {
const [resource] = createResource(fetchData);

return (
<Suspense fallback={<p>loading...</p>}>
<div>HELLO WORLD</div>
{resource()}
</Suspense>
);
}
7 Replies
Jasmin 🌈💜
It should work thinkies Have a look here: https://playground.solidjs.com/anonymous/b990a527-c631-4a60-a2f8-3792fbe13021 Maybe something else makes the component block
Solid Playground
Quickly discover what the solid compiler will generate from your JSX template
the magic guy
the magic guy•11mo ago
Hmm odd… What could cause the entire component to block…?
Jasmin 🌈💜
something higher up probably. you could share the code and i can have a look if you want :)
Martnart
Martnart•11mo ago
Do you have SSR enabled? Loading a page via SSR will wait for resources to be resolved. CSR will trigger the Suspense instead as you would expect, i.e. navigating from another page.
the magic guy
the magic guy•11mo ago
The code is here. Im using the template from solid start https://github.com/shawnyu5/FreshMeet/blob/feat/suspend/frontend/src/routes/meetup/test.tsx uh how do I tell what i am using?
Martnart
Martnart•11mo ago
By default SSR is on in solid start. Try changing the vite config plugin line to this: plugins: [solid({ ssr: false })]
the magic guy
the magic guy•11mo ago
ahh interesting... That did it thanks!
Want results from more Discord servers?
Add your server
More Posts
`<script>` tag are loaded at the bottom of body, I need to load them on the `<head>` tag...Hello all 🙂 I need to use the Font Awesome kit which is available by inserting it into the `head` tSolid context doesnt workLearning solid using docs and i use the docs example to create a context but for some reason this erReactivity inside closure in return valueI have a function with a store, singals etc. This function returns an object, that object contains aError [RollupError]: "assign" is not exported by "node_modules/solid-js/web/dist/server.js"When trying to build my solid-start app using `solid-start build` I get the following error: ``` fisolid-router not updating when going the same page but with different parameterso/ so i have this in `/routines/[id].tsx`: ```tsx export default function EditRoutine() { const updating a member inside another member inside an array inside a store using an indexo/ so i have data structured as follows, which is inside a store: ```js { actions: [ { FileRoutes duplicate hydration and not displaying dynamic routeif i used fileroutes the nested route is not working well, but if i used not fileroutes it behave How to use SolidStart on existing SolidJs project in order to benefit of File Based Routing ?PS: I use SolidJs only for SPA, so only client-side ? Is it possible to use SolidStart only for clieHow do I modify a member of an object in an array in a SolidJS Store using the SetStoreFunction?(Re-post from https://stackoverflow.com/questions/76843586/how-do-i-modify-a-member-of-an-object-in-useParams() not changing when switching pages?i'm getting really odd behavior ```tsx export default function EditRoutine() { const params = us