Next.js Discord

Discord Forum

Getting `Functions cannot be passed directly to Client Components` incorrectly

Unanswered
Kokoni posted this in #help-forum
Open in Discord
KokoniOP
page.tsx

I know that the "use server" is unnecessary on a page, but I get a different error otherwise. Also note that this is in a parallel route app/(layout)/profile/(modal)/@dialog/(.)group/create/page.tsx.

"use server"

import GroupForm from "@/components/app/GroupForm";
import { DialogContent, DialogTitle } from "@/components/ui/dialog";
import RoutedDialog from "@/components/ui/routed-dialog";
import { createGroup } from "@/lib/actions/group";
import { getCurrentUser } from "@/lib/utils";
import { revalidatePath, revalidateTag } from "next/cache";
import { redirect } from "next/navigation";

export default async function Group() {
  const { session } = await getCurrentUser();

  async function createGroupAndRevalidate(formData: FormData) {
    "use server"
    const group = createGroup(formData, session.user.id);
    revalidatePath("/profile");
    revalidatePath("/overview");
    return redirect("/profile");
  }

  return (
    <RoutedDialog defaultOpen>
      <DialogContent>
        <DialogTitle>Create a Group</DialogTitle>
        <GroupForm action={createGroupAndRevalidate} />
      </DialogContent>
    </RoutedDialog>
  );
}

18 Replies

KokoniOP
@aardani here ya go
KokoniOP
So marking a page as "use server" is an antipattern/not allowed?
Alright well either way, when I remove the directive from the top of the page file, I get a

Error: Failed to find Server Action "23771b8443c9ade39920168898d34262232f3be3". This request might be from an older or newer deployment.
Which despite using next since app dir/server actions came out I've never experienced haha
@Kokoni So marking a page as "use server" is an antipattern/not allowed?
its not an antipattern/not allowed, its simply a wrong usage
KokoniOP
Neato
KokoniOP
Just remove the top "use server" and it's the exact same code
Happens on both deployed and dev. Deployed says that posting to the base route is not allowed, dev gives the above error
interesting
KokoniOP
I'm guessing it's a parallel route problem, that the action isn't registered on the base route but on the parallel
And that doesn't have an action map
can you reproduce the bug on a minimal setup? preferably in code sandbox
KokoniOP
Sure
KokoniOP
I gotcha. I'm heading into class rn but I can get it after