Unverified Commit 000d022b authored by Shu Ding's avatar Shu Ding Committed by GitHub

Support `.bind` syntax with Action functions (#49422)

This PR implements initial support for `.bind` syntax for inline actions
(not top-level `"use server"` files yet). For example:

```js
export default function Page({ foo, x, y }) {
  async function action(a, b, c, d) {
    'use server'
    console.log(a, b, c, d)
  }

  return <ClientComp action={action.bind(null, foo[0], foo[1], foo.x, foo[y])} />
}
```

Is now valid.

Fixes NEXT-1109.
parent d9b82a95
/* __next_internal_client_entry_do_not_use__ default auto */ /* __next_internal_action_entry_do_not_use__ $$ACTION_0 */ export default function App() {
async function fn() {
return $$ACTION_0(fn.$$bound);
/* __next_internal_client_entry_do_not_use__ default auto */ /* __next_internal_action_entry_do_not_use__ $$ACTION_0 */ import __create_action_proxy__ from "private-next-rsc-action-proxy";
export default function App() {
async function fn(...args) {
return $$ACTION_0.apply(null, (fn.$$bound || []).concat(args));
}
fn.$$typeof = Symbol.for("react.server.reference");
fn.$$id = "6d53ce510b2e36499b8f56038817b9bad86cabb4";
fn.$$bound = null;
__create_action_proxy__("6d53ce510b2e36499b8f56038817b9bad86cabb4", null, fn, $$ACTION_0);
return <div>App</div>;
}
export async function $$ACTION_0(closure) {}
export async function $$ACTION_0() {}
/* __next_internal_action_entry_do_not_use__ foo */ export function foo() {}
import ensureServerEntryExports from "private-next-rsc-action-proxy";
/* __next_internal_action_entry_do_not_use__ foo */ import __create_action_proxy__ from "private-next-rsc-action-proxy";
export function foo() {}
import ensureServerEntryExports from "private-next-rsc-action-validate";
ensureServerEntryExports([
foo
]);
foo.$$typeof = Symbol.for("react.server.reference");
foo.$$id = "ab21efdafbe611287bc25c0462b1e0510d13e48b";
foo.$$bound = null;
foo.$$with_bound = false;
__create_action_proxy__("ab21efdafbe611287bc25c0462b1e0510d13e48b", null, foo);
/* __next_internal_action_entry_do_not_use__ bar */ 'use strict';
/* __next_internal_action_entry_do_not_use__ bar */ import __create_action_proxy__ from "private-next-rsc-action-proxy";
'use strict';
export function bar() {}
import ensureServerEntryExports from "private-next-rsc-action-proxy";
import ensureServerEntryExports from "private-next-rsc-action-validate";
ensureServerEntryExports([
bar
]);
bar.$$typeof = Symbol.for("react.server.reference");
bar.$$id = "ac840dcaf5e8197cb02b7f3a43c119b7a770b272";
bar.$$bound = null;
bar.$$with_bound = false;
__create_action_proxy__("ac840dcaf5e8197cb02b7f3a43c119b7a770b272", null, bar);
/* __next_internal_action_entry_do_not_use__ x */ export const x = 1;
import ensureServerEntryExports from "private-next-rsc-action-proxy";
/* __next_internal_action_entry_do_not_use__ x */ import __create_action_proxy__ from "private-next-rsc-action-proxy";
export const x = 1;
import ensureServerEntryExports from "private-next-rsc-action-validate";
ensureServerEntryExports([
x
]);
x.$$typeof = Symbol.for("react.server.reference");
x.$$id = "b78c261f135a7a852508c2920bd7228020ff4bd7";
x.$$bound = null;
x.$$with_bound = false;
__create_action_proxy__("b78c261f135a7a852508c2920bd7228020ff4bd7", null, x);
/* __next_internal_action_entry_do_not_use__ */ export default class Component {
/* __next_internal_action_entry_do_not_use__ */ import __create_action_proxy__ from "private-next-rsc-action-proxy";
export default class Component {
render() {
return null;
return null;
}
}
}
import ensureServerEntryExports from "private-next-rsc-action-proxy";
import ensureServerEntryExports from "private-next-rsc-action-validate";
ensureServerEntryExports([]);
/* __next_internal_action_entry_do_not_use__ */ export * from 'foo';
import ensureServerEntryExports from "private-next-rsc-action-proxy";
/* __next_internal_action_entry_do_not_use__ */ import __create_action_proxy__ from "private-next-rsc-action-proxy";
export * from 'foo';
import ensureServerEntryExports from "private-next-rsc-action-validate";
ensureServerEntryExports([]);
/* __next_internal_action_entry_do_not_use__ */ export default (()=>{});
import ensureServerEntryExports from "private-next-rsc-action-proxy";
/* __next_internal_action_entry_do_not_use__ */ import __create_action_proxy__ from "private-next-rsc-action-proxy";
export default (()=>{});
import ensureServerEntryExports from "private-next-rsc-action-validate";
ensureServerEntryExports([]);
/* __next_internal_action_entry_do_not_use__ $$ACTION_1 */ const foo = ($$ACTION_0 = ()=>$$ACTION_1($$ACTION_0.$$bound), $$ACTION_0.$$typeof = Symbol.for("react.server.reference"), $$ACTION_0.$$id = "188d5d945750dc32e2c842b93c75a65763d4a922", $$ACTION_0.$$bound = null, $$ACTION_0);
export const $$ACTION_1 = (closure)=>{};
/* __next_internal_action_entry_do_not_use__ $$ACTION_1 */ import __create_action_proxy__ from "private-next-rsc-action-proxy";
const foo = ($$ACTION_0 = async (...args)=>$$ACTION_1.apply(null, ($$ACTION_0.$$bound || []).concat(args)), __create_action_proxy__("188d5d945750dc32e2c842b93c75a65763d4a922", null, $$ACTION_0, $$ACTION_1), $$ACTION_0);
export const $$ACTION_1 = ()=>{};
var $$ACTION_0;
/* __next_internal_action_entry_do_not_use__ $$ACTION_1 */ const foo = ($$ACTION_0 = async ()=>$$ACTION_1($$ACTION_0.$$bound), $$ACTION_0.$$typeof = Symbol.for("react.server.reference"), $$ACTION_0.$$id = "188d5d945750dc32e2c842b93c75a65763d4a922", $$ACTION_0.$$bound = null, $$ACTION_0);
export const $$ACTION_1 = async (closure)=>{
/* __next_internal_action_entry_do_not_use__ $$ACTION_1 */ import __create_action_proxy__ from "private-next-rsc-action-proxy";
const foo = ($$ACTION_0 = async (...args)=>$$ACTION_1.apply(null, ($$ACTION_0.$$bound || []).concat(args)), __create_action_proxy__("188d5d945750dc32e2c842b93c75a65763d4a922", null, $$ACTION_0, $$ACTION_1), $$ACTION_0);
export const $$ACTION_1 = async ()=>{
'use strict';
};
var $$ACTION_0;
......
// app/send.ts
/* __next_internal_action_entry_do_not_use__ myAction,default */ import createServerReference from "private-next-rsc-action-client-wrapper";
/* __next_internal_action_entry_do_not_use__ myAction,default */ import __create_action_proxy__ from "private-next-rsc-action-proxy";
import createServerReference from "private-next-rsc-action-client-wrapper";
export const myAction = createServerReference("e10665baac148856374b2789aceb970f66fec33e");
export default createServerReference("c18c215a6b7cdc64bf709f3a714ffdef1bf9651d");
// app/send.ts
/* __next_internal_action_entry_do_not_use__ foo */ import createServerReference from "private-next-rsc-action-client-wrapper";
/* __next_internal_action_entry_do_not_use__ foo */ import __create_action_proxy__ from "private-next-rsc-action-proxy";
import createServerReference from "private-next-rsc-action-client-wrapper";
export const foo = createServerReference("ab21efdafbe611287bc25c0462b1e0510d13e48b");
/* __next_internal_action_entry_do_not_use__ $$ACTION_0 */ import deleteFromDb from 'db';
/* __next_internal_action_entry_do_not_use__ $$ACTION_0 */ import __create_action_proxy__ from "private-next-rsc-action-proxy";
import deleteFromDb from 'db';
export function Item({ id1 , id2 }) {
async function deleteItem() {
return $$ACTION_0(deleteItem.$$bound);
async function deleteItem(...args) {
return $$ACTION_0.apply(null, (deleteItem.$$bound || []).concat(args));
}
deleteItem.$$typeof = Symbol.for("react.server.reference");
deleteItem.$$id = "6d53ce510b2e36499b8f56038817b9bad86cabb4";
deleteItem.$$bound = [
__create_action_proxy__("6d53ce510b2e36499b8f56038817b9bad86cabb4", [
id1,
id2
];
], deleteItem, $$ACTION_0);
return <Button action={deleteItem}>Delete</Button>;
}
export async function $$ACTION_0(closure) {
await deleteFromDb(closure[0]);
await deleteFromDb(closure[1]);
}
\ No newline at end of file
export async function $$ACTION_0(id1, id2) {
await deleteFromDb(id1);
await deleteFromDb(id2);
}
/* __next_internal_action_entry_do_not_use__ default */ export default async function foo() {}
import ensureServerEntryExports from "private-next-rsc-action-proxy";
/* __next_internal_action_entry_do_not_use__ default */ import __create_action_proxy__ from "private-next-rsc-action-proxy";
export default async function foo() {}
import ensureServerEntryExports from "private-next-rsc-action-validate";
ensureServerEntryExports([
foo
]);
foo.$$typeof = Symbol.for("react.server.reference");
foo.$$id = "c18c215a6b7cdc64bf709f3a714ffdef1bf9651d";
foo.$$bound = null;
foo.$$with_bound = false;
__create_action_proxy__("c18c215a6b7cdc64bf709f3a714ffdef1bf9651d", null, foo);
/* __next_internal_action_entry_do_not_use__ default */ export default async function $$ACTION_0() {}
import ensureServerEntryExports from "private-next-rsc-action-proxy";
/* __next_internal_action_entry_do_not_use__ default */ import __create_action_proxy__ from "private-next-rsc-action-proxy";
export default async function $$ACTION_0() {}
import ensureServerEntryExports from "private-next-rsc-action-validate";
ensureServerEntryExports([
$$ACTION_0
]);
$$ACTION_0.$$typeof = Symbol.for("react.server.reference");
$$ACTION_0.$$id = "c18c215a6b7cdc64bf709f3a714ffdef1bf9651d";
$$ACTION_0.$$bound = null;
$$ACTION_0.$$with_bound = false;
__create_action_proxy__("c18c215a6b7cdc64bf709f3a714ffdef1bf9651d", null, $$ACTION_0);
/* __next_internal_action_entry_do_not_use__ default */ async function foo() {}
/* __next_internal_action_entry_do_not_use__ default */ import __create_action_proxy__ from "private-next-rsc-action-proxy";
async function foo() {}
export default foo;
import ensureServerEntryExports from "private-next-rsc-action-proxy";
import ensureServerEntryExports from "private-next-rsc-action-validate";
ensureServerEntryExports([
foo
]);
foo.$$typeof = Symbol.for("react.server.reference");
foo.$$id = "c18c215a6b7cdc64bf709f3a714ffdef1bf9651d";
foo.$$bound = null;
foo.$$with_bound = false;
__create_action_proxy__("c18c215a6b7cdc64bf709f3a714ffdef1bf9651d", null, foo);
/* __next_internal_action_entry_do_not_use__ default,bar */ const foo = async function() {};
/* __next_internal_action_entry_do_not_use__ default,bar */ import __create_action_proxy__ from "private-next-rsc-action-proxy";
const foo = async function() {};
export default foo;
const bar = async function() {};
export { bar };
import ensureServerEntryExports from "private-next-rsc-action-proxy";
import ensureServerEntryExports from "private-next-rsc-action-validate";
ensureServerEntryExports([
foo,
bar
]);
foo.$$typeof = Symbol.for("react.server.reference");
foo.$$id = "c18c215a6b7cdc64bf709f3a714ffdef1bf9651d";
foo.$$bound = null;
foo.$$with_bound = false;
bar.$$typeof = Symbol.for("react.server.reference");
bar.$$id = "ac840dcaf5e8197cb02b7f3a43c119b7a770b272";
bar.$$bound = null;
bar.$$with_bound = false;
__create_action_proxy__("c18c215a6b7cdc64bf709f3a714ffdef1bf9651d", null, foo);
__create_action_proxy__("ac840dcaf5e8197cb02b7f3a43c119b7a770b272", null, bar);
/* __next_internal_action_entry_do_not_use__ foo */ export async function foo() {
/* __next_internal_action_entry_do_not_use__ foo */ import __create_action_proxy__ from "private-next-rsc-action-proxy";
export async function foo() {
async function bar() {}
}
import ensureServerEntryExports from "private-next-rsc-action-proxy";
import ensureServerEntryExports from "private-next-rsc-action-validate";
ensureServerEntryExports([
foo
foo
]);
foo.$$typeof = Symbol.for("react.server.reference");
foo.$$id = "ab21efdafbe611287bc25c0462b1e0510d13e48b";
foo.$$bound = null;
foo.$$with_bound = false;
__create_action_proxy__("ab21efdafbe611287bc25c0462b1e0510d13e48b", null, foo);
/* __next_internal_action_entry_do_not_use__ default */ export default $$ACTION_0 = async (a, b)=>{
/* __next_internal_action_entry_do_not_use__ default */ import __create_action_proxy__ from "private-next-rsc-action-proxy";
export default $$ACTION_0 = async (a, b)=>{
console.log(a, b);
};
var $$ACTION_0;
import ensureServerEntryExports from "private-next-rsc-action-proxy";
import ensureServerEntryExports from "private-next-rsc-action-validate";
ensureServerEntryExports([
$$ACTION_0
$$ACTION_0
]);
$$ACTION_0.$$typeof = Symbol.for("react.server.reference");
$$ACTION_0.$$id = "c18c215a6b7cdc64bf709f3a714ffdef1bf9651d";
$$ACTION_0.$$bound = null;
$$ACTION_0.$$with_bound = false;
__create_action_proxy__("c18c215a6b7cdc64bf709f3a714ffdef1bf9651d", null, $$ACTION_0);
/* __next_internal_action_entry_do_not_use__ $$ACTION_1,$$ACTION_2,$$ACTION_4 */ import deleteFromDb from 'db';
/* __next_internal_action_entry_do_not_use__ $$ACTION_1,$$ACTION_2,$$ACTION_4 */ import __create_action_proxy__ from "private-next-rsc-action-proxy";
import deleteFromDb from 'db';
const v1 = 'v1';
export function Item({ id1 , id2 }) {
const v2 = id2;
const deleteItem = ($$ACTION_0 = async ()=>$$ACTION_1($$ACTION_0.$$bound), $$ACTION_0.$$typeof = Symbol.for("react.server.reference"), $$ACTION_0.$$id = "188d5d945750dc32e2c842b93c75a65763d4a922", $$ACTION_0.$$bound = [
const deleteItem = ($$ACTION_0 = async (...args)=>$$ACTION_1.apply(null, ($$ACTION_0.$$bound || []).concat(args)), __create_action_proxy__("188d5d945750dc32e2c842b93c75a65763d4a922", [
id1,
v2
], $$ACTION_0);
], $$ACTION_0, $$ACTION_1), $$ACTION_0);
return <Button action={deleteItem}>Delete</Button>;
}
export const $$ACTION_1 = async (closure)=>{
await deleteFromDb(closure[0]);
export const $$ACTION_1 = async (id1, v2)=>{
await deleteFromDb(id1);
await deleteFromDb(v1);
await deleteFromDb(closure[1]);
await deleteFromDb(v2);
};
var $$ACTION_0;
const f = (x)=>{
async function g(y, ...z) {
return $$ACTION_2(g.$$bound);
async function g(...args) {
return $$ACTION_2.apply(null, (g.$$bound || []).concat(args));
}
g.$$typeof = Symbol.for("react.server.reference");
g.$$id = "9878bfa39811ca7650992850a8751f9591b6a557";
g.$$bound = [
__create_action_proxy__("9878bfa39811ca7650992850a8751f9591b6a557", [
x
];
], g, $$ACTION_2);
};
export async function $$ACTION_2(closure, y = closure[1], z = closure.slice(2)) {
return closure[0] + y + z[0];
export async function $$ACTION_2(x, y, ...z) {
return x + y + z[0];
}
const g = (x)=>{
f = ($$ACTION_3 = async (y, ...z)=>$$ACTION_4($$ACTION_3.$$bound), $$ACTION_3.$$typeof = Symbol.for("react.server.reference"), $$ACTION_3.$$id = "9c0dd1f7c2b3f41d32e10f5c437de3d67ad32c6c", $$ACTION_3.$$bound = [
f = ($$ACTION_3 = async (...args)=>$$ACTION_4.apply(null, ($$ACTION_3.$$bound || []).concat(args)), __create_action_proxy__("9c0dd1f7c2b3f41d32e10f5c437de3d67ad32c6c", [
x
], $$ACTION_3);
], $$ACTION_3, $$ACTION_4), $$ACTION_3);
};
export const $$ACTION_4 = async (closure, y = closure[1], z = closure.slice(2))=>{
return closure[0] + y + z[0];
export const $$ACTION_4 = async (x, y, ...z)=>{
return x + y + z[0];
};
var $$ACTION_3;
var $$ACTION_3;
\ No newline at end of file
/* __next_internal_action_entry_do_not_use__ foo,bar */ export const foo = async ()=>{};
/* __next_internal_action_entry_do_not_use__ foo,bar */ import __create_action_proxy__ from "private-next-rsc-action-proxy";
export const foo = async ()=>{};
const bar = async ()=>{};
export { bar };
import ensureServerEntryExports from "private-next-rsc-action-proxy";
import ensureServerEntryExports from "private-next-rsc-action-validate";
ensureServerEntryExports([
foo,
bar
]);
foo.$$typeof = Symbol.for("react.server.reference");
foo.$$id = "ab21efdafbe611287bc25c0462b1e0510d13e48b";
foo.$$bound = null;
foo.$$with_bound = false;
bar.$$typeof = Symbol.for("react.server.reference");
bar.$$id = "ac840dcaf5e8197cb02b7f3a43c119b7a770b272";
bar.$$bound = null;
bar.$$with_bound = false;
__create_action_proxy__("ab21efdafbe611287bc25c0462b1e0510d13e48b", null, foo);
__create_action_proxy__("ac840dcaf5e8197cb02b7f3a43c119b7a770b272", null, bar);
/* __next_internal_action_entry_do_not_use__ $$ACTION_1,$$ACTION_3 */ import deleteFromDb from 'db';
/* __next_internal_action_entry_do_not_use__ $$ACTION_1,$$ACTION_3 */ import __create_action_proxy__ from "private-next-rsc-action-proxy";
import deleteFromDb from 'db';
const v1 = 'v1';
export function Item({ id1 , id2 }) {
const v2 = id2;
return <>
<Button action={$$ACTION_0 = async ()=>$$ACTION_1($$ACTION_0.$$bound), $$ACTION_0.$$typeof = Symbol.for("react.server.reference"), $$ACTION_0.$$id = "188d5d945750dc32e2c842b93c75a65763d4a922", $$ACTION_0.$$bound = [
<Button action={$$ACTION_0 = async (...args)=>$$ACTION_1.apply(null, ($$ACTION_0.$$bound || []).concat(args)), __create_action_proxy__("188d5d945750dc32e2c842b93c75a65763d4a922", [
id1,
v2
], $$ACTION_0}>
], $$ACTION_0, $$ACTION_1), $$ACTION_0}>
Delete
</Button>
<Button action={$$ACTION_2 = async function() {
return $$ACTION_3($$ACTION_2.$$bound);
}, $$ACTION_2.$$typeof = Symbol.for("react.server.reference"), $$ACTION_2.$$id = "56a859f462d35a297c46a1bbd1e6a9058c104ab8", $$ACTION_2.$$bound = [
<Button action={$$ACTION_2 = async function(...args) {
return $$ACTION_3.apply(null, ($$ACTION_2.$$bound || []).concat(args));
}, __create_action_proxy__("56a859f462d35a297c46a1bbd1e6a9058c104ab8", [
id1,
v2
], $$ACTION_2}>
], $$ACTION_2, $$ACTION_3), $$ACTION_2}>
Delete
......@@ -26,15 +27,15 @@ export function Item({ id1 , id2 }) {
</>;
}
export const $$ACTION_1 = async (closure)=>{
await deleteFromDb(closure[0]);
export const $$ACTION_1 = async (id1, v2)=>{
await deleteFromDb(id1);
await deleteFromDb(v1);
await deleteFromDb(closure[1]);
await deleteFromDb(v2);
};
var $$ACTION_0;
export async function $$ACTION_3(closure) {
await deleteFromDb(closure[0]);
export async function $$ACTION_3(id1, v2) {
await deleteFromDb(id1);
await deleteFromDb(v1);
await deleteFromDb(closure[1]);
await deleteFromDb(v2);
}
var $$ACTION_2;
/* __next_internal_action_entry_do_not_use__ $$ACTION_1 */ export function Item({ value }) {
/* __next_internal_action_entry_do_not_use__ $$ACTION_1 */ import __create_action_proxy__ from "private-next-rsc-action-proxy";
export function Item({ value }) {
return <>
<Button action={$$ACTION_0 = async (value2)=>$$ACTION_1($$ACTION_0.$$bound), $$ACTION_0.$$typeof = Symbol.for("react.server.reference"), $$ACTION_0.$$id = "188d5d945750dc32e2c842b93c75a65763d4a922", $$ACTION_0.$$bound = [
<Button action={$$ACTION_0 = async (...args)=>$$ACTION_1.apply(null, ($$ACTION_0.$$bound || []).concat(args)), __create_action_proxy__("188d5d945750dc32e2c842b93c75a65763d4a922", [
value
], $$ACTION_0}>
], $$ACTION_0, $$ACTION_1), $$ACTION_0}>
Multiple
......@@ -11,7 +12,7 @@
</>;
}
export const $$ACTION_1 = async (closure, value2 = closure[1])=>{
return closure[0] * value2;
export const $$ACTION_1 = async (value, value2)=>{
return value * value2;
};
var $$ACTION_0;
/* __next_internal_action_entry_do_not_use__ $$ACTION_0 */ async function myAction(a, b, c) {
/* __next_internal_action_entry_do_not_use__ $$ACTION_0 */ import __create_action_proxy__ from "private-next-rsc-action-proxy";
async function myAction(...args) {
return $$ACTION_0.apply(null, (myAction.$$bound || []).concat(args));
}
__create_action_proxy__("6d53ce510b2e36499b8f56038817b9bad86cabb4", null, myAction, $$ACTION_0);
export async function $$ACTION_0(a, b, c) {
console.log('a');
}
myAction.$$typeof = Symbol.for("react.server.reference");
myAction.$$id = "6d53ce510b2e36499b8f56038817b9bad86cabb4";
myAction.$$bound = null;
myAction.$$with_bound = false;
export const $$ACTION_0 = myAction;
export default function Page() {
return <Button action={myAction}>Delete</Button>;
}
/* __next_internal_action_entry_do_not_use__ default */ const [foo] = [
null
/* __next_internal_action_entry_do_not_use__ default */ import __create_action_proxy__ from "private-next-rsc-action-proxy";
const [foo] = [
null
];
export default foo;
import ensureServerEntryExports from "private-next-rsc-action-proxy";
import ensureServerEntryExports from "private-next-rsc-action-validate";
ensureServerEntryExports([
foo
]);
foo.$$typeof = Symbol.for("react.server.reference");
foo.$$id = "c18c215a6b7cdc64bf709f3a714ffdef1bf9651d";
foo.$$bound = null;
foo.$$with_bound = false;
__create_action_proxy__("c18c215a6b7cdc64bf709f3a714ffdef1bf9651d", null, foo);
/* __next_internal_action_entry_do_not_use__ $$ACTION_1,$$ACTION_3,$$ACTION_5 */ import { validator, another } from 'auth';
/* __next_internal_action_entry_do_not_use__ $$ACTION_1,$$ACTION_3,$$ACTION_5 */ import __create_action_proxy__ from "private-next-rsc-action-proxy";
import { validator, another } from 'auth';
const x = 1;
export default function Page() {
const y = 1;
return <Foo action={validator(($$ACTION_0 = async function(z) {
return $$ACTION_1($$ACTION_0.$$bound);
}, $$ACTION_0.$$typeof = Symbol.for("react.server.reference"), $$ACTION_0.$$id = "188d5d945750dc32e2c842b93c75a65763d4a922", $$ACTION_0.$$bound = [
return <Foo action={validator(($$ACTION_0 = async function(...args) {
return $$ACTION_1.apply(null, ($$ACTION_0.$$bound || []).concat(args));
}, __create_action_proxy__("188d5d945750dc32e2c842b93c75a65763d4a922", [
y
], $$ACTION_0))}/>;
], $$ACTION_0, $$ACTION_1), $$ACTION_0))}/>;
}
export async function $$ACTION_1(closure, z = closure[1]) {
return x + closure[0] + z;
export async function $$ACTION_1(y, z) {
return x + y + z;
}
var $$ACTION_0;
validator(($$ACTION_2 = async ()=>$$ACTION_3($$ACTION_2.$$bound), $$ACTION_2.$$typeof = Symbol.for("react.server.reference"), $$ACTION_2.$$id = "56a859f462d35a297c46a1bbd1e6a9058c104ab8", $$ACTION_2.$$bound = null, $$ACTION_2));
export const $$ACTION_3 = async (closure)=>{};
validator(($$ACTION_2 = async (...args)=>$$ACTION_3.apply(null, ($$ACTION_2.$$bound || []).concat(args)), __create_action_proxy__("56a859f462d35a297c46a1bbd1e6a9058c104ab8", null, $$ACTION_2, $$ACTION_3), $$ACTION_2));
export const $$ACTION_3 = async ()=>{};
var $$ACTION_2;
another(validator(($$ACTION_4 = async ()=>$$ACTION_5($$ACTION_4.$$bound), $$ACTION_4.$$typeof = Symbol.for("react.server.reference"), $$ACTION_4.$$id = "1383664d1dc2d9cfe33b88df3fa0eaffef8b99bc", $$ACTION_4.$$bound = null, $$ACTION_4)));
export const $$ACTION_5 = async (closure)=>{};
another(validator(($$ACTION_4 = async (...args)=>$$ACTION_5.apply(null, ($$ACTION_4.$$bound || []).concat(args)), __create_action_proxy__("1383664d1dc2d9cfe33b88df3fa0eaffef8b99bc", null, $$ACTION_4, $$ACTION_5), $$ACTION_4)));
export const $$ACTION_5 = async ()=>{};
var $$ACTION_4;
/* __next_internal_action_entry_do_not_use__ action,default */ import { validator } from 'auth';
/* __next_internal_action_entry_do_not_use__ action,default */ import __create_action_proxy__ from "private-next-rsc-action-proxy";
import { validator } from 'auth';
export const action = validator(async ()=>{});
export default $$ACTION_0 = validator(async ()=>{});
var $$ACTION_0;
import ensureServerEntryExports from "private-next-rsc-action-proxy";
import ensureServerEntryExports from "private-next-rsc-action-validate";
ensureServerEntryExports([
action,
$$ACTION_0
]);
action.$$typeof = Symbol.for("react.server.reference");
action.$$id = "f14702b5a021dd117f7ec7a3c838f397c2046d3b";
action.$$bound = null;
action.$$with_bound = false;
$$ACTION_0.$$typeof = Symbol.for("react.server.reference");
$$ACTION_0.$$id = "c18c215a6b7cdc64bf709f3a714ffdef1bf9651d";
$$ACTION_0.$$bound = null;
$$ACTION_0.$$with_bound = false;
__create_action_proxy__("f14702b5a021dd117f7ec7a3c838f397c2046d3b", null, action);
__create_action_proxy__("c18c215a6b7cdc64bf709f3a714ffdef1bf9651d", null, $$ACTION_0);
export default function Page({ foo, x, y }) {
async function action(a, b, c, d) {
'use server'
console.log(a, b, x, c, d)
}
action.bind(null, foo[0], foo[1], foo.x, foo[y])
const action2 = async (a, b, c, d) => {
'use server'
console.log(a, b, x, c, d)
}
action2.bind(null, foo[0], foo[1], foo.x, foo[y])
}
/* __next_internal_action_entry_do_not_use__ $$ACTION_0,$$ACTION_2 */ import __create_action_proxy__ from "private-next-rsc-action-proxy";
export default function Page({ foo , x , y }) {
async function action(...args) {
return $$ACTION_0.apply(null, (action.$$bound || []).concat(args));
}
__create_action_proxy__("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)), __create_action_proxy__("9878bfa39811ca7650992850a8751f9591b6a557", [
x
], $$ACTION_1, $$ACTION_2), $$ACTION_1);
action2.bind(null, foo[0], foo[1], foo.x, foo[y]);
}
export async function $$ACTION_0(x, a, b, c, d) {
console.log(a, b, x, c, d);
}
export const $$ACTION_2 = async (x, a, b, c, d)=>{
console.log(a, b, x, c, d);
};
var $$ACTION_1;
// app/send.ts
/* __next_internal_action_entry_do_not_use__ myAction */ export async function myAction(a, b, c) {
/* __next_internal_action_entry_do_not_use__ myAction */ import __create_action_proxy__ from "private-next-rsc-action-proxy";
export async function myAction(a, b, c) {
console.log('a');
}
import ensureServerEntryExports from "private-next-rsc-action-proxy";
import ensureServerEntryExports from "private-next-rsc-action-validate";
ensureServerEntryExports([
myAction
]);
myAction.$$typeof = Symbol.for("react.server.reference");
myAction.$$id = "e10665baac148856374b2789aceb970f66fec33e";
myAction.$$bound = null;
myAction.$$with_bound = false;
__create_action_proxy__("e10665baac148856374b2789aceb970f66fec33e", null, myAction);
/* __next_internal_action_entry_do_not_use__ a,b,c */ export async function a() {}
/* __next_internal_action_entry_do_not_use__ a,b,c */ import __create_action_proxy__ from "private-next-rsc-action-proxy";
export async function a() {}
export async function b() {}
export async function c() {}
function d() {}
function Foo() {
async function e() {}
}
import ensureServerEntryExports from "private-next-rsc-action-proxy";
import ensureServerEntryExports from "private-next-rsc-action-validate";
ensureServerEntryExports([
a,
b,
c
]);
a.$$typeof = Symbol.for("react.server.reference");
a.$$id = "6e7bc104e4d6e7fda190c4a51be969cfd0be6d6d";
a.$$bound = null;
a.$$with_bound = false;
b.$$typeof = Symbol.for("react.server.reference");
b.$$id = "d1f7eb64271d7c601dfef7d4d7053de1c2ca4338";
b.$$bound = null;
b.$$with_bound = false;
c.$$typeof = Symbol.for("react.server.reference");
c.$$id = "1ab723c80dcca470e0410b4b2a2fc2bf21f41476";
c.$$bound = null;
c.$$with_bound = false;
__create_action_proxy__("6e7bc104e4d6e7fda190c4a51be969cfd0be6d6d", null, a);
__create_action_proxy__("d1f7eb64271d7c601dfef7d4d7053de1c2ca4338", null, b);
__create_action_proxy__("1ab723c80dcca470e0410b4b2a2fc2bf21f41476", null, c);
/* __next_internal_action_entry_do_not_use__ $$ACTION_0 */ import deleteFromDb from 'db';
/* __next_internal_action_entry_do_not_use__ $$ACTION_0 */ import __create_action_proxy__ from "private-next-rsc-action-proxy";
import deleteFromDb from 'db';
const v1 = 'v1';
export function Item({ id1 , id2 }) {
const v2 = id2;
async function deleteItem() {
return $$ACTION_0(deleteItem.$$bound);
async function deleteItem(...args) {
return $$ACTION_0.apply(null, (deleteItem.$$bound || []).concat(args));
}
deleteItem.$$typeof = Symbol.for("react.server.reference");
deleteItem.$$id = "6d53ce510b2e36499b8f56038817b9bad86cabb4";
deleteItem.$$bound = [
__create_action_proxy__("6d53ce510b2e36499b8f56038817b9bad86cabb4", [
id1,
v2
];
], deleteItem, $$ACTION_0);
return <Button action={deleteItem}>Delete</Button>;
}
export async function $$ACTION_0(closure) {
await deleteFromDb(closure[0]);
export async function $$ACTION_0(id1, v2) {
await deleteFromDb(id1);
await deleteFromDb(v1);
await deleteFromDb(closure[1]);
}
\ No newline at end of file
await deleteFromDb(v2);
}
/* __next_internal_action_entry_do_not_use__ $$ACTION_0 */ import f, { f1, f2 } from 'foo';
/* __next_internal_action_entry_do_not_use__ $$ACTION_0 */ import __create_action_proxy__ from "private-next-rsc-action-proxy";
import f, { f1, f2 } from 'foo';
const f3 = 1;
var f4;
let f5;
......@@ -17,26 +18,24 @@ export function y(p, [p1, { p2 }], ...p3) {
if (true) {
const f8 = 1;
}
async function action() {
return $$ACTION_0(action.$$bound);
async function action(...args) {
return $$ACTION_0.apply(null, (action.$$bound || []).concat(args));
}
action.$$typeof = Symbol.for("react.server.reference");
action.$$id = "6d53ce510b2e36499b8f56038817b9bad86cabb4";
action.$$bound = [
__create_action_proxy__("6d53ce510b2e36499b8f56038817b9bad86cabb4", [
f2,
f11,
p,
p1,
p2,
p3
];
], action, $$ACTION_0);
return <Button action={action}>Delete</Button>;
}
export async function $$ACTION_0(closure) {
export async function $$ACTION_0(f2, f11, p, p1, p2, p3) {
const f17 = 1;
if (true) {
const f18 = 1;
const f19 = 1;
}
console.log(f, f1, closure[0], f3, f4, f5, f6, f7, f8, closure[0](f9), f12, closure[1], f16.x, f17, f18, closure[2], closure[3], closure[4], closure[5], g19, g20, globalThis);
console.log(f, f1, f2, f3, f4, f5, f6, f7, f8, f2(f9), f12, f11, f16.x, f17, f18, p, p1, p2, p3, g19, g20, globalThis);
}
/* __next_internal_action_entry_do_not_use__ $$ACTION_0 */ import deleteFromDb from 'db';
/* __next_internal_action_entry_do_not_use__ $$ACTION_0 */ import __create_action_proxy__ from "private-next-rsc-action-proxy";
import deleteFromDb from 'db';
export function Item(product, foo, bar) {
async function deleteItem() {
return $$ACTION_0(deleteItem.$$bound);
async function deleteItem(...args) {
return $$ACTION_0.apply(null, (deleteItem.$$bound || []).concat(args));
}
deleteItem.$$typeof = Symbol.for("react.server.reference");
deleteItem.$$id = "6d53ce510b2e36499b8f56038817b9bad86cabb4";
deleteItem.$$bound = [
__create_action_proxy__("6d53ce510b2e36499b8f56038817b9bad86cabb4", [
product.id,
product?.foo,
product.bar.baz,
product,
foo,
bar
];
], deleteItem, $$ACTION_0);
return <Button action={deleteItem}>Delete</Button>;
}
export async function $$ACTION_0(closure) {
await deleteFromDb(closure[3].id, closure[3]?.foo, closure[3].bar.baz, closure[3][closure[4], closure[5]]);
}
\ No newline at end of file
export async function $$ACTION_0(product, product, product, product, foo, bar) {
await deleteFromDb(product.id, product?.foo, product.bar.baz, product[foo, bar]);
}
/* __next_internal_action_entry_do_not_use__ $$ACTION_0 */ async function myAction(a, b, c) {
/* __next_internal_action_entry_do_not_use__ $$ACTION_0 */ import __create_action_proxy__ from "private-next-rsc-action-proxy";
async function myAction(...args) {
return $$ACTION_0.apply(null, (myAction.$$bound || []).concat(args));
}
__create_action_proxy__("6d53ce510b2e36499b8f56038817b9bad86cabb4", null, myAction, $$ACTION_0);
export async function $$ACTION_0(a, b, c) {
// comment
'use strict';
console.log('a');
}
myAction.$$typeof = Symbol.for("react.server.reference");
myAction.$$id = "6d53ce510b2e36499b8f56038817b9bad86cabb4";
myAction.$$bound = null;
myAction.$$with_bound = false;
export const $$ACTION_0 = myAction;
export default function Page() {
return <Button action={myAction}>Delete</Button>;
}
// app/send.ts
/* __next_internal_action_entry_do_not_use__ foo,baz,default */ async function foo() {}
/* __next_internal_action_entry_do_not_use__ foo,baz,default */ import __create_action_proxy__ from "private-next-rsc-action-proxy";
async function foo() {}
export { foo };
async function bar() {}
export { bar as baz };
async function qux() {}
export { qux as default };
import ensureServerEntryExports from "private-next-rsc-action-proxy";
import ensureServerEntryExports from "private-next-rsc-action-validate";
ensureServerEntryExports([
foo,
bar,
qux
]);
foo.$$typeof = Symbol.for("react.server.reference");
foo.$$id = "ab21efdafbe611287bc25c0462b1e0510d13e48b";
foo.$$bound = null;
foo.$$with_bound = false;
bar.$$typeof = Symbol.for("react.server.reference");
bar.$$id = "050e3854b72b19e3c7e3966a67535543a90bf7e0";
bar.$$bound = null;
bar.$$with_bound = false;
qux.$$typeof = Symbol.for("react.server.reference");
qux.$$id = "c18c215a6b7cdc64bf709f3a714ffdef1bf9651d";
qux.$$bound = null;
qux.$$with_bound = false;
__create_action_proxy__("ab21efdafbe611287bc25c0462b1e0510d13e48b", null, foo);
__create_action_proxy__("050e3854b72b19e3c7e3966a67535543a90bf7e0", null, bar);
__create_action_proxy__("c18c215a6b7cdc64bf709f3a714ffdef1bf9651d", null, qux);
......@@ -13,6 +13,7 @@ import {
WEBPACK_LAYERS,
RSC_ACTION_PROXY_ALIAS,
RSC_ACTION_CLIENT_WRAPPER_ALIAS,
RSC_ACTION_VALIDATE_ALIAS,
} from '../lib/constants'
import { fileExists } from '../lib/file-exists'
import { CustomRoutes } from '../lib/load-custom-routes.js'
......@@ -1058,12 +1059,15 @@ export default async function getBaseWebpackConfig(
...(isClient || isEdgeServer ? getOptimizedAliases() : {}),
...getReactProfilingInProduction(),
[RSC_ACTION_PROXY_ALIAS]:
'next/dist/build/webpack/loaders/next-flight-loader/action-proxy',
[RSC_ACTION_VALIDATE_ALIAS]:
'next/dist/build/webpack/loaders/next-flight-loader/action-validate',
[RSC_ACTION_CLIENT_WRAPPER_ALIAS]:
'next/dist/build/webpack/loaders/next-flight-loader/action-client-wrapper',
[RSC_ACTION_PROXY_ALIAS]:
'next/dist/build/webpack/loaders/next-flight-loader/action-proxy',
...(isClient || isEdgeServer
? {
[clientResolveRewrites]: hasRewrites
......@@ -1279,7 +1283,7 @@ export default async function getBaseWebpackConfig(
}
const notExternalModules =
/^(?:private-next-pages\/|next\/(?:dist\/pages\/|(?:app|document|link|image|legacy\/image|constants|dynamic|script|navigation|headers)$)|string-hash|private-next-rsc-action-proxy|private-next-rsc-action-client-wrapper$)/
/^(?:private-next-pages\/|next\/(?:dist\/pages\/|(?:app|document|link|image|legacy\/image|constants|dynamic|script|navigation|headers)$)|string-hash|private-next-rsc-action-validate|private-next-rsc-action-client-wrapper|private-next-rsc-action-proxy$)/
if (notExternalModules.test(request)) {
return
}
......
......@@ -30,12 +30,7 @@ ${individualActions
async function endpoint(id, ...args) {
const action = await actions[id]()
if (action.$$with_bound === false) {
return action.apply(null, args)
}
return action.call(null, args)
return action.apply(null, args)
}
// Using CJS to avoid this to be tree-shaken away due to unused exports.
......
export default function ensureServerEntryExports(actions: any[]) {
for (let i = 0; i < actions.length; i++) {
const action = actions[i]
if (typeof action !== 'function') {
throw new Error(
`A "use server" file can only export async functions, found ${typeof action}.`
)
export default function createActionProxy(
id: string,
bound: null | any[],
action: any,
originalAction?: any
) {
action.$$typeof = Symbol.for('react.server.reference')
action.$$id = id
action.$$bound = bound
action.bind = function (_: any, ...boundArgs: any[]) {
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 action(...newAction.$$bound, ...args)
}
}
for (const key of ['$$typeof', '$$id', '$$FORM_ACTION']) {
// @ts-ignore
newAction[key] = action[key]
}
// Rebind args
newAction.$$bound = (action.$$bound || []).concat(boundArgs)
return newAction
}
}
export default function ensureServerEntryExports(actions: any[]) {
for (let i = 0; i < actions.length; i++) {
const action = actions[i]
if (typeof action !== 'function') {
throw new Error(
`A "use server" file can only export async functions, found ${typeof action}.`
)
}
}
}
......@@ -24,6 +24,7 @@ export const DOT_NEXT_ALIAS = 'private-dot-next'
export const ROOT_DIR_ALIAS = 'private-next-root-dir'
export const APP_DIR_ALIAS = 'private-next-app-dir'
export const RSC_MOD_REF_PROXY_ALIAS = 'private-next-rsc-mod-ref-proxy'
export const RSC_ACTION_VALIDATE_ALIAS = 'private-next-rsc-action-validate'
export const RSC_ACTION_PROXY_ALIAS = 'private-next-rsc-action-proxy'
export const RSC_ACTION_CLIENT_WRAPPER_ALIAS =
'private-next-rsc-action-client-wrapper'
......
......@@ -106,6 +106,17 @@ createNextDescribe(
}, '/header?name=test&constructor=FormData')
})
it('should support .bind', async () => {
const browser = await next.browser('/server')
await browser.eval(`document.getElementById('n').value = '123'`)
await browser.elementByCss('#minus-one').click()
await check(() => {
return browser.eval('window.location.pathname + window.location.search')
}, '/header?result=122')
})
it('should support notFound (javascript disabled)', async () => {
const browser = await next.browser('/server', {
// TODO we should also test this with javascript on but not-found is not implemented yet.
......
......@@ -12,6 +12,7 @@ export default function Counter() {
<button
id="inc"
onClick={async () => {
console.log(inc)
const newCount = await inc(count)
setCount(newCount)
}}
......
......@@ -27,6 +27,13 @@ async function file(formData) {
}
export default function Form() {
const b = 1
async function add(a, formData) {
'use server'
// Bind variable, closure variable, and argument.
redirect('/header?result=' + (a + b + Number(formData.get('n'))))
}
return (
<>
<hr />
......@@ -52,6 +59,13 @@ export default function Form() {
Upload file
</button>
</form>
<hr />
<form>
<input type="text" name="n" id="n" required />
<button type="submit" id="minus-one" formAction={add.bind(null, -2)}>
-1
</button>
</form>
</>
)
}
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