Fossil
Fossil
TTCTheo's Typesafe Cult
Created by Kenzo on 7/8/2024 in #questions
Caching does not work with trpc in Next, what would you do?
I feel like a tremendous pleb. The regular approach of adding headers to next.config.js adds the correct Cache-Control headers to the response, and the server respects them. cc @Kenzo
// next.config.js
headers: async () => {
return [
{
source: "/api/trpc/yourRouteName",
headers: [
{
key: "Cache-Control",
value: "public, s-maxage=90, max-age=90",
},
],
},
];
},
// next.config.js
headers: async () => {
return [
{
source: "/api/trpc/yourRouteName",
headers: [
{
key: "Cache-Control",
value: "public, s-maxage=90, max-age=90",
},
],
},
];
},
26 replies
TtRPC
Created by P.S.Nikhil on 12/15/2023 in #❓-help
How to cache trpc server request next.js app router
Holy fck you're right. I feel like a tremendous pleb. This adds the correct Cache-Control headers to the response, and the server respects them. cc @Kenzo
// next.config.js
headers: async () => {
return [
{
source: "/api/trpc/yourRouteName",
headers: [
{
key: "Cache-Control",
value: "public, s-maxage=90, max-age=90",
},
],
},
];
},
// next.config.js
headers: async () => {
return [
{
source: "/api/trpc/yourRouteName",
headers: [
{
key: "Cache-Control",
value: "public, s-maxage=90, max-age=90",
},
],
},
];
},
24 replies
TtRPC
Created by P.S.Nikhil on 12/15/2023 in #❓-help
How to cache trpc server request next.js app router
Can you link to this Kenzo?
24 replies
TTCTheo's Typesafe Cult
Created by Lukem121 on 9/11/2023 in #questions
Error: Invariant: headers() expects to have requestAsyncStorage, none available.
For me this happened when calling headers() as part of the context for createServerSideHelpers. It is actually covered here: "That also means that you don't have the request and response at hand like you usually do. Make sure you're instantiating the server-side helpers with a context without req & res" https://trpc.io/docs/client/nextjs/server-side-helpers#1-internal-router
5 replies
TTCTheo's Typesafe Cult
Created by v-for-v on 4/21/2024 in #questions
Bug!? Server side calls are not being cached
Apologies 'Greater' is misleading here. Let me rephrase: Your TRPC endpoints can still be queried directly, and will have the previous issue of being uncached. Thus - your TRPC endpoints themselves are a DDoS vector (regardless of how you're querying them in your app)
54 replies
TTCTheo's Typesafe Cult
Created by v-for-v on 4/21/2024 in #questions
Bug!? Server side calls are not being cached
Yea the endpoints would still be exposed and uncached in prod though - so greater potential for a DDoS?
54 replies
TTCTheo's Typesafe Cult
Created by v-for-v on 4/21/2024 in #questions
Bug!? Server side calls are not being cached
Yea the existing trpc docs refer to a cacheing method (setting cache-control headers) which are ignored with the app router. I've found no way to control the tRPC cache with the app router
54 replies
TTCTheo's Typesafe Cult
Created by Bartholomeas on 4/6/2024 in #questions
Refetching/revalidating server query with TRPC
Yea shades of the same issue - I have found no documentation online for how to handle trpc endpoint cacheing/revalidation with Next Ap Router https://discord.com/channels/966627436387266600/1212328159991570452/1212328159991570452 & https://discord.com/channels/966627436387266600/1228337408563740803
12 replies
TtRPC
Created by Time on 4/14/2024 in #❓-help
Getting strange react error in nextjs
Is Config a server component? Make sure you're declaring "use client" at the top
3 replies
TtRPC
Created by P.S.Nikhil on 12/15/2023 in #❓-help
How to cache trpc server request next.js app router
Currently documented tRPC cacheing methods (https://trpc.io/docs/server/caching) won't work as they rely on setting headers which NextJs now overrides (https://nextjs.org/docs/app/api-reference/next-config-js/headers#cache-control)
24 replies
TTCTheo's Typesafe Cult
Created by Gnark | David on 2/28/2024 in #questions
Cache with TRPC app router
Currently documented tRPC cacheing methods (https://trpc.io/docs/server/caching) won't work as they rely on setting headers which NextJs now overrides (https://nextjs.org/docs/app/api-reference/next-config-js/headers#cache-control)
6 replies
TtRPC
Created by P.S.Nikhil on 12/15/2023 in #❓-help
How to cache trpc server request next.js app router
Yea lots of options with clientside cacheing. Kinda ridiculous there's no docs for app router cacheing
24 replies
TtRPC
Created by P.S.Nikhil on 12/15/2023 in #❓-help
How to cache trpc server request next.js app router
Did you figure this out? I am stumped
24 replies
TTCTheo's Typesafe Cult
Created by Gnark | David on 2/28/2024 in #questions
Cache with TRPC app router
Bump. Cannot find a way to have caching respected for trpc endpoints. create-t3-app@7.30.1 I'm able to set cache-control headers in the createCallerFactory context, or fetchRequestHandler's responseContext but it doesnt seem to have an impact
6 replies