-
Notifications
You must be signed in to change notification settings - Fork 27.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Assign proper function names to server actions (#71478)
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.
- Loading branch information
1 parent
1f46214
commit c54b8a3
Showing
46 changed files
with
727 additions
and
285 deletions.
There are no files selected for viewing
248 changes: 193 additions & 55 deletions
248
crates/next-custom-transforms/src/transforms/server_actions.rs
Large diffs are not rendered by default.
Oops, something went wrong.
5 changes: 2 additions & 3 deletions
5
crates/next-custom-transforms/tests/errors/server-actions/server-graph/6/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
/* __next_internal_action_entry_do_not_use__ {"6a88810ecce4a4e8b59d53b8327d7e98bbf251d7":"$$RSC_SERVER_ACTION_0"} */ import { registerServerReference } from "private-next-rsc-server-reference"; | ||
/* __next_internal_action_entry_do_not_use__ {} */ import { registerServerReference } from "private-next-rsc-server-reference"; | ||
import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption"; | ||
export default registerServerReference($$RSC_SERVER_ACTION_0, "6a88810ecce4a4e8b59d53b8327d7e98bbf251d7", null); | ||
export async function $$RSC_SERVER_ACTION_0() {} | ||
export default (()=>{}); |
2 changes: 1 addition & 1 deletion
2
crates/next-custom-transforms/tests/errors/server-actions/server-graph/7/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
/* __next_internal_action_entry_do_not_use__ {"6a88810ecce4a4e8b59d53b8327d7e98bbf251d7":"$$RSC_SERVER_ACTION_0"} */ import { registerServerReference } from "private-next-rsc-server-reference"; | ||
import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption"; | ||
export const $$RSC_SERVER_ACTION_0 = async function foo() {}; | ||
const foo = registerServerReference($$RSC_SERVER_ACTION_0, "6a88810ecce4a4e8b59d53b8327d7e98bbf251d7", null); | ||
export async function $$RSC_SERVER_ACTION_0() {} |
6 changes: 3 additions & 3 deletions
6
crates/next-custom-transforms/tests/errors/server-actions/server-graph/8/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
crates/next-custom-transforms/tests/fixture/server-actions/client/7/input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
'use server' | ||
|
||
export default async () => {} |
2 changes: 2 additions & 0 deletions
2
crates/next-custom-transforms/tests/fixture/server-actions/client/7/output.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
crates/next-custom-transforms/tests/fixture/server-actions/server/11/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 8 additions & 5 deletions
13
crates/next-custom-transforms/tests/fixture/server-actions/server/15/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 2 additions & 3 deletions
5
crates/next-custom-transforms/tests/fixture/server-actions/server/17/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 5 additions & 4 deletions
9
crates/next-custom-transforms/tests/fixture/server-actions/server/2/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,12 @@ | ||
/* __next_internal_action_entry_do_not_use__ {"6a88810ecce4a4e8b59d53b8327d7e98bbf251d7":"$$RSC_SERVER_ACTION_0","90b5db271335765a4b0eab01f044b381b5ebd5cd":"$$RSC_SERVER_ACTION_1"} */ import { registerServerReference } from "private-next-rsc-server-reference"; | ||
import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption"; | ||
var myAction = registerServerReference($$RSC_SERVER_ACTION_0, "6a88810ecce4a4e8b59d53b8327d7e98bbf251d7", null); | ||
export async function $$RSC_SERVER_ACTION_0(a, b, c) { | ||
export const $$RSC_SERVER_ACTION_0 = async function myAction(a, b, c) { | ||
console.log('a'); | ||
} | ||
}; | ||
var myAction = registerServerReference($$RSC_SERVER_ACTION_0, "6a88810ecce4a4e8b59d53b8327d7e98bbf251d7", null); | ||
export default function Page() { | ||
return <Button action={myAction}>Delete</Button>; | ||
} | ||
export const $$RSC_SERVER_ACTION_1 = async function() {}; | ||
// TODO: should use `action` as function name? | ||
export const action = withValidate(registerServerReference($$RSC_SERVER_ACTION_1, "90b5db271335765a4b0eab01f044b381b5ebd5cd", null)); | ||
export async function $$RSC_SERVER_ACTION_1() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 11 additions & 10 deletions
21
crates/next-custom-transforms/tests/fixture/server-actions/server/21/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,19 @@ | ||
/* __next_internal_action_entry_do_not_use__ {"1c36b06e398c97abe5d5d7ae8c672bfddf4e1b91":"$$RSC_SERVER_ACTION_2","90b5db271335765a4b0eab01f044b381b5ebd5cd":"$$RSC_SERVER_ACTION_1","9ed0cc47abc4e1c64320cf42b74ae60b58c40f00":"$$RSC_SERVER_ACTION_3"} */ import { registerServerReference } from "private-next-rsc-server-reference"; | ||
/* __next_internal_action_entry_do_not_use__ {"1c36b06e398c97abe5d5d7ae8c672bfddf4e1b91":"$$RSC_SERVER_ACTION_2","6a88810ecce4a4e8b59d53b8327d7e98bbf251d7":"$$RSC_SERVER_ACTION_0","90b5db271335765a4b0eab01f044b381b5ebd5cd":"$$RSC_SERVER_ACTION_1"} */ import { registerServerReference } from "private-next-rsc-server-reference"; | ||
import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption"; | ||
import { validator, another } from 'auth'; | ||
const x = 1; | ||
export const $$RSC_SERVER_ACTION_0 = async function($$ACTION_CLOSURE_BOUND, z) { | ||
var [$$ACTION_ARG_0] = await decryptActionBoundArgs("6a88810ecce4a4e8b59d53b8327d7e98bbf251d7", $$ACTION_CLOSURE_BOUND); | ||
return x + $$ACTION_ARG_0 + z; | ||
}; | ||
export default function Page() { | ||
const y = 1; | ||
return <Foo action={validator(registerServerReference($$RSC_SERVER_ACTION_1, "90b5db271335765a4b0eab01f044b381b5ebd5cd", null).bind(null, encryptActionBoundArgs("90b5db271335765a4b0eab01f044b381b5ebd5cd", [ | ||
return <Foo // TODO: should use `action` as function name? | ||
action={validator(registerServerReference($$RSC_SERVER_ACTION_0, "6a88810ecce4a4e8b59d53b8327d7e98bbf251d7", null).bind(null, encryptActionBoundArgs("6a88810ecce4a4e8b59d53b8327d7e98bbf251d7", [ | ||
y | ||
])))}/>; | ||
} | ||
export async function $$RSC_SERVER_ACTION_1($$ACTION_CLOSURE_BOUND, z) { | ||
var [$$ACTION_ARG_0] = await decryptActionBoundArgs("90b5db271335765a4b0eab01f044b381b5ebd5cd", $$ACTION_CLOSURE_BOUND); | ||
return x + $$ACTION_ARG_0 + z; | ||
} | ||
validator(registerServerReference($$RSC_SERVER_ACTION_2, "1c36b06e398c97abe5d5d7ae8c672bfddf4e1b91", null)); | ||
export async function $$RSC_SERVER_ACTION_2() {} | ||
another(validator(registerServerReference($$RSC_SERVER_ACTION_3, "9ed0cc47abc4e1c64320cf42b74ae60b58c40f00", null))); | ||
export async function $$RSC_SERVER_ACTION_3() {} | ||
export const $$RSC_SERVER_ACTION_1 = async function() {}; | ||
validator(registerServerReference($$RSC_SERVER_ACTION_1, "90b5db271335765a4b0eab01f044b381b5ebd5cd", null)); | ||
export const $$RSC_SERVER_ACTION_2 = async function() {}; | ||
another(validator(registerServerReference($$RSC_SERVER_ACTION_2, "1c36b06e398c97abe5d5d7ae8c672bfddf4e1b91", null))); |
18 changes: 10 additions & 8 deletions
18
crates/next-custom-transforms/tests/fixture/server-actions/server/22/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,17 @@ | ||
/* __next_internal_action_entry_do_not_use__ {"1c36b06e398c97abe5d5d7ae8c672bfddf4e1b91":"$$RSC_SERVER_ACTION_2","6a88810ecce4a4e8b59d53b8327d7e98bbf251d7":"$$RSC_SERVER_ACTION_0","c18c215a6b7cdc64bf709f3a714ffdef1bf9651d":"default","f14702b5a021dd117f7ec7a3c838f397c2046d3b":"action"} */ import { registerServerReference } from "private-next-rsc-server-reference"; | ||
/* __next_internal_action_entry_do_not_use__ {"c18c215a6b7cdc64bf709f3a714ffdef1bf9651d":"default","f14702b5a021dd117f7ec7a3c838f397c2046d3b":"action"} */ import { registerServerReference } from "private-next-rsc-server-reference"; | ||
import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption"; | ||
import { validator } from 'auth'; | ||
export const action = validator(registerServerReference($$RSC_SERVER_ACTION_0, "6a88810ecce4a4e8b59d53b8327d7e98bbf251d7", null)); | ||
export async function $$RSC_SERVER_ACTION_0() {} | ||
export default $$RSC_SERVER_ACTION_1 = validator(registerServerReference($$RSC_SERVER_ACTION_2, "1c36b06e398c97abe5d5d7ae8c672bfddf4e1b91", null)); | ||
var $$RSC_SERVER_ACTION_1; | ||
export async function $$RSC_SERVER_ACTION_2() {} | ||
export const action = validator(async ()=>{}); | ||
export default $$RSC_SERVER_ACTION_0 = validator(async ()=>{}); | ||
var $$RSC_SERVER_ACTION_0; | ||
Object.defineProperty($$RSC_SERVER_ACTION_0, "name", { | ||
"value": "default", | ||
"writable": false | ||
}); | ||
import { ensureServerEntryExports } from "private-next-rsc-action-validate"; | ||
ensureServerEntryExports([ | ||
action, | ||
$$RSC_SERVER_ACTION_1 | ||
$$RSC_SERVER_ACTION_0 | ||
]); | ||
registerServerReference(action, "f14702b5a021dd117f7ec7a3c838f397c2046d3b", null); | ||
registerServerReference($$RSC_SERVER_ACTION_1, "c18c215a6b7cdc64bf709f3a714ffdef1bf9651d", null); | ||
registerServerReference($$RSC_SERVER_ACTION_0, "c18c215a6b7cdc64bf709f3a714ffdef1bf9651d", null); |
Oops, something went wrong.