-
Notifications
You must be signed in to change notification settings - Fork 26.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Setting Cookies Via Server Action Reloads Entire App #50163
Comments
That's dev only as we ditch all the cache of CSS resources when a server refresh is triggered, which should be fine. Are you seeing that on prod as well? Also, if cookies are mutated inside an Action, it's expected to re-render the app because there could be data that depends on cookies. |
@shuding In prod, the glitch is only apparent when turning on highlighting. The prod example can be interacted with here. Screen.Recording.2023-05-22.at.12.29.50.PM.movThe visual glitch is gone here, but, do we really want to assume the entire app should reload every time "any" cookie is set or mutated? In some cases, a cookie should change frequently, with every click. |
This comment has been minimized.
This comment has been minimized.
Same issue here. |
Almost year has passed since you posted this and I'm experiencing same issue. |
This comment has been minimized.
This comment has been minimized.
I'm experiencing same issue.. will this be resolved somehow? setting a cookie using api route does not sound good. |
I'm facing the same issue. The server action triggers all database queries (used to server side render the page of the actual route) when a cookie is set or deleted, even in production. This seems totally useless, since the components are not even rendered on the server and not sent to the client. Looking for an explanation why this happens, and potentionally how to avoid it wihout switching to an API route. |
I wonder to which degree using api route could be considered a good practice. I mean if it is - so it will be, but on the other hand, I'm using server actions (useFormState basically) to process user login form, which I process with server action, set a cookie if login was a success, and return json response. However, due to full reload, the return value never actually has a chance to reach its caller, because the whole app gets remounted (not even refreshed, but complete remount, including reset of all vars defined by useState). It feels like a really thermonuclear thing to me?… |
I'm experiencing this issue when running getSession inside of a server action, in combination with import { getSession } from "@auth0/nextjs-auth0";
export async function saveUsername(
prevState: SetUsernameFormState,
formData: FormData
): Promise<SetUsernameFormState> {
const session = await getSession();
return {
message: "Nothing to do",
};
} |
I'm facing the same issue, using auth0 to check for authenticated user on server actions. |
Verify canary release
Provide environment information
Operating System: Platform: darwin Arch: arm64 Version: Darwin Kernel Version 22.4.0: Mon Mar 6 20:59:28 PST 2023; root:xnu-8796.101.5~3/RELEASE_ARM64_T6000 Binaries: Node: 16.14.0 npm: 8.3.1 Yarn: 1.22.19 pnpm: 6.11.0 Relevant packages: next: 13.4.4-canary.0 eslint-config-next: 13.4.3 react: 18.2.0 react-dom: 18.2.0 typescript: 5.0.4
Which area(s) of Next.js are affected? (leave empty if unsure)
App directory (appDir: true)
Link to the code that reproduces this issue or a replay of the bug
https://github.com/johnson-jesse/next-server-action-cookie
To Reproduce
Describe the Bug
Setting cookies in a server action causes the entire app to reload. This appears as a render glitch most noticeable when the layout is using a custom font that also needs to load.
Screen.Recording.2023-05-22.at.10.04.59.AM.mov
Expected Behavior
Setting cookies in a server action does not cause the entire app to reload thus avoiding loading the font again.
Which browser are you using? (if relevant)
Chrome Version 112.0.5615.137 (Official Build) (x86_64)
How are you deploying your application? (if relevant)
N/A
The text was updated successfully, but these errors were encountered: