Top level "use server" doesn't seem to work
Hey all, I've noticed that I put "use server" at the top of the file, it doesn't seem to actually treat the functions in the file as server functions, and the actions don't work as expected.
I wanted to ask here before filing an issue, as I feel like maybe I am misunderstanding.
For example, this seems to work:
However, this throws an error when I try to call these functions:
Is this intended behavior?
4 Replies
These two examples aren't equivalent -
use server
files should only export raw functions, wrapping them in cache
won't work and means that the cache
won't exist on the client
An equivalent form would be defining the async functions in one use server
file and then exporting the cache-wrapped versions in a second non-use server
fileahhh ok. thanks!
Oh this is a good explanation. I just always use it inline instead of top level
Me too. Then I am sure nothing leaks 🥷