IceAge2OnDVD
IceAge2OnDVD
Explore posts from servers
TtRPC
Created by 2matto on 3/16/2024 in #❓-help
Where to put clean up code?
Looking to do the same with Neon DB, any updates?
7 replies
TtRPC
Created by IceAge2OnDVD on 9/8/2023 in #❓-help
Next cookies() not being set on Mutation in App Dir (T3 Turbo)
Managed to get it working, basically the answer is to avoid batchStreamLink on any routes/paths that need to set cookies.
export function TRPCReactProvider(props: {
children: React.ReactNode;
headers: Headers; // <-- Important
}) {
const [queryClient] = useState(() => new QueryClient());

const [trpcClient] = useState(() =>
api.createClient({
transformer,
links: [
unauthenticatedHandler,
loggerLink({
enabled: (opts) =>
process.env.NODE_ENV === "development" ||
(opts.direction === "down" && opts.result instanceof Error),
}),
splitLink({
condition(op) {
// Add logic here to return true for paths/routes that need to set cookies
return op.path.startsWith("auth.");
},
true: httpBatchLink({
url: getUrl(),
headers() {
const heads = new Map(props.headers);
heads.set("x-trpc-source", "react-no-stream");
return Object.fromEntries(heads);
},
}),
false: unstable_httpBatchStreamLink({
url: getUrl(),
headers() {
const heads = new Map(props.headers);
heads.set("x-trpc-source", "react-stream");
return Object.fromEntries(heads);
},
}),
}),
],
}),
);
export function TRPCReactProvider(props: {
children: React.ReactNode;
headers: Headers; // <-- Important
}) {
const [queryClient] = useState(() => new QueryClient());

const [trpcClient] = useState(() =>
api.createClient({
transformer,
links: [
unauthenticatedHandler,
loggerLink({
enabled: (opts) =>
process.env.NODE_ENV === "development" ||
(opts.direction === "down" && opts.result instanceof Error),
}),
splitLink({
condition(op) {
// Add logic here to return true for paths/routes that need to set cookies
return op.path.startsWith("auth.");
},
true: httpBatchLink({
url: getUrl(),
headers() {
const heads = new Map(props.headers);
heads.set("x-trpc-source", "react-no-stream");
return Object.fromEntries(heads);
},
}),
false: unstable_httpBatchStreamLink({
url: getUrl(),
headers() {
const heads = new Map(props.headers);
heads.set("x-trpc-source", "react-stream");
return Object.fromEntries(heads);
},
}),
}),
],
}),
);
19 replies
TtRPC
Created by IceAge2OnDVD on 9/8/2023 in #❓-help
Next cookies() not being set on Mutation in App Dir (T3 Turbo)
https://trpc.io/docs/client/links/splitLink , i'm going to have a look at using split links, see if that works
19 replies
TtRPC
Created by IceAge2OnDVD on 9/8/2023 in #❓-help
Next cookies() not being set on Mutation in App Dir (T3 Turbo)
is there a way you could make it so that certain mutations are never streamed? Like use a regular http link for certain routes
19 replies
TtRPC
Created by IceAge2OnDVD on 9/8/2023 in #❓-help
Next cookies() not being set on Mutation in App Dir (T3 Turbo)
makes sense
19 replies
TtRPC
Created by IceAge2OnDVD on 9/8/2023 in #❓-help
Next cookies() not being set on Mutation in App Dir (T3 Turbo)
Ahhh i see
19 replies
TtRPC
Created by IceAge2OnDVD on 9/8/2023 in #❓-help
Next cookies() not being set on Mutation in App Dir (T3 Turbo)
Is there on open issue for this?
19 replies
TtRPC
Created by IceAge2OnDVD on 9/8/2023 in #❓-help
Next cookies() not being set on Mutation in App Dir (T3 Turbo)
At least it doesn’t make sense to me
19 replies
TtRPC
Created by IceAge2OnDVD on 9/8/2023 in #❓-help
Next cookies() not being set on Mutation in App Dir (T3 Turbo)
I though that it may be something to do with not being able to set cookies after streaming starts, but then it doesn’t make sense how cookies work in query but not mutation
19 replies
TtRPC
Created by IceAge2OnDVD on 9/8/2023 in #❓-help
Next cookies() not being set on Mutation in App Dir (T3 Turbo)
Sorry for thing ping but I feel like I may need some more expert help on this @marminge
19 replies