Next.js Discord

Discord Forum

Next 14 | Server Actions being spammed

Unanswered
Asian black bear posted this in #help-forum
Open in Discord
Original message was deleted.

34 Replies

Avatar
Shy Albatross
you're misusing server actions, that's why
Server actions are designed for mutations that update server-side state; they are not recommended for data fetching.
https://react.dev/reference/react/use-server
also I assume that Next/React has no way of knowing if prisma.status.whatever is stable (contrary to fetch, which it expects to be stable based on URL, params and headers, therefore it caches it) so your component that awaits getStatus() rerenders forever?
Avatar
Asian black bear
it works fine in other projects. could it be a next 14 thing?
Avatar
Shy Albatross
delete the "use server" because there's no reason to go over HTTP when wanting to fetch data between a server function and a server component
Avatar
Asian black bear
prisma can't run then, might just move it to an api route
Avatar
Shy Albatross
wdym prisma can't run
Avatar
Asian black bear
if i remove the 'use server' it won't fetch the data
Avatar
Shy Albatross
it's still on the server even after you remove "use server"
Avatar
Asian black bear
tell that to next
Image
Avatar
Shy Albatross
that's not a next error, that's a prisma error, maybe prisma doesn't support next 14 yet
running in 'unknown'
Avatar
Asian black bear
this happens in 13 as well
Avatar
Shy Albatross
so prisma doesn't support RSC?
Avatar
Asian black bear
it needs 'use server' to run
Avatar
Shy Albatross
hard to say, their article and demo for RSC are outdated
Avatar
Asian black bear
it works fine in several other projects. might just move it to an api layer
Avatar
Shy Albatross
no "use server" here
Avatar
Asian black bear
because they aren't in a client component
i'm fetching from a client component
Avatar
Shy Albatross
status is a client component? you failed to include that in the OP
there's no "use client" there
Avatar
Asian black bear
the page is, forgot to add the screenshot
i will just move it to an api route. not worth the troubles
Avatar
Shy Albatross
well then I suspect the issue is that the component awaits something that doesn't look like it stabilises so it keeps rerendering forever
at least with an API route you will be aware that you need to secure it somehow
Avatar
Asian black bear
yeah. i just find it weird because i've been doing this in other projects with no issues
Avatar
Shy Albatross
I'd like to point out that it's odd that your whole page is a client component
Avatar
Asian black bear
no need for it to be ssr as it's a dashboard
could go that route, though
yeah just gonna make the page ssr and wrap the interactivity in a client component
Avatar
Shy Albatross
exactly