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
OrJDev3w 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
OrJDev3w 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
him122OP3w 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
OrJDev3w ago
That’s odd, if you open the network tab what does the response look like Oh wait Is the request being made?
him122
him122OP3w ago
I thing that it is it
OrJDev
OrJDev3w ago
onClick instead of onclick Is this the issue?
him122
him122OP3w ago
I tried to console.log in the action but I see nothing
OrJDev
OrJDev3w ago
^ try If it doesn’t work lmk i will fix it in a bit i think i might know what is it
him122
him122OP3w ago
Changing from "onClick" to "onclick" works, but it still does not redirect By "works" I mean that the console.log get executed
OrJDev
OrJDev3w 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
him122OP3w ago
Yep it is working now
OrJDev
OrJDev3w ago
Awesome
Want results from more Discord servers?
Add your server