Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NEXT-1254] Shorthand notation not working in actions #50445

Closed
1 task done
thanosoncode opened this issue May 28, 2023 · 1 comment · Fixed by #50937
Closed
1 task done

[NEXT-1254] Shorthand notation not working in actions #50445

thanosoncode opened this issue May 28, 2023 · 1 comment · Fixed by #50937
Assignees
Labels
bug Issue was opened via the bug report template. linear: next Confirmed issue that is tracked by the Next.js team.

Comments

@thanosoncode
Copy link

thanosoncode commented May 28, 2023

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System:
      Platform: darwin
      Arch: arm64
      Version: Darwin Kernel Version 22.4.0: Mon Mar  6 21:00:41 PST 2023; root:xnu-8796.101.5~3/RELEASE_ARM64_T8103
    Binaries:
      Node: 16.17.0
      npm: 8.15.0
      Yarn: 1.22.17
      pnpm: 7.14.2
    Relevant packages:
      next: 13.4.5-canary.0
      eslint-config-next: 13.4.3
      react: 18.2.0
      react-dom: 18.2.0
      typescript: 5.0.4

Which area(s) of Next.js are affected? (leave empty if unsure)

No response

Link to the code that reproduces this issue or a replay of the bug

https://github.com/thanosoncode/next-blog/blob/master/app/page.tsx

To Reproduce

Create a List component that renders a list and a DeleteForm that handles item delete using actions.

const List = async () => {
  const posts = (await prisma.post.findMany()) as Post[];

  return (
    <div className="flex flex-col gap-12">
      <div>
        <h1 className="text-2xl mb-8">All posts</h1>
        <section className="flex flex-col gap-3">
          {posts.map((post) => (
            <div
              key={post.id}
              className="flex gap-4 justify-between items-start"
            >
              <Link href={`/posts/${post.id}`} className="block underline">
                {post.title}
              </Link>
              {/* @ts-expect-error Server Component */}
              <DeleteForm id={post.id} />
            </div>
          ))}
        </section>
      </div>
    </div>
  );
};
const DeleteForm = async ({ id }: { id: string }) => {
  const deletePost = async () => {
    "use server";
    await prisma.post.delete({ where: { id } });
    revalidatePath("/");
  };

  return (
    <form action={deletePost}>
      <button className="text-sm" type="submit">
        delete
      </button>
    </form>
  );
};

Describe the Bug

If shorthand notation is used in: await prisma.post.delete({ where: { id } }); we get an unhandledError Error: id is not defined

If explicit notation is used in: await prisma.post.delete({ where: { id : id } }); everything works as expected

Screen.Recording.2023-05-27.at.7.44.47.AM.mov

Expected Behavior

Shorthand notation to work in actions.

Which browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

No response

NEXT-1254

@thanosoncode thanosoncode added the bug Issue was opened via the bug report template. label May 28, 2023
@shuding shuding added the linear: next Confirmed issue that is tracked by the Next.js team. label Jun 3, 2023
@shuding shuding changed the title Shorthand notation not working in actions [NEXT-1254] Shorthand notation not working in actions Jun 3, 2023
@shuding shuding self-assigned this Jun 3, 2023
@kodiakhq kodiakhq bot closed this as completed in #50937 Jun 8, 2023
kodiakhq bot pushed a commit that referenced this issue Jun 8, 2023
…0937)

This PR fixes the case of having a shorthand prop `{ id }` referenced from a non-top level closure in the Server Actions compiler. The main problem is that an `Ident` in `PropOrSpread` is not considered as an `Expr`.

See corresponding issue report and test case for more details.
fix #50445
fix NEXT-1254
@github-actions
Copy link
Contributor

github-actions bot commented Jul 8, 2023

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 8, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template. linear: next Confirmed issue that is tracked by the Next.js team.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants