Next.js Discord

Discord Forum

Can't set cookies in server action

Unanswered
Blue-throated Hummingbird posted this in #help-forum
Open in Discord
Blue-throated HummingbirdOP
When I try to call this server action function I get the following error, am I doing something wrong?

Error: Cookies can only be modified in a Server Action or Route Handler.

36 Replies

Blue-throated HummingbirdOP
Fixed it by using 'use client' where I called it which makes sense, stupid question, mb.
Asiatic Lion
oh lmao gotcha
Blue-throated HummingbirdOP
Is it normal for the entire page to like flash whenever I call the function?
Asiatic Lion
it happens sometimes for me too
not sure why
in dev or production? or both
Blue-throated HummingbirdOP
only tested dev
Asiatic Lion
i see it barely on production
you should be fine, dev refreshes a ton
Blue-throated HummingbirdOP
Looks like it makes the request then reloads the css or something? weird
Blue-throated HummingbirdOP
Appears to be fine on a production build
Asiatic Lion
thats good
are you using css-in-js
if so, thats where the flash comes from
css-in-js is 👎
Asiatic Lion
i import css files and it still does that
not sure why
where are you importing them
Asiatic Lion
in rootlayout
tailwind?
Blue-throated HummingbirdOP
im using tailwind and CVA
@DirtyCajunRice | AppDir tailwind?
Asiatic Lion
no normal css
barebones
@DirtyCajunRice | AppDir css-in-js is 👎
Blue-throated HummingbirdOP
cva is css-in-js, why do you say its bad?
@Blue-throated Hummingbird cva is css-in-js, why do you say its bad?
because its client-forced css. with RSC that is wasteful
Blue-throated HummingbirdOP
How should I create components like buttons that have multiple styles then?
Asiatic Lion
with my normie css i just add classes to a class string depending on the props passed
@DirtyCajunRice | AppDir …? what do you mean multiple styles
Asiatic Lion
like <Button big={true} />
or false, etc
Blue-throated HummingbirdOP
different colored buttons, sizes, states
i mean… how much you choose to abstract that out is totally up to you… but you can predefine those via the component layer as presets
none of that requires client anything
button states are hover… pressed… disabled… and default. All definable without needing client