S
SolidJS2mo ago
him122

pRPC - redirect not working in callers

When using the redirect$ function from prcp or the redirect function from solid-router it just does not redirect.
export const redirectAction = createAction(async () => {
throw redirect$("/hello");
});
export const redirectAction = createAction(async () => {
throw redirect$("/hello");
});
Doing the same in a plain server function works as intended.
export const redirectQuery = cache(async () => {
"use server";

throw redirect$("/hello");
}, "redirectQuery");
export const redirectQuery = cache(async () => {
"use server";

throw redirect$("/hello");
}, "redirectQuery");
13 Replies
OrJDev
OrJDev2mo ago
return redirect$( Instead of throw In pRPC, redirect is a utility function Its not being used the same way it is in server function
OrJDev
OrJDev2mo ago
In solid you use throw redirect instead of returning - in order to not confuse the actual return type of the function Bur pRPC is smart enough to omit out the redirect type and only take the actual return type
him122
him122OP2mo ago
export const redirectAction = createAction(async () => {
return redirect$("/hello");
});
export const redirectAction = createAction(async () => {
return redirect$("/hello");
});
import { type VoidComponent } from "solid-js";
import { redirectAction } from "~/server/hello/hello.queries";

const Home: VoidComponent = () => {
const redirect = redirectAction();

return (
<main>
<button onclick={async () => await redirect.mutateAsync({})}>
{/* <button type="button" onclick={async () => await redirectAction()}> */}
Redirect aaaaaaaaaaaaaaaaaa
</button>
</main>
);
};

export default Home;
import { type VoidComponent } from "solid-js";
import { redirectAction } from "~/server/hello/hello.queries";

const Home: VoidComponent = () => {
const redirect = redirectAction();

return (
<main>
<button onclick={async () => await redirect.mutateAsync({})}>
{/* <button type="button" onclick={async () => await redirectAction()}> */}
Redirect aaaaaaaaaaaaaaaaaa
</button>
</main>
);
};

export default Home;
Still not redirecting
OrJDev
OrJDev2mo ago
That’s odd, if you open the network tab what does the response look like Oh wait Is the request being made?
him122
him122OP2mo ago
I thing that it is it
OrJDev
OrJDev2mo ago
onClick instead of onclick Is this the issue?
him122
him122OP2mo ago
I tried to console.log in the action but I see nothing
OrJDev
OrJDev2mo ago
^ try If it doesn’t work lmk i will fix it in a bit i think i might know what is it
him122
him122OP2mo ago
Changing from "onClick" to "onclick" works, but it still does not redirect By "works" I mean that the console.log get executed
OrJDev
OrJDev2mo ago
Yes i think i just found an issue with the useNavigate hook, updated Ryan so hopefully we figure it out soon @him122 found the issue with the help of @Brendonovich so releasing a new version in a minute if you are up to test it published
pnpm install @solid-mediakit/prpc@latest @solid-mediakit/prpc-plugin@latest
pnpm install @solid-mediakit/prpc@latest @solid-mediakit/prpc-plugin@latest
this should fix it
him122
him122OP2mo ago
Yep it is working now
OrJDev
OrJDev2mo ago
Awesome
Want results from more Discord servers?
Add your server