importing server actions which use cookies or headers from client components causes Error: Invariant: Method expects to have requestAsyncStorage, none available
#49410
Labels
bug
Issue was opened via the bug report template.
Verify canary release
Provide environment information
Operating System: Platform: darwin Arch: arm64 Version: Darwin Kernel Version 22.5.0: Tue Apr 25 04:07:22 PDT 2023; root:xnu-8796.121.2~8/RELEASE_ARM64_T8103 Binaries: Node: 18.15.0 npm: 9.5.0 Yarn: 1.22.18 pnpm: 7.1.0 Relevant packages: next: 13.4.1 eslint-config-next: N/A react: 18.2.0 react-dom: 18.2.0
Which area(s) of Next.js are affected? (leave empty if unsure)
App directory (appDir: true)
Link to the code that reproduces this issue
https://github.com/Fredkiss3/next-bug-server-actions-headers-cookies
To Reproduce
Run the app and click on one of the buttons in the forms
Describe the Bug
When importing server actions which use cookies or headers from a client component, when you try to call these functions you get an error :
It seems like next considers headers and cookies as client components ?
this error only happens if those actions are imported from a "use server" file into client components, if you instead pass those actions from a server component to a client component as props, everything works fine, but only if there is not any other client component who try to import the same server actions.
If you go to
app/page.tsx
and comment line 8, everything works normally :Expected Behavior
Importing server actions which use headers or cookies from a client component should not cause errors
Which browser are you using? (if relevant)
No response
How are you deploying your application? (if relevant)
No response
The text was updated successfully, but these errors were encountered: