S
SolidJS4w ago
sh03

SSR with `query`

I'm trying to use @solidjs/router's query like this:
const wait = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));

export const fetchData = query(async (id: string) => {
"use server";

await wait(100);

return { id };
}, "data");
const wait = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));

export const fetchData = query(async (id: string) => {
"use server";

await wait(100);

return { id };
}, "data");
and I have ssr: true in my app config. If I disable JS and make a request in a route like this:
const data = createAsync(() => fetchData("Yo"));
const data = createAsync(() => fetchData("Yo"));
it doesn't SSR the page (in fact the page remains white with no errors neither on the client nor on the server). Is query supposed to be called on the server or how can I SSR async server-only queries?
3 Replies
Brendonovich
Brendonovich4w ago
Default SSR behaviour is streaming which requires JS to be enabled - you can disable this globally by setting mode: "async" in entry-server, or set deferStream: true on the createAsync
sh03
sh03OP4w ago
Coolio, thank you very much 🙏 I can't seem to find any documentation about this. Are there downsides to using async vs stream?
Brendonovich
Brendonovich4w ago
With stream you can opt-in via deferStream, but with async you can't go back to streaming Just depends what behaviour you want
Want results from more Discord servers?
Add your server