Unverified Commit 9471fb85 authored by Shu Ding's avatar Shu Ding Committed by GitHub

Improve Server Actions compiler (#58391)

Currently to make inline-defined Server Actions work, the compiler hoists the actual `"use server"` function to the module level and convert the inlined function to a parentheses expression that creates a noop wrapper function and wraps it with the proxy. This works fine however expressions are still different from declarations (#57392). So there're some details that can't be aligned well.

With this change, we're going to make the compilation for the two types of inline-defined Server Actions more robust and more lightweight:

#### 1. Expressions

```jsx
const action = async () => { "use server" ... }
const action = async function () { "use server" ... }
const action = async function named () { "use server" ... }
foo={async function () { "use server" ... }}
...
```

These expressions can directly be replaced with a new expression `createActionProxy("id", hoisted_action)`. A `.bind(...)` member call can be followed if it needs to bind any variables from the closure level.

#### 2. Declarations

```js
async function named () { "use server" ... }
```

In this case, we replace all the same `named` idents to be the expression `createActionProxy("id", hoisted_action)`, and removed that function declaration.

With these changes, these will be fewer structural changes to the AST and the code is more performant.

The PR also changes it to use React's `registerServerReference` method directly instead of our in-house implementation inside `createActionProxy`.

Another small change is to stabilize the comment header to use `BTreeMap` inside the SWC transform. Otherwise the test snapshots will randomly mismatch.

Closes #57392.
parent ce183f6e
/* __next_internal_client_entry_do_not_use__ default auto */ /* __next_internal_action_entry_do_not_use__ {"6d53ce510b2e36499b8f56038817b9bad86cabb4":"$$ACTION_0"} */ import { createActionProxy } from "private-next-rsc-action-proxy";
/* __next_internal_client_entry_do_not_use__ default auto */ /* __next_internal_action_entry_do_not_use__ {"6d53ce510b2e36499b8f56038817b9bad86cabb4":"$$ACTION_0"} */ export async function $$ACTION_0() {}
export default function App() {
async function fn(...args) {
return $$ACTION_0.apply(null, (fn.$$bound || []).concat(args));
}
createActionProxy("6d53ce510b2e36499b8f56038817b9bad86cabb4", null, fn, $$ACTION_0);
function fn() {}
return <div>App</div>;
}
export async function $$ACTION_0() {}
......@@ -5,4 +5,4 @@ import { ensureServerEntryExports } from "private-next-rsc-action-validate";
ensureServerEntryExports([
foo
]);
createActionProxy("ab21efdafbe611287bc25c0462b1e0510d13e48b", null, foo);
createActionProxy("ab21efdafbe611287bc25c0462b1e0510d13e48b", foo);
......@@ -6,4 +6,4 @@ import { ensureServerEntryExports } from "private-next-rsc-action-validate";
ensureServerEntryExports([
bar
]);
createActionProxy("ac840dcaf5e8197cb02b7f3a43c119b7a770b272", null, bar);
createActionProxy("ac840dcaf5e8197cb02b7f3a43c119b7a770b272", bar);
......@@ -5,4 +5,4 @@ import { ensureServerEntryExports } from "private-next-rsc-action-validate";
ensureServerEntryExports([
x
]);
createActionProxy("b78c261f135a7a852508c2920bd7228020ff4bd7", null, x);
createActionProxy("b78c261f135a7a852508c2920bd7228020ff4bd7", x);
/* __next_internal_action_entry_do_not_use__ {"188d5d945750dc32e2c842b93c75a65763d4a922":"$$ACTION_1"} */ import { createActionProxy } from "private-next-rsc-action-proxy";
import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption";
const foo = ($$ACTION_0 = async (...args)=>$$ACTION_1.apply(null, ($$ACTION_0.$$bound || []).concat(args)), createActionProxy("188d5d945750dc32e2c842b93c75a65763d4a922", null, $$ACTION_0, $$ACTION_1), $$ACTION_0);
export var $$ACTION_1 = ()=>{};
var $$ACTION_0;
const foo = createActionProxy("188d5d945750dc32e2c842b93c75a65763d4a922", $$ACTION_1);
export async function $$ACTION_1() {}
/* __next_internal_action_entry_do_not_use__ {"188d5d945750dc32e2c842b93c75a65763d4a922":"$$ACTION_1"} */ import { createActionProxy } from "private-next-rsc-action-proxy";
import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption";
const foo = ($$ACTION_0 = async (...args)=>$$ACTION_1.apply(null, ($$ACTION_0.$$bound || []).concat(args)), createActionProxy("188d5d945750dc32e2c842b93c75a65763d4a922", null, $$ACTION_0, $$ACTION_1), $$ACTION_0);
export var $$ACTION_1 = async ()=>{
const foo = createActionProxy("188d5d945750dc32e2c842b93c75a65763d4a922", $$ACTION_1);
export async function $$ACTION_1() {
'use strict';
};
var $$ACTION_0;
}
const bar = async ()=>{
const x = 1;
// prettier-ignore
......
// app/send.ts
/* __next_internal_action_entry_do_not_use__ {"c18c215a6b7cdc64bf709f3a714ffdef1bf9651d":"default","e10665baac148856374b2789aceb970f66fec33e":"myAction"} */ import { createActionProxy } from "private-next-rsc-action-proxy";
/* __next_internal_action_entry_do_not_use__ {"c18c215a6b7cdc64bf709f3a714ffdef1bf9651d":"default","e10665baac148856374b2789aceb970f66fec33e":"myAction"} */ export default createServerReference("c18c215a6b7cdc64bf709f3a714ffdef1bf9651d");
import { createServerReference } from "private-next-rsc-action-client-wrapper";
export var myAction = createServerReference("e10665baac148856374b2789aceb970f66fec33e");
export default createServerReference("c18c215a6b7cdc64bf709f3a714ffdef1bf9651d");
// app/send.ts
/* __next_internal_action_entry_do_not_use__ {"ab21efdafbe611287bc25c0462b1e0510d13e48b":"foo"} */ import { createActionProxy } from "private-next-rsc-action-proxy";
/* __next_internal_action_entry_do_not_use__ {"ab21efdafbe611287bc25c0462b1e0510d13e48b":"foo"} */ export var foo = createServerReference("ab21efdafbe611287bc25c0462b1e0510d13e48b");
import { createServerReference } from "private-next-rsc-action-client-wrapper";
export var foo = createServerReference("ab21efdafbe611287bc25c0462b1e0510d13e48b");
/* __next_internal_action_entry_do_not_use__ {"bd336abe00c3c59da66acb696fc8e151d8e54ea4":"sampleFunction","a0c73dd6f5af839e3335c6b19262ecb86cca6af4":"sampleFunction2","f03b256ee88a51700367acee3082894e25e6e7d9":"sampleFunction4","d4f2e95bc745b6500b439c0847003511748c8ece":"sampleFunction3"} */ import { createActionProxy } from "private-next-rsc-action-proxy";
/* __next_internal_action_entry_do_not_use__ {"a0c73dd6f5af839e3335c6b19262ecb86cca6af4":"sampleFunction2","bd336abe00c3c59da66acb696fc8e151d8e54ea4":"sampleFunction","d4f2e95bc745b6500b439c0847003511748c8ece":"sampleFunction3","f03b256ee88a51700367acee3082894e25e6e7d9":"sampleFunction4"} */ export var sampleFunction4 = createServerReference("f03b256ee88a51700367acee3082894e25e6e7d9");
import { createServerReference } from "private-next-rsc-action-client-wrapper";
export var sampleFunction = createServerReference("bd336abe00c3c59da66acb696fc8e151d8e54ea4");
export var sampleFunction2 = createServerReference("a0c73dd6f5af839e3335c6b19262ecb86cca6af4");
export var sampleFunction3 = createServerReference("d4f2e95bc745b6500b439c0847003511748c8ece");
export var sampleFunction4 = createServerReference("f03b256ee88a51700367acee3082894e25e6e7d9");
/* __next_internal_action_entry_do_not_use__ {"ac840dcaf5e8197cb02b7f3a43c119b7a770b272":"bar"} */ import { createActionProxy } from "private-next-rsc-action-proxy";
/* __next_internal_action_entry_do_not_use__ {"ac840dcaf5e8197cb02b7f3a43c119b7a770b272":"bar"} */ export var bar = createServerReference("ac840dcaf5e8197cb02b7f3a43c119b7a770b272");
import { createServerReference } from "private-next-rsc-action-client-wrapper";
export var bar = createServerReference("ac840dcaf5e8197cb02b7f3a43c119b7a770b272");
......@@ -2,16 +2,11 @@
import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption";
import deleteFromDb from 'db';
export function Item({ id1, id2 }) {
async function deleteItem(...args) {
return $$ACTION_0.apply(null, (deleteItem.$$bound || []).concat(args));
}
createActionProxy("6d53ce510b2e36499b8f56038817b9bad86cabb4", [
encryptActionBoundArgs("6d53ce510b2e36499b8f56038817b9bad86cabb4", [
id1,
id2
])
], deleteItem, $$ACTION_0);
return <Button action={deleteItem}>Delete</Button>;
function deleteItem() {}
return <Button action={createActionProxy("6d53ce510b2e36499b8f56038817b9bad86cabb4", $$ACTION_0).bind(null, encryptActionBoundArgs("6d53ce510b2e36499b8f56038817b9bad86cabb4", [
id1,
id2
]))}>Delete</Button>;
}
export async function $$ACTION_0($$ACTION_CLOSURE_BOUND) {
var [$$ACTION_ARG_0, $$ACTION_ARG_1] = await decryptActionBoundArgs("6d53ce510b2e36499b8f56038817b9bad86cabb4", $$ACTION_CLOSURE_BOUND);
......@@ -23,17 +18,14 @@ export default function Home() {
name: 'John',
test: 'test'
};
const action = ($$ACTION_1 = async (...args)=>$$ACTION_2.apply(null, ($$ACTION_1.$$bound || []).concat(args)), createActionProxy("9878bfa39811ca7650992850a8751f9591b6a557", [
encryptActionBoundArgs("9878bfa39811ca7650992850a8751f9591b6a557", [
info.name,
info.test
])
], $$ACTION_1, $$ACTION_2), $$ACTION_1);
const action = createActionProxy("9878bfa39811ca7650992850a8751f9591b6a557", $$ACTION_2).bind(null, encryptActionBoundArgs("9878bfa39811ca7650992850a8751f9591b6a557", [
info.name,
info.test
]));
return null;
}
export var $$ACTION_2 = async ($$ACTION_CLOSURE_BOUND)=>{
export async function $$ACTION_2($$ACTION_CLOSURE_BOUND) {
var [$$ACTION_ARG_0, $$ACTION_ARG_1] = await decryptActionBoundArgs("9878bfa39811ca7650992850a8751f9591b6a557", $$ACTION_CLOSURE_BOUND);
console.log($$ACTION_ARG_0);
console.log($$ACTION_ARG_1);
};
var $$ACTION_1;
}
......@@ -5,4 +5,4 @@ import { ensureServerEntryExports } from "private-next-rsc-action-validate";
ensureServerEntryExports([
foo
]);
createActionProxy("c18c215a6b7cdc64bf709f3a714ffdef1bf9651d", null, foo);
createActionProxy("c18c215a6b7cdc64bf709f3a714ffdef1bf9651d", foo);
......@@ -5,4 +5,4 @@ import { ensureServerEntryExports } from "private-next-rsc-action-validate";
ensureServerEntryExports([
$$ACTION_0
]);
createActionProxy("c18c215a6b7cdc64bf709f3a714ffdef1bf9651d", null, $$ACTION_0);
createActionProxy("c18c215a6b7cdc64bf709f3a714ffdef1bf9651d", $$ACTION_0);
......@@ -6,4 +6,4 @@ import { ensureServerEntryExports } from "private-next-rsc-action-validate";
ensureServerEntryExports([
foo
]);
createActionProxy("c18c215a6b7cdc64bf709f3a714ffdef1bf9651d", null, foo);
createActionProxy("c18c215a6b7cdc64bf709f3a714ffdef1bf9651d", foo);
......@@ -9,5 +9,5 @@ ensureServerEntryExports([
foo,
bar
]);
createActionProxy("c18c215a6b7cdc64bf709f3a714ffdef1bf9651d", null, foo);
createActionProxy("ac840dcaf5e8197cb02b7f3a43c119b7a770b272", null, bar);
createActionProxy("c18c215a6b7cdc64bf709f3a714ffdef1bf9651d", foo);
createActionProxy("ac840dcaf5e8197cb02b7f3a43c119b7a770b272", bar);
......@@ -7,4 +7,4 @@ import { ensureServerEntryExports } from "private-next-rsc-action-validate";
ensureServerEntryExports([
foo
]);
createActionProxy("ab21efdafbe611287bc25c0462b1e0510d13e48b", null, foo);
createActionProxy("ab21efdafbe611287bc25c0462b1e0510d13e48b", foo);
......@@ -8,4 +8,4 @@ import { ensureServerEntryExports } from "private-next-rsc-action-validate";
ensureServerEntryExports([
$$ACTION_0
]);
createActionProxy("c18c215a6b7cdc64bf709f3a714ffdef1bf9651d", null, $$ACTION_0);
createActionProxy("c18c215a6b7cdc64bf709f3a714ffdef1bf9651d", $$ACTION_0);
/* __next_internal_action_entry_do_not_use__ {"9c0dd1f7c2b3f41d32e10f5c437de3d67ad32c6c":"$$ACTION_4","9878bfa39811ca7650992850a8751f9591b6a557":"$$ACTION_2","188d5d945750dc32e2c842b93c75a65763d4a922":"$$ACTION_1"} */ import { createActionProxy } from "private-next-rsc-action-proxy";
/* __next_internal_action_entry_do_not_use__ {"188d5d945750dc32e2c842b93c75a65763d4a922":"$$ACTION_1","9878bfa39811ca7650992850a8751f9591b6a557":"$$ACTION_2","9c0dd1f7c2b3f41d32e10f5c437de3d67ad32c6c":"$$ACTION_4"} */ import { createActionProxy } from "private-next-rsc-action-proxy";
import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption";
import deleteFromDb from 'db';
const v1 = 'v1';
export function Item({ id1, id2 }) {
const v2 = id2;
const deleteItem = ($$ACTION_0 = async (...args)=>$$ACTION_1.apply(null, ($$ACTION_0.$$bound || []).concat(args)), createActionProxy("188d5d945750dc32e2c842b93c75a65763d4a922", [
encryptActionBoundArgs("188d5d945750dc32e2c842b93c75a65763d4a922", [
id1,
v2
])
], $$ACTION_0, $$ACTION_1), $$ACTION_0);
const deleteItem = createActionProxy("188d5d945750dc32e2c842b93c75a65763d4a922", $$ACTION_1).bind(null, encryptActionBoundArgs("188d5d945750dc32e2c842b93c75a65763d4a922", [
id1,
v2
]));
return <Button action={deleteItem}>Delete</Button>;
}
export var $$ACTION_1 = async ($$ACTION_CLOSURE_BOUND)=>{
export async function $$ACTION_1($$ACTION_CLOSURE_BOUND) {
var [$$ACTION_ARG_0, $$ACTION_ARG_1] = await decryptActionBoundArgs("188d5d945750dc32e2c842b93c75a65763d4a922", $$ACTION_CLOSURE_BOUND);
await deleteFromDb($$ACTION_ARG_0);
await deleteFromDb(v1);
await deleteFromDb($$ACTION_ARG_1);
};
var $$ACTION_0;
}
const f = (x)=>{
async function g(...args) {
return $$ACTION_2.apply(null, (g.$$bound || []).concat(args));
}
createActionProxy("9878bfa39811ca7650992850a8751f9591b6a557", [
encryptActionBoundArgs("9878bfa39811ca7650992850a8751f9591b6a557", [
x
])
], g, $$ACTION_2);
function g() {}
};
export async function $$ACTION_2($$ACTION_CLOSURE_BOUND, y, ...z) {
var [$$ACTION_ARG_0] = await decryptActionBoundArgs("9878bfa39811ca7650992850a8751f9591b6a557", $$ACTION_CLOSURE_BOUND);
return $$ACTION_ARG_0 + y + z[0];
}
const g = (x)=>{
f = ($$ACTION_3 = async (...args)=>$$ACTION_4.apply(null, ($$ACTION_3.$$bound || []).concat(args)), createActionProxy("9c0dd1f7c2b3f41d32e10f5c437de3d67ad32c6c", [
encryptActionBoundArgs("9c0dd1f7c2b3f41d32e10f5c437de3d67ad32c6c", [
x
])
], $$ACTION_3, $$ACTION_4), $$ACTION_3);
f = createActionProxy("9c0dd1f7c2b3f41d32e10f5c437de3d67ad32c6c", $$ACTION_4).bind(null, encryptActionBoundArgs("9c0dd1f7c2b3f41d32e10f5c437de3d67ad32c6c", [
x
]));
};
export var $$ACTION_4 = async ($$ACTION_CLOSURE_BOUND, y, ...z)=>{
export async function $$ACTION_4($$ACTION_CLOSURE_BOUND, y, ...z) {
var [$$ACTION_ARG_0] = await decryptActionBoundArgs("9c0dd1f7c2b3f41d32e10f5c437de3d67ad32c6c", $$ACTION_CLOSURE_BOUND);
return $$ACTION_ARG_0 + y + z[0];
};
var $$ACTION_3;
}
......@@ -8,5 +8,5 @@ ensureServerEntryExports([
foo,
bar
]);
createActionProxy("ab21efdafbe611287bc25c0462b1e0510d13e48b", null, foo);
createActionProxy("ac840dcaf5e8197cb02b7f3a43c119b7a770b272", null, bar);
createActionProxy("ab21efdafbe611287bc25c0462b1e0510d13e48b", foo);
createActionProxy("ac840dcaf5e8197cb02b7f3a43c119b7a770b272", bar);
......@@ -6,25 +6,19 @@ export function Item({ id1, id2 }) {
const v2 = id2;
return <>
<Button action={$$ACTION_0 = async (...args)=>$$ACTION_1.apply(null, ($$ACTION_0.$$bound || []).concat(args)), createActionProxy("188d5d945750dc32e2c842b93c75a65763d4a922", [
encryptActionBoundArgs("188d5d945750dc32e2c842b93c75a65763d4a922", [
id1,
v2
])
], $$ACTION_0, $$ACTION_1), $$ACTION_0}>
<Button action={createActionProxy("188d5d945750dc32e2c842b93c75a65763d4a922", $$ACTION_1).bind(null, encryptActionBoundArgs("188d5d945750dc32e2c842b93c75a65763d4a922", [
id1,
v2
]))}>
Delete
</Button>
<Button action={$$ACTION_2 = async function(...args) {
return $$ACTION_3.apply(null, ($$ACTION_2.$$bound || []).concat(args));
}, createActionProxy("56a859f462d35a297c46a1bbd1e6a9058c104ab8", [
encryptActionBoundArgs("56a859f462d35a297c46a1bbd1e6a9058c104ab8", [
id1,
v2
])
], $$ACTION_2, $$ACTION_3), $$ACTION_2}>
<Button action={createActionProxy("56a859f462d35a297c46a1bbd1e6a9058c104ab8", $$ACTION_3).bind(null, encryptActionBoundArgs("56a859f462d35a297c46a1bbd1e6a9058c104ab8", [
id1,
v2
]))}>
Delete
......@@ -32,17 +26,15 @@ export function Item({ id1, id2 }) {
</>;
}
export var $$ACTION_1 = async ($$ACTION_CLOSURE_BOUND)=>{
export async function $$ACTION_1($$ACTION_CLOSURE_BOUND) {
var [$$ACTION_ARG_0, $$ACTION_ARG_1] = await decryptActionBoundArgs("188d5d945750dc32e2c842b93c75a65763d4a922", $$ACTION_CLOSURE_BOUND);
await deleteFromDb($$ACTION_ARG_0);
await deleteFromDb(v1);
await deleteFromDb($$ACTION_ARG_1);
};
var $$ACTION_0;
}
export async function $$ACTION_3($$ACTION_CLOSURE_BOUND) {
var [$$ACTION_ARG_0, $$ACTION_ARG_1] = await decryptActionBoundArgs("56a859f462d35a297c46a1bbd1e6a9058c104ab8", $$ACTION_CLOSURE_BOUND);
await deleteFromDb($$ACTION_ARG_0);
await deleteFromDb(v1);
await deleteFromDb($$ACTION_ARG_1);
}
var $$ACTION_2;
......@@ -3,11 +3,9 @@ import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc
export function Item({ value }) {
return <>
<Button action={$$ACTION_0 = async (...args)=>$$ACTION_1.apply(null, ($$ACTION_0.$$bound || []).concat(args)), createActionProxy("188d5d945750dc32e2c842b93c75a65763d4a922", [
encryptActionBoundArgs("188d5d945750dc32e2c842b93c75a65763d4a922", [
value
])
], $$ACTION_0, $$ACTION_1), $$ACTION_0}>
<Button action={createActionProxy("188d5d945750dc32e2c842b93c75a65763d4a922", $$ACTION_1).bind(null, encryptActionBoundArgs("188d5d945750dc32e2c842b93c75a65763d4a922", [
value
]))}>
Multiple
......@@ -15,8 +13,7 @@ export function Item({ value }) {
</>;
}
export var $$ACTION_1 = async ($$ACTION_CLOSURE_BOUND, value2)=>{
export async function $$ACTION_1($$ACTION_CLOSURE_BOUND, value2) {
var [$$ACTION_ARG_0] = await decryptActionBoundArgs("188d5d945750dc32e2c842b93c75a65763d4a922", $$ACTION_CLOSURE_BOUND);
return $$ACTION_ARG_0 * value2;
};
var $$ACTION_0;
}
/* __next_internal_action_entry_do_not_use__ {"6d53ce510b2e36499b8f56038817b9bad86cabb4":"$$ACTION_0","9878bfa39811ca7650992850a8751f9591b6a557":"$$ACTION_2"} */ import { createActionProxy } from "private-next-rsc-action-proxy";
import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption";
async function myAction(...args) {
return $$ACTION_0.apply(null, (myAction.$$bound || []).concat(args));
}
createActionProxy("6d53ce510b2e36499b8f56038817b9bad86cabb4", null, myAction, $$ACTION_0);
function myAction() {}
export async function $$ACTION_0(a, b, c) {
console.log('a');
}
export default function Page() {
return <Button action={myAction}>Delete</Button>;
return <Button action={createActionProxy("6d53ce510b2e36499b8f56038817b9bad86cabb4", $$ACTION_0)}>Delete</Button>;
}
export const action = withValidate(($$ACTION_1 = async (...args)=>$$ACTION_2.apply(null, ($$ACTION_1.$$bound || []).concat(args)), createActionProxy("9878bfa39811ca7650992850a8751f9591b6a557", null, $$ACTION_1, $$ACTION_2), $$ACTION_1));
export var $$ACTION_2 = async ()=>{};
var $$ACTION_1;
export const action = withValidate(createActionProxy("9878bfa39811ca7650992850a8751f9591b6a557", $$ACTION_2));
export async function $$ACTION_2() {}
......@@ -8,4 +8,4 @@ import { ensureServerEntryExports } from "private-next-rsc-action-validate";
ensureServerEntryExports([
foo
]);
createActionProxy("c18c215a6b7cdc64bf709f3a714ffdef1bf9651d", null, foo);
createActionProxy("c18c215a6b7cdc64bf709f3a714ffdef1bf9651d", foo);
/* __next_internal_action_entry_do_not_use__ {"1383664d1dc2d9cfe33b88df3fa0eaffef8b99bc":"$$ACTION_5","56a859f462d35a297c46a1bbd1e6a9058c104ab8":"$$ACTION_3","188d5d945750dc32e2c842b93c75a65763d4a922":"$$ACTION_1"} */ import { createActionProxy } from "private-next-rsc-action-proxy";
/* __next_internal_action_entry_do_not_use__ {"1383664d1dc2d9cfe33b88df3fa0eaffef8b99bc":"$$ACTION_5","188d5d945750dc32e2c842b93c75a65763d4a922":"$$ACTION_1","56a859f462d35a297c46a1bbd1e6a9058c104ab8":"$$ACTION_3"} */ import { createActionProxy } from "private-next-rsc-action-proxy";
import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption";
import { validator, another } from 'auth';
const x = 1;
export default function Page() {
const y = 1;
return <Foo action={validator(($$ACTION_0 = async function(...args) {
return $$ACTION_1.apply(null, ($$ACTION_0.$$bound || []).concat(args));
}, createActionProxy("188d5d945750dc32e2c842b93c75a65763d4a922", [
encryptActionBoundArgs("188d5d945750dc32e2c842b93c75a65763d4a922", [
y
])
], $$ACTION_0, $$ACTION_1), $$ACTION_0))}/>;
return <Foo action={validator(createActionProxy("188d5d945750dc32e2c842b93c75a65763d4a922", $$ACTION_1).bind(null, encryptActionBoundArgs("188d5d945750dc32e2c842b93c75a65763d4a922", [
y
])))}/>;
}
export async function $$ACTION_1($$ACTION_CLOSURE_BOUND, z) {
var [$$ACTION_ARG_0] = await decryptActionBoundArgs("188d5d945750dc32e2c842b93c75a65763d4a922", $$ACTION_CLOSURE_BOUND);
return x + $$ACTION_ARG_0 + z;
}
var $$ACTION_0;
validator(($$ACTION_2 = async (...args)=>$$ACTION_3.apply(null, ($$ACTION_2.$$bound || []).concat(args)), createActionProxy("56a859f462d35a297c46a1bbd1e6a9058c104ab8", null, $$ACTION_2, $$ACTION_3), $$ACTION_2));
export var $$ACTION_3 = async ()=>{};
var $$ACTION_2;
another(validator(($$ACTION_4 = async (...args)=>$$ACTION_5.apply(null, ($$ACTION_4.$$bound || []).concat(args)), createActionProxy("1383664d1dc2d9cfe33b88df3fa0eaffef8b99bc", null, $$ACTION_4, $$ACTION_5), $$ACTION_4)));
export var $$ACTION_5 = async ()=>{};
var $$ACTION_4;
validator(createActionProxy("56a859f462d35a297c46a1bbd1e6a9058c104ab8", $$ACTION_3));
export async function $$ACTION_3() {}
another(validator(createActionProxy("1383664d1dc2d9cfe33b88df3fa0eaffef8b99bc", $$ACTION_5)));
export async function $$ACTION_5() {}
......@@ -9,5 +9,5 @@ ensureServerEntryExports([
action,
$$ACTION_0
]);
createActionProxy("f14702b5a021dd117f7ec7a3c838f397c2046d3b", null, action);
createActionProxy("c18c215a6b7cdc64bf709f3a714ffdef1bf9651d", null, $$ACTION_0);
createActionProxy("f14702b5a021dd117f7ec7a3c838f397c2046d3b", action);
createActionProxy("c18c215a6b7cdc64bf709f3a714ffdef1bf9651d", $$ACTION_0);
/* __next_internal_action_entry_do_not_use__ {"6d53ce510b2e36499b8f56038817b9bad86cabb4":"$$ACTION_0","9878bfa39811ca7650992850a8751f9591b6a557":"$$ACTION_2"} */ import { createActionProxy } from "private-next-rsc-action-proxy";
import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption";
export default function Page({ foo, x, y }) {
async function action(...args) {
return $$ACTION_0.apply(null, (action.$$bound || []).concat(args));
}
createActionProxy("6d53ce510b2e36499b8f56038817b9bad86cabb4", [
encryptActionBoundArgs("6d53ce510b2e36499b8f56038817b9bad86cabb4", [
x
])
], action, $$ACTION_0);
action.bind(null, foo[0], foo[1], foo.x, foo[y]);
const action2 = ($$ACTION_1 = async (...args)=>$$ACTION_2.apply(null, ($$ACTION_1.$$bound || []).concat(args)), createActionProxy("9878bfa39811ca7650992850a8751f9591b6a557", [
encryptActionBoundArgs("9878bfa39811ca7650992850a8751f9591b6a557", [
x
])
], $$ACTION_1, $$ACTION_2), $$ACTION_1);
function action() {}
createActionProxy("6d53ce510b2e36499b8f56038817b9bad86cabb4", $$ACTION_0).bind(null, encryptActionBoundArgs("6d53ce510b2e36499b8f56038817b9bad86cabb4", [
x
])).bind(null, foo[0], foo[1], foo.x, foo[y]);
const action2 = createActionProxy("9878bfa39811ca7650992850a8751f9591b6a557", $$ACTION_2).bind(null, encryptActionBoundArgs("9878bfa39811ca7650992850a8751f9591b6a557", [
x
]));
action2.bind(null, foo[0], foo[1], foo.x, foo[y]);
}
export async function $$ACTION_0($$ACTION_CLOSURE_BOUND, a, b, c, d) {
var [$$ACTION_ARG_0] = await decryptActionBoundArgs("6d53ce510b2e36499b8f56038817b9bad86cabb4", $$ACTION_CLOSURE_BOUND);
console.log(a, b, $$ACTION_ARG_0, c, d);
}
export var $$ACTION_2 = async ($$ACTION_CLOSURE_BOUND, a, b, c, d)=>{
export async function $$ACTION_2($$ACTION_CLOSURE_BOUND, a, b, c, d) {
var [$$ACTION_ARG_0] = await decryptActionBoundArgs("9878bfa39811ca7650992850a8751f9591b6a557", $$ACTION_CLOSURE_BOUND);
console.log(a, b, $$ACTION_ARG_0, c, d);
};
var $$ACTION_1;
}
/* __next_internal_action_entry_do_not_use__ {"6d53ce510b2e36499b8f56038817b9bad86cabb4":"$$ACTION_0"} */ import { createActionProxy } from "private-next-rsc-action-proxy";
import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption";
export default function Page({ foo, x, y }) {
async function action(...args) {
return $$ACTION_0.apply(null, (action.$$bound || []).concat(args));
}
createActionProxy("6d53ce510b2e36499b8f56038817b9bad86cabb4", [
encryptActionBoundArgs("6d53ce510b2e36499b8f56038817b9bad86cabb4", [
foo
])
], action, $$ACTION_0);
function action() {}
}
export async function $$ACTION_0($$ACTION_CLOSURE_BOUND, a, b, c, { d }) {
var [$$ACTION_ARG_0] = await decryptActionBoundArgs("6d53ce510b2e36499b8f56038817b9bad86cabb4", $$ACTION_CLOSURE_BOUND);
......
import deleteFromDb from 'db'
export function Item({ id1, id2 }) {
id1++
return (() => {
id1++
return <Button action={deleteItem}>Delete</Button>
})()
async function deleteItem() {
'use server'
await deleteFromDb(id1)
await deleteFromDb(id2)
}
}
// In this example, if Button immediately executes the action, different ids should
// be passed.
export function Item2({ id1, id2 }) {
id1++
const temp = []
temp.push(<Button action={deleteItem}>Delete</Button>)
id1++
temp.push(<Button action={deleteItem}>Delete</Button>)
return temp
async function deleteItem() {
'use server'
await deleteFromDb(id1)
await deleteFromDb(id2)
}
}
/* __next_internal_action_entry_do_not_use__ {"188d5d945750dc32e2c842b93c75a65763d4a922":"$$ACTION_1","6d53ce510b2e36499b8f56038817b9bad86cabb4":"$$ACTION_0"} */ import { createActionProxy } from "private-next-rsc-action-proxy";
import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption";
import deleteFromDb from 'db';
export function Item({ id1, id2 }) {
id1++;
return (()=>{
id1++;
return <Button action={createActionProxy("6d53ce510b2e36499b8f56038817b9bad86cabb4", $$ACTION_0).bind(null, encryptActionBoundArgs("6d53ce510b2e36499b8f56038817b9bad86cabb4", [
id1,
id2
]))}>Delete</Button>;
})();
function deleteItem() {}
}
export async function $$ACTION_0($$ACTION_CLOSURE_BOUND) {
var [$$ACTION_ARG_0, $$ACTION_ARG_1] = await decryptActionBoundArgs("6d53ce510b2e36499b8f56038817b9bad86cabb4", $$ACTION_CLOSURE_BOUND);
await deleteFromDb($$ACTION_ARG_0);
await deleteFromDb($$ACTION_ARG_1);
}
// In this example, if Button immediately executes the action, different ids should
// be passed.
export function Item2({ id1, id2 }) {
id1++;
const temp = [];
temp.push(<Button action={createActionProxy("188d5d945750dc32e2c842b93c75a65763d4a922", $$ACTION_1).bind(null, encryptActionBoundArgs("188d5d945750dc32e2c842b93c75a65763d4a922", [
id1,
id2
]))}>Delete</Button>);
id1++;
temp.push(<Button action={createActionProxy("188d5d945750dc32e2c842b93c75a65763d4a922", $$ACTION_1).bind(null, encryptActionBoundArgs("188d5d945750dc32e2c842b93c75a65763d4a922", [
id1,
id2
]))}>Delete</Button>);
return temp;
function deleteItem() {}
}
export async function $$ACTION_1($$ACTION_CLOSURE_BOUND) {
var [$$ACTION_ARG_0, $$ACTION_ARG_1] = await decryptActionBoundArgs("188d5d945750dc32e2c842b93c75a65763d4a922", $$ACTION_CLOSURE_BOUND);
await deleteFromDb($$ACTION_ARG_0);
await deleteFromDb($$ACTION_ARG_1);
}
const noop = (action) => action
export const log = noop(async (data) => {
'use server'
console.log(data)
})
/* __next_internal_action_entry_do_not_use__ {"188d5d945750dc32e2c842b93c75a65763d4a922":"$$ACTION_1"} */ import { createActionProxy } from "private-next-rsc-action-proxy";
import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption";
const noop = (action)=>action;
export const log = noop(createActionProxy("188d5d945750dc32e2c842b93c75a65763d4a922", $$ACTION_1));
export async function $$ACTION_1(data) {
console.log(data);
}
......@@ -8,4 +8,4 @@ import { ensureServerEntryExports } from "private-next-rsc-action-validate";
ensureServerEntryExports([
myAction
]);
createActionProxy("e10665baac148856374b2789aceb970f66fec33e", null, myAction);
createActionProxy("e10665baac148856374b2789aceb970f66fec33e", myAction);
......@@ -13,6 +13,6 @@ ensureServerEntryExports([
b,
c
]);
createActionProxy("6e7bc104e4d6e7fda190c4a51be969cfd0be6d6d", null, a);
createActionProxy("d1f7eb64271d7c601dfef7d4d7053de1c2ca4338", null, b);
createActionProxy("1ab723c80dcca470e0410b4b2a2fc2bf21f41476", null, c);
createActionProxy("6e7bc104e4d6e7fda190c4a51be969cfd0be6d6d", a);
createActionProxy("d1f7eb64271d7c601dfef7d4d7053de1c2ca4338", b);
createActionProxy("1ab723c80dcca470e0410b4b2a2fc2bf21f41476", c);
......@@ -4,18 +4,13 @@ import deleteFromDb from 'db';
const v1 = 'v1';
export function Item({ id1, id2, id3, id4 }) {
const v2 = id2;
async function deleteItem(...args) {
return $$ACTION_0.apply(null, (deleteItem.$$bound || []).concat(args));
}
createActionProxy("6d53ce510b2e36499b8f56038817b9bad86cabb4", [
encryptActionBoundArgs("6d53ce510b2e36499b8f56038817b9bad86cabb4", [
id1,
v2,
id3,
id4.x
])
], deleteItem, $$ACTION_0);
return <Button action={deleteItem}>Delete</Button>;
function deleteItem() {}
return <Button action={createActionProxy("6d53ce510b2e36499b8f56038817b9bad86cabb4", $$ACTION_0).bind(null, encryptActionBoundArgs("6d53ce510b2e36499b8f56038817b9bad86cabb4", [
id1,
v2,
id3,
id4.x
]))}>Delete</Button>;
}
export async function $$ACTION_0($$ACTION_CLOSURE_BOUND) {
var [$$ACTION_ARG_0, $$ACTION_ARG_1, $$ACTION_ARG_2, $$ACTION_ARG_3] = await decryptActionBoundArgs("6d53ce510b2e36499b8f56038817b9bad86cabb4", $$ACTION_CLOSURE_BOUND);
......
......@@ -19,20 +19,15 @@ export function y(p, [p1, { p2 }], ...p3) {
if (true) {
const f8 = 1;
}
async function action(...args) {
return $$ACTION_0.apply(null, (action.$$bound || []).concat(args));
}
createActionProxy("6d53ce510b2e36499b8f56038817b9bad86cabb4", [
encryptActionBoundArgs("6d53ce510b2e36499b8f56038817b9bad86cabb4", [
f2,
f11,
p,
p1,
p2,
p3
])
], action, $$ACTION_0);
return <Button action={action}>Delete</Button>;
function action() {}
return <Button action={createActionProxy("6d53ce510b2e36499b8f56038817b9bad86cabb4", $$ACTION_0).bind(null, encryptActionBoundArgs("6d53ce510b2e36499b8f56038817b9bad86cabb4", [
f2,
f11,
p,
p1,
p2,
p3
]))}>Delete</Button>;
}
export async function $$ACTION_0($$ACTION_CLOSURE_BOUND) {
var [$$ACTION_ARG_0, $$ACTION_ARG_1, $$ACTION_ARG_2, $$ACTION_ARG_3, $$ACTION_ARG_4, $$ACTION_ARG_5] = await decryptActionBoundArgs("6d53ce510b2e36499b8f56038817b9bad86cabb4", $$ACTION_CLOSURE_BOUND);
......
import deleteFromDb from 'db'
export function Item(product, foo, bar) {
async function deleteItem() {
export function Item1(product, foo, bar) {
const a = async function deleteItem1() {
'use server'
await deleteFromDb(
product.id,
......@@ -10,5 +10,44 @@ export function Item(product, foo, bar) {
product[(foo, bar)]
)
}
return <Button action={deleteItem}>Delete</Button>
return <Button action={a}>Delete</Button>
}
export function Item2(product, foo, bar) {
async function deleteItem2() {
'use server'
await deleteFromDb(
product.id,
product?.foo,
product.bar.baz,
product[(foo, bar)]
)
}
return <Button action={deleteItem2}>Delete</Button>
}
export function Item3(product, foo, bar) {
const deleteItem3 = async function () {
'use server'
await deleteFromDb(
product.id,
product?.foo,
product.bar.baz,
product[(foo, bar)]
)
}
return <Button action={deleteItem3}>Delete</Button>
}
export function Item4(product, foo, bar) {
const deleteItem4 = async () => {
'use server'
await deleteFromDb(
product.id,
product?.foo,
product.bar.baz,
product[(foo, bar)]
)
}
return <Button action={deleteItem4}>Delete</Button>
}
/* __next_internal_action_entry_do_not_use__ {"6d53ce510b2e36499b8f56038817b9bad86cabb4":"$$ACTION_0"} */ import { createActionProxy } from "private-next-rsc-action-proxy";
/* __next_internal_action_entry_do_not_use__ {"1383664d1dc2d9cfe33b88df3fa0eaffef8b99bc":"$$ACTION_5","188d5d945750dc32e2c842b93c75a65763d4a922":"$$ACTION_1","56a859f462d35a297c46a1bbd1e6a9058c104ab8":"$$ACTION_3","6d53ce510b2e36499b8f56038817b9bad86cabb4":"$$ACTION_0"} */ import { createActionProxy } from "private-next-rsc-action-proxy";
import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption";
import deleteFromDb from 'db';
export function Item(product, foo, bar) {
async function deleteItem(...args) {
return $$ACTION_0.apply(null, (deleteItem.$$bound || []).concat(args));
}
createActionProxy("6d53ce510b2e36499b8f56038817b9bad86cabb4", [
encryptActionBoundArgs("6d53ce510b2e36499b8f56038817b9bad86cabb4", [
product.id,
product?.foo,
product.bar.baz,
product,
foo,
bar
])
], deleteItem, $$ACTION_0);
return <Button action={deleteItem}>Delete</Button>;
export function Item1(product, foo, bar) {
const a = createActionProxy("6d53ce510b2e36499b8f56038817b9bad86cabb4", $$ACTION_0).bind(null, encryptActionBoundArgs("6d53ce510b2e36499b8f56038817b9bad86cabb4", [
product.id,
product?.foo,
product.bar.baz,
product,
foo,
bar
]));
return <Button action={a}>Delete</Button>;
}
export async function $$ACTION_0($$ACTION_CLOSURE_BOUND) {
var [$$ACTION_ARG_0, $$ACTION_ARG_1, $$ACTION_ARG_2, $$ACTION_ARG_3, $$ACTION_ARG_4, $$ACTION_ARG_5] = await decryptActionBoundArgs("6d53ce510b2e36499b8f56038817b9bad86cabb4", $$ACTION_CLOSURE_BOUND);
await deleteFromDb($$ACTION_ARG_3.id, $$ACTION_ARG_3?.foo, $$ACTION_ARG_3.bar.baz, $$ACTION_ARG_3[$$ACTION_ARG_4, $$ACTION_ARG_5]);
}
export function Item2(product, foo, bar) {
function deleteItem2() {}
return <Button action={createActionProxy("188d5d945750dc32e2c842b93c75a65763d4a922", $$ACTION_1).bind(null, encryptActionBoundArgs("188d5d945750dc32e2c842b93c75a65763d4a922", [
product.id,
product?.foo,
product.bar.baz,
product,
foo,
bar
]))}>Delete</Button>;
}
export async function $$ACTION_1($$ACTION_CLOSURE_BOUND) {
var [$$ACTION_ARG_0, $$ACTION_ARG_1, $$ACTION_ARG_2, $$ACTION_ARG_3, $$ACTION_ARG_4, $$ACTION_ARG_5] = await decryptActionBoundArgs("188d5d945750dc32e2c842b93c75a65763d4a922", $$ACTION_CLOSURE_BOUND);
await deleteFromDb($$ACTION_ARG_3.id, $$ACTION_ARG_3?.foo, $$ACTION_ARG_3.bar.baz, $$ACTION_ARG_3[$$ACTION_ARG_4, $$ACTION_ARG_5]);
}
export function Item3(product, foo, bar) {
const deleteItem3 = createActionProxy("56a859f462d35a297c46a1bbd1e6a9058c104ab8", $$ACTION_3).bind(null, encryptActionBoundArgs("56a859f462d35a297c46a1bbd1e6a9058c104ab8", [
product.id,
product?.foo,
product.bar.baz,
product,
foo,
bar
]));
return <Button action={deleteItem3}>Delete</Button>;
}
export async function $$ACTION_3($$ACTION_CLOSURE_BOUND) {
var [$$ACTION_ARG_0, $$ACTION_ARG_1, $$ACTION_ARG_2, $$ACTION_ARG_3, $$ACTION_ARG_4, $$ACTION_ARG_5] = await decryptActionBoundArgs("56a859f462d35a297c46a1bbd1e6a9058c104ab8", $$ACTION_CLOSURE_BOUND);
await deleteFromDb($$ACTION_ARG_3.id, $$ACTION_ARG_3?.foo, $$ACTION_ARG_3.bar.baz, $$ACTION_ARG_3[$$ACTION_ARG_4, $$ACTION_ARG_5]);
}
export function Item4(product, foo, bar) {
const deleteItem4 = createActionProxy("1383664d1dc2d9cfe33b88df3fa0eaffef8b99bc", $$ACTION_5).bind(null, encryptActionBoundArgs("1383664d1dc2d9cfe33b88df3fa0eaffef8b99bc", [
product.id,
product?.foo,
product.bar.baz,
product,
foo,
bar
]));
return <Button action={deleteItem4}>Delete</Button>;
}
export async function $$ACTION_5($$ACTION_CLOSURE_BOUND) {
var [$$ACTION_ARG_0, $$ACTION_ARG_1, $$ACTION_ARG_2, $$ACTION_ARG_3, $$ACTION_ARG_4, $$ACTION_ARG_5] = await decryptActionBoundArgs("1383664d1dc2d9cfe33b88df3fa0eaffef8b99bc", $$ACTION_CLOSURE_BOUND);
await deleteFromDb($$ACTION_ARG_3.id, $$ACTION_ARG_3?.foo, $$ACTION_ARG_3.bar.baz, $$ACTION_ARG_3[$$ACTION_ARG_4, $$ACTION_ARG_5]);
}
/* __next_internal_action_entry_do_not_use__ {"6d53ce510b2e36499b8f56038817b9bad86cabb4":"$$ACTION_0"} */ import { createActionProxy } from "private-next-rsc-action-proxy";
import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption";
async function myAction(...args) {
return $$ACTION_0.apply(null, (myAction.$$bound || []).concat(args));
}
createActionProxy("6d53ce510b2e36499b8f56038817b9bad86cabb4", null, myAction, $$ACTION_0);
function myAction() {}
export async function $$ACTION_0(a, b, c) {
// comment
'use strict';
console.log('a');
}
export default function Page() {
return <Button action={myAction}>Delete</Button>;
return <Button action={createActionProxy("6d53ce510b2e36499b8f56038817b9bad86cabb4", $$ACTION_0)}>Delete</Button>;
}
// app/send.ts
/* __next_internal_action_entry_do_not_use__ {"c18c215a6b7cdc64bf709f3a714ffdef1bf9651d":"default","ab21efdafbe611287bc25c0462b1e0510d13e48b":"foo","050e3854b72b19e3c7e3966a67535543a90bf7e0":"baz"} */ import { createActionProxy } from "private-next-rsc-action-proxy";
/* __next_internal_action_entry_do_not_use__ {"050e3854b72b19e3c7e3966a67535543a90bf7e0":"baz","ab21efdafbe611287bc25c0462b1e0510d13e48b":"foo","c18c215a6b7cdc64bf709f3a714ffdef1bf9651d":"default"} */ import { createActionProxy } from "private-next-rsc-action-proxy";
import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption";
async function foo() {}
export { foo };
......@@ -13,6 +13,6 @@ ensureServerEntryExports([
bar,
qux
]);
createActionProxy("ab21efdafbe611287bc25c0462b1e0510d13e48b", null, foo);
createActionProxy("050e3854b72b19e3c7e3966a67535543a90bf7e0", null, bar);
createActionProxy("c18c215a6b7cdc64bf709f3a714ffdef1bf9651d", null, qux);
createActionProxy("ab21efdafbe611287bc25c0462b1e0510d13e48b", foo);
createActionProxy("050e3854b72b19e3c7e3966a67535543a90bf7e0", bar);
createActionProxy("c18c215a6b7cdc64bf709f3a714ffdef1bf9651d", qux);
const SERVER_REFERENCE_TAG = Symbol.for('react.server.reference')
/* eslint-disable import/no-extraneous-dependencies */
import { registerServerReference } from 'react-server-dom-webpack/server.edge'
export function createActionProxy(
id: string,
boundArgsFromClosure: null | any[],
action: any,
originalAction?: any
) {
function bindImpl(this: any, _: any, ...boundArgs: any[]) {
const currentAction = this
const newAction = async function (...args: any[]) {
if (originalAction) {
return originalAction(newAction.$$bound.concat(args))
} else {
// In this case we're calling the user-defined action directly.
return currentAction(...newAction.$$bound, ...args)
}
}
for (const key of ['$$typeof', '$$id', '$$FORM_ACTION']) {
// @ts-ignore
newAction[key] = currentAction[key]
}
// Rebind args
newAction.$$bound = (currentAction.$$bound || []).concat(boundArgs)
// Assign bind method
newAction.bind = bindImpl.bind(newAction)
return newAction
}
Object.defineProperties(action, {
$$typeof: {
value: SERVER_REFERENCE_TAG,
},
$$id: {
value: id,
},
$$bound: {
value: boundArgsFromClosure,
},
bind: {
value: bindImpl,
},
})
export function createActionProxy(id: string, action: any) {
return registerServerReference(action, id, null)
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment