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

[Server Actions] Calling server actions causes TypeError: Cannot redefine property: $$id to throw #61183

Closed
mwskwong opened this issue Jan 26, 2024 · 1 comment · Fixed by #61244
Assignees
Labels
bug Issue was opened via the bug report template. locked

Comments

@mwskwong
Copy link

mwskwong commented Jan 26, 2024

Link to the code that reproduces this issue

https://github.com/mwskwong/server-actions-build-fail

To Reproduce

  1. Call any server actions in a v14.1.1-canary.10 or above Next.js app

Current vs. Expected behavior

Current:
The following error is thrown when an arbitrary server action is called.

TypeError: Cannot redefine property: $$id
    at Function.defineProperties (<anonymous>)
    at t.registerServerReference (/server-actions-build-fail/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:141808)
    at i (/server-actions-build-fail/.next/server/app/page.js:1:18906)
    at 4426 (/server-actions-build-fail/.next/server/app/page.js:1:16042)
    at t (/server-actions-build-fail/.next/server/webpack-runtime.js:1:127)
    at 801 (/server-actions-build-fail/.next/server/app/page.js:1:16510)
    at Function.t (/server-actions-build-fail/.next/server/webpack-runtime.js:1:127)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async collectGenerateParams (/server-actions-build-fail/node_modules/next/dist/build/utils.js:920:21)
    at async /server-actions-build-fail/node_modules/next/dist/build/utils.js:1143:17

Expected: No error prompted

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 23.2.0: Wed Nov 15 21:53:18 PST 2023; root:xnu-10002.61.3~2/RELEASE_ARM64_T6000
Binaries:
  Node: 20.10.0
  npm: 10.2.3
  Yarn: 1.22.19
  pnpm: N/A
Relevant Packages:
  next: 14.1.1-canary.12 // Latest available version is detected (14.1.1-canary.12).
  eslint-config-next: 14.1.1-canary.12
  react: 18.2.0
  react-dom: 18.2.0
  typescript: 5.3.3
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

App Router

Which stage(s) are affected? (Select all that apply)

next build (local), next start (local)

Additional context

  • This issue starts appearing in v14.1.1-canary.10
  • Although the reproduction calls the server action directly in an RSC and causes the project to fail to build, the issue is also observed when calling a server action upon user interactions (e.g. on button click), except it will be a runtime error instead.
  • Potentially related to Error: Cannot redefine property: $$id in action-proxy.ts #54655
@mwskwong mwskwong added the bug Issue was opened via the bug report template. label Jan 26, 2024
@shuding shuding self-assigned this Jan 26, 2024
@huozhi huozhi closed this as completed in ecef83a Jan 27, 2024
Copy link
Contributor

This closed issue has been automatically locked because it had no new activity for 2 weeks. 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 Feb 11, 2024
ijjk pushed a commit that referenced this issue Feb 28, 2024
When we apply `createActionProxy` twice to the same value, it currently
errors because we can't override the ID of it.

This PR makes sure that 1) when the value already have an ID defined, we
skip setting it again; 2) all the action IDs are being tracked even for
duplicated ones.

Note that it's technically impossible to "detect" the duplication here
(via static analyzation) and only set it once. For example:

```ts
'use server'

export async function foo () {}
export const bar = a_value_we_dont_know_yet ? foo : async () => {}
```

So, the compiler will always wrap `createActionProxy` for every exported
value and assume they're different Server Actions (hence different IDs).
With this fix, if we find that it's already defined before, we just
return the defined reference as they're strictly identical so the ID
does't matter.

Closes #54655, closes #61183.

Closes NEXT-2264
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. locked
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants