Haaxor1689
Haaxor1689
TtRPC
Created by Haaxor1689 on 12/10/2023 in #❓-help
Transferring huge buffer
I'm using tRPC with superjson serializer in an Electron app. I have a router querry that loads an png image, parses it with sharp and sends it as a buffer to client to render inside canvas. For larger files (62MB) I'm getting a Invalid array length error from superjson though. Can you think of a way to work around this issue?
7 replies
TtRPC
Created by Haaxor1689 on 12/10/2023 in #❓-help
Report progress of mutation
I'm using tRPC in a electron app and am running a nodeWorker from main thread. Is there a way to report partial progress to useMutation in renderrer thread? I know I could use subscription but is this possible with mutation?
7 replies
TtRPC
Created by Haaxor1689 on 5/16/2023 in #❓-help
setMutationDefaults for optimistic updates
I have a preferences router, with a get query and a set mutation. I had optimistic updates set up in the onSuccess of the useMutation hook, wherever I used it, like this:
const preferences = api.preferences.get.useQuery();
const savePreferences = api.preferences.set.useMutation({
onSuccess: v =>
queryClient.setQueryData(
getQueryKey(api.preferences.get, undefined, 'query'),
v
)
});
const preferences = api.preferences.get.useQuery();
const savePreferences = api.preferences.set.useMutation({
onSuccess: v =>
queryClient.setQueryData(
getQueryKey(api.preferences.get, undefined, 'query'),
v
)
});
Now that I'm adding more and more instances where I need to use the set endpoint, I don't want to copy paste the onSuccess for optimistic updates. There is the setMutationDefaults function of query client that would be ideal for this but it isn't working.
queryClient.setMutationDefaults(getQueryKey(api.preferences.set), {
onSuccess: v =>
queryClient.setQueryData(
getQueryKey(api.preferences.get, undefined, 'query'),
v
)
})
queryClient.setMutationDefaults(getQueryKey(api.preferences.set), {
onSuccess: v =>
queryClient.setQueryData(
getQueryKey(api.preferences.get, undefined, 'query'),
v
)
})
Is this not working in tRPC wrapper because it's not setting the mutationKey or am I doing something wrong? Like I could make a wrapper hook for this mutation but using these defaults seems to me like much cleaner solution.
5 replies