mirror of
https://github.com/hanzoai/next.js.git
synced 2026-09-24 17:00:51 +00:00
This PR adjusts the server action transforms to assign proper function names for the generated server reference proxies. - If the original function has a name, this name is used. - If a function expression is assigned to a variable, the variable's name is used. - If an anonymous function expression is assigned to a prop, the prop's name is used. In addition, this PR simplifies the output for exported functions, avoiding unnecessary `registerServerReference` calls. It also fixes the source mapping of default exported server actions. **Before:** <img width="890" alt="before" src="https://github.com/user-attachments/assets/a3d6a5f8-d48e-474d-8f03-b49306fb704f"> **After:** <img width="890" alt="after" src="https://github.com/user-attachments/assets/8f332690-6c26-46f1-9eef-7680f47ea578"> Next up, we will do the same for `'use cache'` functions.
61 lines
1.4 KiB
TypeScript
61 lines
1.4 KiB
TypeScript
import { Form } from './form'
|
|
import defaultAction1, { foo, bar, baz, qux } from './actions1'
|
|
import defaultAction2 from './actions2'
|
|
import defaultAction3 from './actions3'
|
|
import Link from 'next/link'
|
|
import { ServerComponent } from './server-component'
|
|
|
|
export default function Page() {
|
|
const action1 = async () => {
|
|
'use server'
|
|
|
|
return 'declarator arrow function expression'
|
|
}
|
|
|
|
async function action2() {
|
|
'use server'
|
|
|
|
return 'function declaration'
|
|
}
|
|
|
|
return (
|
|
<main>
|
|
<ServerComponent />
|
|
<Form id="form-1" action={defaultAction1} />
|
|
<Form id="form-2" action={defaultAction2} />
|
|
<Form id="form-3" action={defaultAction3} />
|
|
<Form id="form-4" action={foo} />
|
|
<Form id="form-5" action={bar} />
|
|
<Form id="form-6" action={baz} />
|
|
<Form id="form-7" action={qux} />
|
|
<Form id="form-8" action={action1} />
|
|
<Form id="form-9" action={action2} />
|
|
<Form
|
|
id="form-10"
|
|
action={async () => {
|
|
'use server'
|
|
|
|
return 'arrow function expression'
|
|
}}
|
|
/>
|
|
<Form
|
|
id="form-11"
|
|
action={async function () {
|
|
'use server'
|
|
|
|
return 'anonymous function expression'
|
|
}}
|
|
/>
|
|
<Form
|
|
id="form-12"
|
|
action={async function myAction() {
|
|
'use server'
|
|
|
|
return 'named function expression'
|
|
}}
|
|
/>
|
|
<Link href="/client">client component page</Link>
|
|
</main>
|
|
)
|
|
}
|