next.js icon indicating copy to clipboard operation
next.js copied to clipboard

Docs: Write cookies from Server Functions

Open MartinCura opened this issue 1 month ago • 1 comments

What is the documentation issue?

Not sure if i'm wrong or this is a small detail.

Docs for cookies mention many times that cookies can only be mutated by Server Actions or Route Handlers. https://nextjs.org/docs/app/api-reference/functions/cookies

But we can also do this (.set(), .delete()) from Server Functions in general, right?

I think i'm doing it in my app without problems.

Again maybe a detail but having the word "Action" there so many times threw me off, and i can't think of a way where i architect this flow to use a form action (and corresponding server action) instead of a simple server function (accessed as a normal function from a RSC and as an endpoint from the client).

And maybe there was already an issue about this but i missed it.

Is there any context that might help us understand?

More so, the "Server Actions" links in the cookies docs page all link to a more general page about "Updating data" which talks about Server Functions.

Does the docs page already exist? Please link to it.

https://nextjs.org/docs/app/api-reference/functions/cookies#setting-a-cookie

MartinCura avatar Dec 03 '25 18:12 MartinCura

Yes, Server Functions can be qualified as a Server Action by client side usage, https://react.dev/reference/rsc/server-functions:

If a Server Function is passed to an action prop or called from inside an action then it is a Server Action, but not all Server Functions are Server Actions

So, when the document says, you can do that in Server Actions, it also means it applies to Server Functions. I am gonna update the naming though.

icyJoseph avatar Dec 03 '25 19:12 icyJoseph