Files
Hendrik LiebauandGitHub 1f25118390 Fix name tracking for closures in server actions transform (#79657)
When a server function passes a closure to a method on a closed-over
value (e.g. an array), we must correctly track the value itself so that
it's included in the bound arguments.

For example, in this snippet, `list` must be bound to the server action:

```js
export function Component({ list }) {
  return (
    <form
      action={async () => {
        'use server'
        console.log(list.find((x) => !!x))
      }}
    >
      <button>submit</button>
    </form>
  )
}
```

This use case used to work but was accidentally broken by #73189.

fixes #79608
fixes #77247
closes NAR-8
2025-05-27 17:23:25 +02:00

30 lines
504 B
JavaScript

export function ComponentA({ list, y }) {
return (
<form
action={async () => {
'use server'
console.log(list.find((x) => x === y))
}}
>
<button>submit</button>
</form>
)
}
export function ComponentB({ list, y }) {
return (
<form
action={async () => {
'use server'
console.log(
list.find(function (x) {
return x === y
})
)
}}
>
<button>submit</button>
</form>
)
}