mirror of
https://github.com/hanzoai/next.js.git
synced 2026-10-30 14:46:38 +00:00
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
30 lines
504 B
JavaScript
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>
|
|
)
|
|
}
|