Query vs data loader?

const getUsers = cache(async () => {
"use server";
return store.users.list();
}, "users");

export const route = {
load: () => getUsers(),
};

export default function Page() {
const users = createAsync(() => getUsers());
//OR
// const users = trpc.getUsers.createQuery();

return <For each={users()}>{(user) => <li>{user.name}</li>}</For>;
}
const getUsers = cache(async () => {
"use server";
return store.users.list();
}, "users");

export const route = {
load: () => getUsers(),
};

export default function Page() {
const users = createAsync(() => getUsers());
//OR
// const users = trpc.getUsers.createQuery();

return <For each={users()}>{(user) => <li>{user.name}</li>}</For>;
}
What is the difference between using "use server" data loader vs just using solid query based trpc for loading data?
8 Replies
Massukka
MassukkaOP7mo ago
Afaik both get resolved in ssr, so I don't quite understand the difference
peerreynders
peerreynders7mo ago
Ignoring everthing else; what is the difference in bundle size?
Massukka
MassukkaOP7mo ago
I guess just the size of solid query + trpc
peerreynders
peerreynders7mo ago
Which is what? 3-4x Preact? I see the primitives in SolidStart as the parts you will need. Now if any additional benefits that you need are offered by Query/tRPC you have to consider the trade-offs. But I also think that with tRPC there is also more work maintaining the server/client interface which is basically done for you with "use server"/seroval.
Brendonovich
Brendonovich7mo ago
- solid query allows for more complex caching (mainly more long-lived caching) than cache - trpc gives you procedure middleware, input validation, and their plugin ecosystem built in - cache + server functions give you single flight mutations - solid query and server functions can be combined if you want - you can use server functions as a transport for trpc if you want (we use it for easy stream batching) generally i'd say cache + server functions is the more barebones setup that requires less setup to get working, but will also need more manual work to add extra functionality. trpc and solid query give you a lot out of the box that can be useful for making more data-heavy apps.
Massukka
MassukkaOP7mo ago
Thanks
Brendonovich
Brendonovich7mo ago
u know what im gonna add that to my list of solid start things i have in obsidian for whenever people ask lol
Massukka
MassukkaOP7mo ago
Yeah I think I will take your post for my solid start project post mortem blog.
Want results from more Discord servers?
Add your server