T
TanStackβ€’4w ago
adverse-sapphire

useMutation weird issue with server actions

guys, weird question but before some days, some mutations stopped working locally (not sure why it hasn't happend before). I am a bit confused as to why this example doesn't fire the server action (a file that export loginAction and is marked with 'use server' (I don't like it too Tanner πŸ™‚ ))
const loginMutation = useMutation({ mutationFn: loginAction });
const loginMutation = useMutation({ mutationFn: loginAction });
While doing this works
const loginMutation = useMutation({
mutationFn: (values: z.infer<typeof loginSchema>) => loginAction(values),
});
const loginMutation = useMutation({
mutationFn: (values: z.infer<typeof loginSchema>) => loginAction(values),
});
4 Replies
adverse-sapphire
adverse-sapphireβ€’4w ago
We now pass the context as second argument and i guess that's not serializable
adverse-sapphire
adverse-sapphireOPβ€’4w ago
So, is the second approach the only solution? I don’t want to go through the whole codebase and do the latter by typing every value
adverse-sapphire
adverse-sapphireβ€’4w ago
mutationFn is now (values, context) => Promise if you write this mutationFn: loginAction, it sends both params to the serverAction I presume, and next doesn't like that I guess. what error are you even getting?
adverse-sapphire
adverse-sapphireOPβ€’4w ago
No errors at all, loginAction never fires This doesn't happen with a project started from scratch so I am assuming it's either an issue with next 14 or some configuration issue. For now, I think im going to modify every action with the second approach to not pass the context.

Did you find this page helpful?