Does 'use server' now implicitly make my exports async?
Unanswered
Alaskan Husky posted this in #help-forum
Alaskan HuskyOP
Hi, after updating Next from 14.1.0 to 14.2.3, I found that a file annotated with "use server" behaves differently.
After a few hours debugging, it seems like "use server" now does some magic to make the exports async.
Is that correct? If so, is there some documentation about that change?
"use server"
import { headers } from "next/headers"
export const getCurrentPath = () => {
const headersList = headers()
return headersList.get("x-pathname")
}After a few hours debugging, it seems like "use server" now does some magic to make the exports async.
Is that correct? If so, is there some documentation about that change?
5 Replies
@Alaskan Husky Hi, after updating Next from 14.1.0 to 14.2.3, I found that a file annotated with "use server" behaves differently.
"use server"
import { headers } from "next/headers"
export const getCurrentPath = () => {
const headersList = headers()
return headersList.get("x-pathname")
}
After a few hours debugging, it seems like "use server" now does some magic to make the exports async.
Is that correct? If so, is there some documentation about that change?
server actions have always been async, because they become asynchronous network calls on the client
@Alaskan Husky Hi, after updating Next from 14.1.0 to 14.2.3, I found that a file annotated with "use server" behaves differently.
"use server"
import { headers } from "next/headers"
export const getCurrentPath = () => {
const headersList = headers()
return headersList.get("x-pathname")
}
After a few hours debugging, it seems like "use server" now does some magic to make the exports async.
Is that correct? If so, is there some documentation about that change?
normally all your functions that are inside your 'use server' file need to be async. No I don't think there is a change. I am a few versions behind and it still throws an error, when I want to export a function that is not async, I can't
you can't make a sync function running
fetchAlaskan HuskyOP
that's the problem folks, it was working in v14.1.0, and it was exporting synchronous functions.
in v14.2.3, it literally changed the function from sync to async.
in v14.2.3, it literally changed the function from sync to async.
@Alaskan Husky that's the problem folks, it was working in v14.1.0, and it was exporting synchronous functions.
in v14.2.3, it literally changed the function from sync to async.
Yes this does happens recently. one of my packages got affected by t his change