Closed MwSpaceLLC closed 2 months ago
The correct arrow function syntax is:
export const setServerCookies = async (...props) => {
cookies().set(...props);
}
Note the position of the async keyword:
We apologize, I think I made a mistake.
so, with arrow functio, same function, we have this error.
⨯ Internal error: Error: Only plain objects, and a few built-ins, can be passed to Client Components from Server Components. Classes or null prototypes are not supported. at eF (W:\projects\djcode.it\node_modules\next\dist\compiled\next-server\app-page.runtime.dev.js:35:270462) at eq (W:\projects\djcode.it\node_modules\next\dist\compiled\next-server\app-page.runtime.dev.js:35:274676) at eJ (W:\projects\djcode.it\node_modules\next\dist\compiled\next-server\app-page.runtime.dev.js:35:275293) at Timeout._onTimeout (W:\projects\djcode.it\node_modules\next\dist\compiled\next-server\app-page.runtime.dev.js:35:265080) at listOnTimeout (node:internal/timers:573:17) at process.processTimers (node:internal/timers:514:7) digest: "58502399"
'use server'
import {cookies} from "next/headers";
/*
What kind of data are you passing between client and server actions? only serializable stuff can be send over the network.
we pass same data, but function not arrow work:
'use server'
import {cookies} from "next/headers";
/*
pass data: serverActionSetCookies('registerEmail', formValues.email || registerEmail)
Ohh, implicit return is tricky, hehe. Change to:
export const serverAction = async (...props) => {
// Set your cookies here
}
That'll make the return type undefined.
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.
Link to the code that reproduces this issue
https://codesandbox.io/p/devbox/icy-dream-h8h9t9
To Reproduce
import on client component server action setServerCookies:
error:
⨯ ./actions/global.actions.js Error: × Expected '{', got 'async' ╭─[W:\projects\djcode.it\actions\global.actions.js:7:1] 7 │ @param props 8 │ @returns {Omit<RequestCookies, "set" | "clear" | "delete"> & Pick<ResponseCookies, "set" | "delete">} 9 │ */ 10 │ export async const setServerCookies = (...props) => cookies().set(...props) · ───── ╰────
Current vs. Expected behavior
make server action with arrow function
Provide environment information
Which area(s) are affected? (Select all that apply)
Webpack
Which stage(s) are affected? (Select all that apply)
next dev (local), next build (local), next start (local)
Additional context
i know the correct syntax is:
but i think that this is not property dev experience to break compiler if we use arrow => funciton.