Open2

Next.js の cookies.delete は Server Components では実行できない

Gen TamuraGen Tamura

Server Components で呼び出す Server Action は、ただ Server Components 内で関数が実行されているだけで、 Server Action 扱いではない。

Unable to delete cookie using Next.js server side action - stack overflow

Route Handlers では実行できた。
docs にも書いてあるが、 Sever Components で実行される Server Action も Server Action だと思っていたため、ちょっとハマってしまった。

Deleting cookies

Good to know: You can only delete cookies in a Server Action or Route Handler.
Gen TamuraGen Tamura

でも docs をみると、 Server and Client Components と記載があって、むむむというお気持ちがある。

Server Actions and Mutations

Server Actions are asynchronous functions that are executed on the server. They can be used in Server and Client Components to handle form submissions and data mutations in Next.js applications.