Fetch Cache Logging In Server Action
Unanswered
Harlequin Duck posted this in #help-forum
Harlequin DuckOP
When my page renders and I make fetch calls in my server component i get those cool logs:
But when i call a server-action from the frontend that also does a fetch call i don't get this cool cache log, i get:
The fetch inside the server action has:
This should start caching the fetch, yes?
In my Next config i have:
Is there a way to upgrade the logging, to show the cache behaviour for all fetches, even inside server-actions?
│ │ POST http://page/url 200 in 390ms (cache skip)
│ │ │ Cache skipped reason: (auto no cache)But when i call a server-action from the frontend that also does a fetch call i don't get this cool cache log, i get:
POST /page/url 200 in 506msThe fetch inside the server action has:
next: {
revalidate: 43200,
},This should start caching the fetch, yes?
In my Next config i have:
logging: {
fetches: {
fullUrl: true,
},
},Is there a way to upgrade the logging, to show the cache behaviour for all fetches, even inside server-actions?
9 Replies
Why are you calling server actions from a page? @Harlequin Duck
They are for mutations.
Harlequin DuckOP
@Arinji I have a dynamic popup that needs to fetch data when it gets opened. I can only execute the fetch on the server.
I just built a server action that executes the fetch and returns the data. So in my client popup, I can just call the async function (server action).
It works perfectly fine. Should I not do that?
I just built a server action that executes the fetch and returns the data. So in my client popup, I can just call the async function (server action).
It works perfectly fine. Should I not do that?
Harlequin DuckOP
I actually do that a bunch of times. I have a few server only fetches, that i also use in SSR but for revalidation i just made a big "use server" file, where i made a bunch of wrapper function for the fetches, so i can later revalidate on the client.
For example using tanstack query i prefetch a bunch of stuff on server render, but the the query client on the client, then also late revalidates using server actions.
For example using tanstack query i prefetch a bunch of stuff on server render, but the the query client on the client, then also late revalidates using server actions.
@Harlequin Duck <@890486507872342027> I have a dynamic popup that needs to fetch data when it gets opened. I can only execute the fetch on the server.
I just built a server action that executes the fetch and returns the data. So in my client popup, I can just call the async function (server action).
It works perfectly fine. Should I not do that?
You do the dynamic popup with portals right?
Or like pass props to it
Basically server actions are for mutations, they expose a POST request
Full url logging won't show it since it's not for getting data for a page
Yes it works as expected, but it's the same as doing GET stuff from a POST api route