Closed khuezy closed 6 months ago
Example:
the /sa
endpoint is the server actions
the /hello
is the traditional /api/hello
call
Is this due to vercel caching?
I see that for fetch, the response header X-Vercel-Cache
is HIT
, where the server action is MISS
.
Yea good catch, I think that either is partial or main reason for the extra latency.
Hey this is indeed a confusion between static and dynamic rendering, when you don't specify no-store on the fetch or on segment config and only have a GET
in route handlers (route.ts
/ route.js
) the route will be prerendered at build time which means it becomes a static payload. Server Actions can't be static by design, as they're meant to handle i.e. forms and rerendering of the path when you call revalidatePath
/ revalidateTag
.
Thanks for looking @timneutkens. You're correct, I missed the fact that it caches the static GET request during build.
This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.
Verify canary release
Provide environment information
Which area(s) of Next.js are affected? (leave empty if unsure)
App Router
Link to the code that reproduces this issue or a replay of the bug
https://sst-next-10-web.vercel.app/sa
To Reproduce
repo: https://github.com/khuezy/sst-next-10/blob/main/packages/web/app/sa/page.tsx
Describe the Bug
Using server actions incurs a 4x latency penalty compared to the traditional fetch api endpoint.
Expected Behavior
Server actions latency should be the same as regular /api calls. I understand Server Actions is still in alpha, hopefully it can be improved.
Which browser are you using? (if relevant)
N/A
How are you deploying your application? (if relevant)
Vercel, AWS, others.