diff --git a/packages/next-swc/crates/core/src/server_actions.rs b/packages/next-swc/crates/core/src/server_actions.rs index 7013520ec7e79..702cb852c4569 100644 --- a/packages/next-swc/crates/core/src/server_actions.rs +++ b/packages/next-swc/crates/core/src/server_actions.rs @@ -1,5 +1,5 @@ use std::{ - collections::HashMap, + collections::BTreeMap, convert::{TryFrom, TryInto}, }; @@ -29,7 +29,8 @@ pub struct Config { } /// A mapping of hashed action id to the action's exported function name. -pub type ActionsMap = HashMap; +// Using BTreeMap to ensure the order of the actions is deterministic. +pub type ActionsMap = BTreeMap; pub fn server_actions( file_name: &FileName, @@ -58,6 +59,7 @@ pub fn server_actions( annotations: Default::default(), extra_items: Default::default(), export_actions: Default::default(), + replaced_action_proxies: Default::default(), }) } @@ -113,6 +115,7 @@ struct ServerActions { // (ident, export name) exported_idents: Vec<(Id, String)>, + replaced_action_proxies: Vec<(Ident, Box)>, annotations: Vec, extra_items: Vec, @@ -157,13 +160,12 @@ impl ServerActions { is_action_fn } - fn add_action_annotations_and_maybe_hoist( + fn maybe_hoist_and_create_proxy( &mut self, ident: &Ident, function: Option<&mut Box>, arrow: Option<&mut ArrowExpr>, - return_paren: bool, - ) -> (Option>, Option>) { + ) -> Option> { let action_name: JsWord = gen_ident(&mut self.ident_cnt); let action_ident = private_ident!(action_name.clone()); @@ -197,56 +199,9 @@ impl ServerActions { } }); - let args_arg = private_ident!("args"); - - let call = CallExpr { - span: DUMMY_SP, - callee: action_ident - .clone() - .make_member(quote_ident!("apply")) - .as_callee(), - args: vec![ - ExprOrSpread { - spread: None, - expr: Lit::Null(Null { span: DUMMY_SP }).into(), - }, - ExprOrSpread { - spread: None, - expr: Box::new(Expr::Call(CallExpr { - span: DUMMY_SP, - callee: Callee::Expr(Box::new(Expr::Member(MemberExpr { - span: DUMMY_SP, - obj: Box::new(Expr::Bin(BinExpr { - span: DUMMY_SP, - op: op!("||"), - left: Box::new(ident.clone().make_member(quote_ident!("$$bound"))), - right: Box::new( - ArrayLit { - span: DUMMY_SP, - elems: vec![], - } - .into(), - ), - })), - prop: MemberProp::Ident(Ident { - sym: "concat".into(), - span: DUMMY_SP, - optional: false, - }), - }))), - args: vec![args_arg.clone().as_arg()], - type_args: Default::default(), - })), - }, - ], - type_args: Default::default(), - }; - if let Some(a) = arrow { - let mut arrow_annotations = Vec::new(); - annotate_ident_as_action( - &mut arrow_annotations, - ident.clone(), + let register_action_expr = annotate_ident_as_action( + action_ident.clone(), ids_from_closure .iter() .cloned() @@ -254,42 +209,28 @@ impl ServerActions { .collect(), &self.file_name, export_name.to_string(), - Some(action_ident.clone()), ); if let BlockStmtOrExpr::BlockStmt(block) = &mut *a.body { block.visit_mut_with(&mut ClosureReplacer { used_ids: &ids_from_closure, }); - } - let new_arrow = ArrowExpr { - span: DUMMY_SP, - params: vec![ - // ...args - Pat::Rest(RestPat { - span: DUMMY_SP, - dot3_token: DUMMY_SP, - arg: Box::new(Pat::Ident(args_arg.into())), - type_ann: Default::default(), - }), - ], - body: Box::new(BlockStmtOrExpr::Expr(Box::new(Expr::Call(call)))), - is_async: true, - is_generator: false, - type_params: Default::default(), - return_type: Default::default(), - }; + self.replaced_action_proxies + .push((ident.clone(), Box::new(register_action_expr))); + } // export const $ACTION_myAction = async () => {} - let mut new_params: Vec = vec![]; + let mut new_params: Vec = vec![]; let mut new_body: BlockStmtOrExpr = *a.body.clone(); if !ids_from_closure.is_empty() { // First argument is the encrypted closure variables - new_params.push(Pat::Ident( - Ident::new("$$ACTION_CLOSURE_BOUND".into(), DUMMY_SP).into(), - )); + new_params.push(Param { + span: DUMMY_SP, + decorators: vec![], + pat: Pat::Ident(Ident::new("$$ACTION_CLOSURE_BOUND".into(), DUMMY_SP).into()), + }); // Also prepend the decryption decl into the body. // var [arg1, arg2, arg3] = await decryptActionBoundArgs(actionId, @@ -348,66 +289,47 @@ impl ServerActions { } for p in a.params.iter() { - new_params.push(p.clone()); + new_params.push(Param { + span: DUMMY_SP, + decorators: vec![], + pat: p.clone(), + }); } - // Create the action export decl + // Create the action export decl from the arrow function self.extra_items .push(ModuleItem::ModuleDecl(ModuleDecl::ExportDecl(ExportDecl { span: DUMMY_SP, - decl: Decl::Var(Box::new(VarDecl { - span: DUMMY_SP, - kind: VarDeclKind::Var, - declare: Default::default(), - decls: vec![VarDeclarator { + decl: FnDecl { + ident: action_ident.clone(), + function: Box::new(Function { + params: new_params, + body: match new_body { + BlockStmtOrExpr::BlockStmt(body) => Some(body), + BlockStmtOrExpr::Expr(expr) => Some(BlockStmt { + span: DUMMY_SP, + stmts: vec![Stmt::Return(ReturnStmt { + span: DUMMY_SP, + arg: Some(expr), + })], + }), + }, + decorators: vec![], span: DUMMY_SP, - name: action_ident.clone().into(), - init: Some(Box::new(Expr::Arrow(ArrowExpr { - params: new_params, - body: Box::new(new_body), - ..a.clone() - }))), - definite: Default::default(), - }], - })), + is_generator: false, + is_async: true, + type_params: None, + return_type: None, + }), + declare: Default::default(), + } + .into(), }))); - // Create a paren expr to wrap all annotations: - // ($ACTION = async () => {}, $ACTION.$$id = "..", .., - // $ACTION) - let mut exprs = vec![Box::new(Expr::Assign(AssignExpr { - span: DUMMY_SP, - left: PatOrExpr::Pat(Box::new(Pat::Ident(ident.clone().into()))), - op: op!("="), - right: Box::new(Expr::Arrow(new_arrow)), - }))]; - exprs.extend(arrow_annotations.into_iter().map(|a| { - if let Stmt::Expr(ExprStmt { expr, .. }) = a { - expr - } else { - unreachable!() - } - })); - exprs.push(Box::new(Expr::Ident(ident.clone()))); - - let new_paren = ParenExpr { - span: DUMMY_SP, - expr: Box::new(Expr::Seq(SeqExpr { - span: DUMMY_SP, - exprs, - })), - }; - - return (Some(Box::new(new_paren)), None); + return Some(Box::new(Expr::Ident(ident.clone()))); } else if let Some(f) = function { - let mut fn_annotations = Vec::new(); - annotate_ident_as_action( - if return_paren { - &mut fn_annotations - } else { - &mut self.annotations - }, - ident.clone(), + let register_action_expr = annotate_ident_as_action( + action_ident.clone(), ids_from_closure .iter() .cloned() @@ -415,41 +337,14 @@ impl ServerActions { .collect(), &self.file_name, export_name.to_string(), - Some(action_ident.clone()), ); f.body.visit_mut_with(&mut ClosureReplacer { used_ids: &ids_from_closure, }); - let new_fn = Function { - params: vec![ - // ...args - Param { - span: DUMMY_SP, - decorators: vec![], - pat: Pat::Rest(RestPat { - span: DUMMY_SP, - dot3_token: DUMMY_SP, - arg: Box::new(Pat::Ident(args_arg.into())), - type_ann: Default::default(), - }), - }, - ], - decorators: vec![], - span: f.span, - body: Some(BlockStmt { - span: DUMMY_SP, - stmts: vec![Stmt::Return(ReturnStmt { - span: DUMMY_SP, - arg: Some(call.into()), - })], - }), - is_generator: false, - is_async: true, - type_params: Default::default(), - return_type: Default::default(), - }; + self.replaced_action_proxies + .push((ident.clone(), Box::new(register_action_expr))); // export async function $ACTION_myAction () {} let mut new_params: Vec = vec![]; @@ -530,41 +425,10 @@ impl ServerActions { .into(), }))); - if return_paren { - // Create a paren expr to wrap all annotations: - // ($ACTION = async function () {}, $ACTION.$$id = "..", .., - // $ACTION) - let mut exprs = vec![Box::new(Expr::Assign(AssignExpr { - span: DUMMY_SP, - left: PatOrExpr::Pat(Box::new(Pat::Ident(ident.clone().into()))), - op: op!("="), - right: Box::new(Expr::Fn(FnExpr { - ident: None, - function: Box::new(new_fn), - })), - }))]; - fn_annotations.into_iter().for_each(|a| { - if let Stmt::Expr(ExprStmt { expr, .. }) = a { - exprs.push(expr); - } - }); - exprs.push(Box::new(Expr::Ident(ident.clone()))); - - let new_paren = ParenExpr { - span: DUMMY_SP, - expr: Box::new(Expr::Seq(SeqExpr { - span: DUMMY_SP, - exprs, - })), - }; - - return (Some(Box::new(new_paren)), None); - } - - return (None, Some(Box::new(new_fn))); + return Some(Box::new(Expr::Ident(ident.clone()))); } - (None, None) + None } } @@ -670,16 +534,22 @@ impl VisitMut for ServerActions { .emit(); }); } else if !self.in_action_file { - let (_, maybe_new_fn) = self.add_action_annotations_and_maybe_hoist( - &f.ident, - Some(&mut f.function), - None, - false, - ); + self.maybe_hoist_and_create_proxy(&f.ident, Some(&mut f.function), None); - if let Some(new_fn) = maybe_new_fn { - f.function = new_fn; - } + // Make the original function declaration empty, as we have hoisted it already. + f.function = Box::new(Function { + params: vec![], + decorators: vec![], + span: DUMMY_SP, + body: Some(BlockStmt { + span: DUMMY_SP, + stmts: vec![], + }), + is_generator: false, + is_async: false, + type_params: None, + return_type: None, + }); } } @@ -814,18 +684,13 @@ impl VisitMut for ServerActions { let action_name = gen_ident(&mut self.ident_cnt); let ident = private_ident!(action_name); - let (maybe_new_paren, _) = - self.add_action_annotations_and_maybe_hoist(&ident, None, Some(a), true); + let maybe_new_expr = self.maybe_hoist_and_create_proxy(&ident, None, Some(a)); - *n = attach_name_to_expr( - ident, - if let Some(new_paren) = maybe_new_paren { - Expr::Paren(*new_paren) - } else { - Expr::Arrow(a.clone()) - }, - &mut self.extra_items, - ); + *n = if let Some(new_expr) = maybe_new_expr { + *new_expr + } else { + Expr::Arrow(a.clone()) + }; } Expr::Fn(f) => { let is_action_fn = self.get_action_info(f.function.body.as_mut(), true); @@ -842,19 +707,11 @@ impl VisitMut for ServerActions { Some(i) => i, }; - let (maybe_new_paren, _) = self.add_action_annotations_and_maybe_hoist( - ident, - Some(&mut f.function), - None, - true, - ); + let maybe_new_expr = + self.maybe_hoist_and_create_proxy(ident, Some(&mut f.function), None); - if let Some(new_paren) = maybe_new_paren { - *n = attach_name_to_expr( - ident.clone(), - Expr::Paren(*new_paren), - &mut self.extra_items, - ); + if let Some(new_expr) = maybe_new_expr { + *n = *new_expr; } } _ => {} @@ -1112,14 +969,15 @@ impl VisitMut for ServerActions { new.push(export_expr); } } else { - annotate_ident_as_action( - &mut self.annotations, - ident.clone(), - Vec::new(), - &self.file_name, - export_name.to_string(), - None, - ); + self.annotations.push(Stmt::Expr(ExprStmt { + span: DUMMY_SP, + expr: Box::new(annotate_ident_as_action( + ident.clone(), + Vec::new(), + &self.file_name, + export_name.to_string(), + )), + })); } } @@ -1199,27 +1057,28 @@ impl VisitMut for ServerActions { }, ); - // import { createActionProxy } from 'private-next-rsc-action-proxy' - // createActionProxy("action_id") - new.push(ModuleItem::ModuleDecl(ModuleDecl::Import(ImportDecl { - span: DUMMY_SP, - specifiers: vec![ImportSpecifier::Named(ImportNamedSpecifier { - span: DUMMY_SP, - local: quote_ident!("createActionProxy"), - imported: None, - is_type_only: false, - })], - src: Box::new(Str { + if self.config.is_react_server_layer { + // Inlined actions are only allowed on the server layer. + // import { createActionProxy } from 'private-next-rsc-action-proxy' + // createActionProxy("action_id") + new.push(ModuleItem::ModuleDecl(ModuleDecl::Import(ImportDecl { span: DUMMY_SP, - value: "private-next-rsc-action-proxy".into(), - raw: None, - }), - type_only: false, - with: None, - }))); + specifiers: vec![ImportSpecifier::Named(ImportNamedSpecifier { + span: DUMMY_SP, + local: quote_ident!("createActionProxy"), + imported: None, + is_type_only: false, + })], + src: Box::new(Str { + span: DUMMY_SP, + value: "private-next-rsc-action-proxy".into(), + raw: None, + }), + type_only: false, + with: None, + }))); - // Encryption and decryption only happens on the server layer. - if self.config.is_react_server_layer { + // Encryption and decryption only happens on the server layer. // import { encryptActionBoundArgs, decryptActionBoundArgs } from // 'private-next-rsc-action-encryption' new.push(ModuleItem::ModuleDecl(ModuleDecl::Import(ImportDecl { @@ -1257,6 +1116,10 @@ impl VisitMut for ServerActions { *stmts = new; + stmts.visit_mut_with(&mut ClosureActionReplacer { + replaced_action_proxies: &self.replaced_action_proxies, + }); + self.annotations = old_annotations; } @@ -1348,79 +1211,74 @@ fn generate_action_id(file_name: &str, export_name: &str) -> String { } fn annotate_ident_as_action( - annotations: &mut Vec, ident: Ident, bound: Vec>, file_name: &str, export_name: String, - maybe_orig_action_ident: Option, -) { +) -> Expr { // Add the proxy wrapper call `createActionProxy($$id, $$bound, myAction, // maybe_orig_action)`. let action_id = generate_action_id(file_name, &export_name); - let mut args = vec![ - // $$id - ExprOrSpread { - spread: None, - expr: Box::new(action_id.clone().into()), - }, - // myAction.$$bound = [encryptActionBoundArgs(actionId, [arg1, arg2, arg3])]; - // or myAction.$$bound = null; if there are no bound values. - ExprOrSpread { - spread: None, - expr: Box::new(if bound.is_empty() { - Lit::Null(Null { span: DUMMY_SP }).into() - } else { - ArrayLit { - span: DUMMY_SP, - elems: vec![Some(ExprOrSpread { - spread: None, - expr: Box::new(Expr::Call(CallExpr { - span: DUMMY_SP, - callee: quote_ident!("encryptActionBoundArgs").as_callee(), - args: vec![ - ExprOrSpread { - spread: None, - expr: Box::new(action_id.into()), - }, - ExprOrSpread { - spread: None, - expr: Box::new(Expr::Array(ArrayLit { - span: DUMMY_SP, - elems: bound, - })), - }, - ], - type_args: None, - })), - })], - } - .into() - }), - }, - ExprOrSpread { - spread: None, - expr: Box::new(Expr::Ident(ident)), - }, - ]; - - annotations.push(Stmt::Expr(ExprStmt { + + let proxy_expr = Expr::Call(CallExpr { span: DUMMY_SP, - expr: Box::new(Expr::Call(CallExpr { + callee: quote_ident!("createActionProxy").as_callee(), + args: vec![ + // $$id + ExprOrSpread { + spread: None, + expr: Box::new(action_id.clone().into()), + }, + ExprOrSpread { + spread: None, + expr: Box::new(Expr::Ident(ident)), + }, + ], + type_args: Default::default(), + }); + + if bound.is_empty() { + proxy_expr + } else { + // proxy_expr.bind(null, [encryptActionBoundArgs("id", [arg1, ...])]) + Expr::Call(CallExpr { span: DUMMY_SP, - callee: quote_ident!("createActionProxy").as_callee(), - args: if let Some(orig_action_ident) = maybe_orig_action_ident { - args.push(ExprOrSpread { + callee: Expr::Member(MemberExpr { + span: DUMMY_SP, + obj: Box::new(proxy_expr), + prop: MemberProp::Ident(quote_ident!("bind")), + }) + .as_callee(), + args: vec![ + ExprOrSpread { spread: None, - expr: Box::new(Expr::Ident(orig_action_ident)), - }); - args - } else { - args - }, + expr: Box::new(Expr::Lit(Lit::Null(Null { span: DUMMY_SP }))), + }, + ExprOrSpread { + spread: None, + expr: Box::new(Expr::Call(CallExpr { + span: DUMMY_SP, + callee: quote_ident!("encryptActionBoundArgs").as_callee(), + args: vec![ + ExprOrSpread { + spread: None, + expr: Box::new(action_id.into()), + }, + ExprOrSpread { + spread: None, + expr: Box::new(Expr::Array(ArrayLit { + span: DUMMY_SP, + elems: bound, + })), + }, + ], + type_args: None, + })), + }, + ], type_args: Default::default(), - })), - })); + }) + } } const DIRECTIVE_TYPOS: &[&str] = &[ @@ -1692,6 +1550,45 @@ fn collect_idents_in_stmt(stmt: &Stmt) -> Vec { ids } +pub(crate) struct ClosureActionReplacer<'a> { + replaced_action_proxies: &'a Vec<(Ident, Box)>, +} + +impl ClosureActionReplacer<'_> { + fn index(&self, i: &Ident) -> Option { + self.replaced_action_proxies + .iter() + .position(|(ident, _)| ident.sym == i.sym && ident.span.ctxt == i.span.ctxt) + } +} + +impl VisitMut for ClosureActionReplacer<'_> { + fn visit_mut_expr(&mut self, e: &mut Expr) { + e.visit_mut_children_with(self); + + if let Expr::Ident(i) = e { + if let Some(index) = self.index(i) { + *e = *self.replaced_action_proxies[index].1.clone(); + } + } + } + + fn visit_mut_prop_or_spread(&mut self, n: &mut PropOrSpread) { + n.visit_mut_children_with(self); + + if let PropOrSpread::Prop(box Prop::Shorthand(i)) = n { + if let Some(index) = self.index(i) { + *n = PropOrSpread::Prop(Box::new(Prop::KeyValue(KeyValueProp { + key: PropName::Ident(i.clone()), + value: Box::new(*self.replaced_action_proxies[index].1.clone()), + }))); + } + } + } + + noop_visit_mut_type!(); +} + pub(crate) struct ClosureReplacer<'a> { used_ids: &'a [Name], } diff --git a/packages/next-swc/crates/core/tests/errors/server-actions/client-graph/1/output.js b/packages/next-swc/crates/core/tests/errors/server-actions/client-graph/1/output.js index 4f6910bb0b0e7..544296c840873 100644 --- a/packages/next-swc/crates/core/tests/errors/server-actions/client-graph/1/output.js +++ b/packages/next-swc/crates/core/tests/errors/server-actions/client-graph/1/output.js @@ -1,9 +1,5 @@ -/* __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
App
; } -export async function $$ACTION_0() {} diff --git a/packages/next-swc/crates/core/tests/errors/server-actions/server-graph/1/output.js b/packages/next-swc/crates/core/tests/errors/server-actions/server-graph/1/output.js index 7a8fe41229e26..9e261dd7b291e 100644 --- a/packages/next-swc/crates/core/tests/errors/server-actions/server-graph/1/output.js +++ b/packages/next-swc/crates/core/tests/errors/server-actions/server-graph/1/output.js @@ -5,4 +5,4 @@ import { ensureServerEntryExports } from "private-next-rsc-action-validate"; ensureServerEntryExports([ foo ]); -createActionProxy("ab21efdafbe611287bc25c0462b1e0510d13e48b", null, foo); +createActionProxy("ab21efdafbe611287bc25c0462b1e0510d13e48b", foo); diff --git a/packages/next-swc/crates/core/tests/errors/server-actions/server-graph/2/output.js b/packages/next-swc/crates/core/tests/errors/server-actions/server-graph/2/output.js index 72edc1481ec50..97d918daabba0 100644 --- a/packages/next-swc/crates/core/tests/errors/server-actions/server-graph/2/output.js +++ b/packages/next-swc/crates/core/tests/errors/server-actions/server-graph/2/output.js @@ -6,4 +6,4 @@ import { ensureServerEntryExports } from "private-next-rsc-action-validate"; ensureServerEntryExports([ bar ]); -createActionProxy("ac840dcaf5e8197cb02b7f3a43c119b7a770b272", null, bar); +createActionProxy("ac840dcaf5e8197cb02b7f3a43c119b7a770b272", bar); diff --git a/packages/next-swc/crates/core/tests/errors/server-actions/server-graph/3/output.js b/packages/next-swc/crates/core/tests/errors/server-actions/server-graph/3/output.js index e3619a247013b..c6a9e115ec00f 100644 --- a/packages/next-swc/crates/core/tests/errors/server-actions/server-graph/3/output.js +++ b/packages/next-swc/crates/core/tests/errors/server-actions/server-graph/3/output.js @@ -5,4 +5,4 @@ import { ensureServerEntryExports } from "private-next-rsc-action-validate"; ensureServerEntryExports([ x ]); -createActionProxy("b78c261f135a7a852508c2920bd7228020ff4bd7", null, x); +createActionProxy("b78c261f135a7a852508c2920bd7228020ff4bd7", x); diff --git a/packages/next-swc/crates/core/tests/errors/server-actions/server-graph/7/output.js b/packages/next-swc/crates/core/tests/errors/server-actions/server-graph/7/output.js index fafe434c1e7f2..a20e6da44a5b2 100644 --- a/packages/next-swc/crates/core/tests/errors/server-actions/server-graph/7/output.js +++ b/packages/next-swc/crates/core/tests/errors/server-actions/server-graph/7/output.js @@ -1,5 +1,4 @@ /* __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() {} diff --git a/packages/next-swc/crates/core/tests/errors/server-actions/server-graph/8/output.js b/packages/next-swc/crates/core/tests/errors/server-actions/server-graph/8/output.js index aeb9d47f6df11..257ea035bb64a 100644 --- a/packages/next-swc/crates/core/tests/errors/server-actions/server-graph/8/output.js +++ b/packages/next-swc/crates/core/tests/errors/server-actions/server-graph/8/output.js @@ -1,10 +1,9 @@ /* __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 diff --git a/packages/next-swc/crates/core/tests/fixture/server-actions/client/1/output.js b/packages/next-swc/crates/core/tests/fixture/server-actions/client/1/output.js index eee92f539097c..d560cc5559c7d 100644 --- a/packages/next-swc/crates/core/tests/fixture/server-actions/client/1/output.js +++ b/packages/next-swc/crates/core/tests/fixture/server-actions/client/1/output.js @@ -1,5 +1,4 @@ // 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"); diff --git a/packages/next-swc/crates/core/tests/fixture/server-actions/client/2/output.js b/packages/next-swc/crates/core/tests/fixture/server-actions/client/2/output.js index e21c169ecfe1a..73612880801a2 100644 --- a/packages/next-swc/crates/core/tests/fixture/server-actions/client/2/output.js +++ b/packages/next-swc/crates/core/tests/fixture/server-actions/client/2/output.js @@ -1,4 +1,3 @@ // 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"); diff --git a/packages/next-swc/crates/core/tests/fixture/server-actions/client/3/output.js b/packages/next-swc/crates/core/tests/fixture/server-actions/client/3/output.js index b03370598668b..9cd3edfa39a3f 100644 --- a/packages/next-swc/crates/core/tests/fixture/server-actions/client/3/output.js +++ b/packages/next-swc/crates/core/tests/fixture/server-actions/client/3/output.js @@ -1,6 +1,5 @@ -/* __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"); diff --git a/packages/next-swc/crates/core/tests/fixture/server-actions/client/4/output.js b/packages/next-swc/crates/core/tests/fixture/server-actions/client/4/output.js index 41fa6e3beec61..9caa9de514b2a 100644 --- a/packages/next-swc/crates/core/tests/fixture/server-actions/client/4/output.js +++ b/packages/next-swc/crates/core/tests/fixture/server-actions/client/4/output.js @@ -1,3 +1,2 @@ -/* __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"); diff --git a/packages/next-swc/crates/core/tests/fixture/server-actions/server/1/output.js b/packages/next-swc/crates/core/tests/fixture/server-actions/server/1/output.js index a90bc4edad633..ceb6571d200f7 100644 --- a/packages/next-swc/crates/core/tests/fixture/server-actions/server/1/output.js +++ b/packages/next-swc/crates/core/tests/fixture/server-actions/server/1/output.js @@ -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 ; + function deleteItem() {} + return ; } 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; +} diff --git a/packages/next-swc/crates/core/tests/fixture/server-actions/server/10/output.js b/packages/next-swc/crates/core/tests/fixture/server-actions/server/10/output.js index 3e8436d9c95a1..8666bb1f6e985 100644 --- a/packages/next-swc/crates/core/tests/fixture/server-actions/server/10/output.js +++ b/packages/next-swc/crates/core/tests/fixture/server-actions/server/10/output.js @@ -5,4 +5,4 @@ import { ensureServerEntryExports } from "private-next-rsc-action-validate"; ensureServerEntryExports([ foo ]); -createActionProxy("c18c215a6b7cdc64bf709f3a714ffdef1bf9651d", null, foo); +createActionProxy("c18c215a6b7cdc64bf709f3a714ffdef1bf9651d", foo); diff --git a/packages/next-swc/crates/core/tests/fixture/server-actions/server/11/output.js b/packages/next-swc/crates/core/tests/fixture/server-actions/server/11/output.js index cea76b8da3fa0..dab935ba484f6 100644 --- a/packages/next-swc/crates/core/tests/fixture/server-actions/server/11/output.js +++ b/packages/next-swc/crates/core/tests/fixture/server-actions/server/11/output.js @@ -5,4 +5,4 @@ import { ensureServerEntryExports } from "private-next-rsc-action-validate"; ensureServerEntryExports([ $$ACTION_0 ]); -createActionProxy("c18c215a6b7cdc64bf709f3a714ffdef1bf9651d", null, $$ACTION_0); +createActionProxy("c18c215a6b7cdc64bf709f3a714ffdef1bf9651d", $$ACTION_0); diff --git a/packages/next-swc/crates/core/tests/fixture/server-actions/server/12/output.js b/packages/next-swc/crates/core/tests/fixture/server-actions/server/12/output.js index 5ee8474d6a6f2..373f388b78dcb 100644 --- a/packages/next-swc/crates/core/tests/fixture/server-actions/server/12/output.js +++ b/packages/next-swc/crates/core/tests/fixture/server-actions/server/12/output.js @@ -6,4 +6,4 @@ import { ensureServerEntryExports } from "private-next-rsc-action-validate"; ensureServerEntryExports([ foo ]); -createActionProxy("c18c215a6b7cdc64bf709f3a714ffdef1bf9651d", null, foo); +createActionProxy("c18c215a6b7cdc64bf709f3a714ffdef1bf9651d", foo); diff --git a/packages/next-swc/crates/core/tests/fixture/server-actions/server/13/output.js b/packages/next-swc/crates/core/tests/fixture/server-actions/server/13/output.js index 37475e9ead4af..c4db2124ab3cb 100644 --- a/packages/next-swc/crates/core/tests/fixture/server-actions/server/13/output.js +++ b/packages/next-swc/crates/core/tests/fixture/server-actions/server/13/output.js @@ -9,5 +9,5 @@ ensureServerEntryExports([ foo, bar ]); -createActionProxy("c18c215a6b7cdc64bf709f3a714ffdef1bf9651d", null, foo); -createActionProxy("ac840dcaf5e8197cb02b7f3a43c119b7a770b272", null, bar); +createActionProxy("c18c215a6b7cdc64bf709f3a714ffdef1bf9651d", foo); +createActionProxy("ac840dcaf5e8197cb02b7f3a43c119b7a770b272", bar); diff --git a/packages/next-swc/crates/core/tests/fixture/server-actions/server/14/output.js b/packages/next-swc/crates/core/tests/fixture/server-actions/server/14/output.js index fd8bf705474bd..1b1dbde5af657 100644 --- a/packages/next-swc/crates/core/tests/fixture/server-actions/server/14/output.js +++ b/packages/next-swc/crates/core/tests/fixture/server-actions/server/14/output.js @@ -7,4 +7,4 @@ import { ensureServerEntryExports } from "private-next-rsc-action-validate"; ensureServerEntryExports([ foo ]); -createActionProxy("ab21efdafbe611287bc25c0462b1e0510d13e48b", null, foo); +createActionProxy("ab21efdafbe611287bc25c0462b1e0510d13e48b", foo); diff --git a/packages/next-swc/crates/core/tests/fixture/server-actions/server/15/output.js b/packages/next-swc/crates/core/tests/fixture/server-actions/server/15/output.js index 867cd841293fe..8aeb838a9c956 100644 --- a/packages/next-swc/crates/core/tests/fixture/server-actions/server/15/output.js +++ b/packages/next-swc/crates/core/tests/fixture/server-actions/server/15/output.js @@ -8,4 +8,4 @@ import { ensureServerEntryExports } from "private-next-rsc-action-validate"; ensureServerEntryExports([ $$ACTION_0 ]); -createActionProxy("c18c215a6b7cdc64bf709f3a714ffdef1bf9651d", null, $$ACTION_0); +createActionProxy("c18c215a6b7cdc64bf709f3a714ffdef1bf9651d", $$ACTION_0); diff --git a/packages/next-swc/crates/core/tests/fixture/server-actions/server/16/output.js b/packages/next-swc/crates/core/tests/fixture/server-actions/server/16/output.js index 48aff3d82ad8b..a33ad000d1f3c 100644 --- a/packages/next-swc/crates/core/tests/fixture/server-actions/server/16/output.js +++ b/packages/next-swc/crates/core/tests/fixture/server-actions/server/16/output.js @@ -1,47 +1,34 @@ -/* __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 ; } -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; +} diff --git a/packages/next-swc/crates/core/tests/fixture/server-actions/server/17/output.js b/packages/next-swc/crates/core/tests/fixture/server-actions/server/17/output.js index 2768102d45678..655766407d050 100644 --- a/packages/next-swc/crates/core/tests/fixture/server-actions/server/17/output.js +++ b/packages/next-swc/crates/core/tests/fixture/server-actions/server/17/output.js @@ -8,5 +8,5 @@ ensureServerEntryExports([ foo, bar ]); -createActionProxy("ab21efdafbe611287bc25c0462b1e0510d13e48b", null, foo); -createActionProxy("ac840dcaf5e8197cb02b7f3a43c119b7a770b272", null, bar); +createActionProxy("ab21efdafbe611287bc25c0462b1e0510d13e48b", foo); +createActionProxy("ac840dcaf5e8197cb02b7f3a43c119b7a770b272", bar); diff --git a/packages/next-swc/crates/core/tests/fixture/server-actions/server/18/output.js b/packages/next-swc/crates/core/tests/fixture/server-actions/server/18/output.js index 1591ca40a433d..b4628bf98efd3 100644 --- a/packages/next-swc/crates/core/tests/fixture/server-actions/server/18/output.js +++ b/packages/next-swc/crates/core/tests/fixture/server-actions/server/18/output.js @@ -6,25 +6,19 @@ export function Item({ id1, id2 }) { const v2 = id2; return <> - - ; + return ; } -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() {} diff --git a/packages/next-swc/crates/core/tests/fixture/server-actions/server/20/output.js b/packages/next-swc/crates/core/tests/fixture/server-actions/server/20/output.js index 1a97f734b5b0b..bd3457e7b41a5 100644 --- a/packages/next-swc/crates/core/tests/fixture/server-actions/server/20/output.js +++ b/packages/next-swc/crates/core/tests/fixture/server-actions/server/20/output.js @@ -8,4 +8,4 @@ import { ensureServerEntryExports } from "private-next-rsc-action-validate"; ensureServerEntryExports([ foo ]); -createActionProxy("c18c215a6b7cdc64bf709f3a714ffdef1bf9651d", null, foo); +createActionProxy("c18c215a6b7cdc64bf709f3a714ffdef1bf9651d", foo); diff --git a/packages/next-swc/crates/core/tests/fixture/server-actions/server/21/output.js b/packages/next-swc/crates/core/tests/fixture/server-actions/server/21/output.js index bdb8662bb91c8..9962a9e0f8bfd 100644 --- a/packages/next-swc/crates/core/tests/fixture/server-actions/server/21/output.js +++ b/packages/next-swc/crates/core/tests/fixture/server-actions/server/21/output.js @@ -1,25 +1,18 @@ -/* __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 ; + return ; } 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() {} diff --git a/packages/next-swc/crates/core/tests/fixture/server-actions/server/22/output.js b/packages/next-swc/crates/core/tests/fixture/server-actions/server/22/output.js index fa43b6820eb81..94f01484799aa 100644 --- a/packages/next-swc/crates/core/tests/fixture/server-actions/server/22/output.js +++ b/packages/next-swc/crates/core/tests/fixture/server-actions/server/22/output.js @@ -9,5 +9,5 @@ ensureServerEntryExports([ action, $$ACTION_0 ]); -createActionProxy("f14702b5a021dd117f7ec7a3c838f397c2046d3b", null, action); -createActionProxy("c18c215a6b7cdc64bf709f3a714ffdef1bf9651d", null, $$ACTION_0); +createActionProxy("f14702b5a021dd117f7ec7a3c838f397c2046d3b", action); +createActionProxy("c18c215a6b7cdc64bf709f3a714ffdef1bf9651d", $$ACTION_0); diff --git a/packages/next-swc/crates/core/tests/fixture/server-actions/server/23/output.js b/packages/next-swc/crates/core/tests/fixture/server-actions/server/23/output.js index d5d8b578ddfcc..19a553d7580aa 100644 --- a/packages/next-swc/crates/core/tests/fixture/server-actions/server/23/output.js +++ b/packages/next-swc/crates/core/tests/fixture/server-actions/server/23/output.js @@ -1,28 +1,20 @@ /* __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; +} diff --git a/packages/next-swc/crates/core/tests/fixture/server-actions/server/24/output.js b/packages/next-swc/crates/core/tests/fixture/server-actions/server/24/output.js index adc929dd6d772..98b899925ae01 100644 --- a/packages/next-swc/crates/core/tests/fixture/server-actions/server/24/output.js +++ b/packages/next-swc/crates/core/tests/fixture/server-actions/server/24/output.js @@ -1,14 +1,7 @@ /* __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); diff --git a/packages/next-swc/crates/core/tests/fixture/server-actions/server/25/input.js b/packages/next-swc/crates/core/tests/fixture/server-actions/server/25/input.js new file mode 100644 index 0000000000000..d6995dc0a6842 --- /dev/null +++ b/packages/next-swc/crates/core/tests/fixture/server-actions/server/25/input.js @@ -0,0 +1,34 @@ +import deleteFromDb from 'db' + +export function Item({ id1, id2 }) { + id1++ + return (() => { + id1++ + return + })() + + 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() + + id1++ + temp.push() + + return temp + + async function deleteItem() { + 'use server' + await deleteFromDb(id1) + await deleteFromDb(id2) + } +} diff --git a/packages/next-swc/crates/core/tests/fixture/server-actions/server/25/output.js b/packages/next-swc/crates/core/tests/fixture/server-actions/server/25/output.js new file mode 100644 index 0000000000000..07ea05c5b4be2 --- /dev/null +++ b/packages/next-swc/crates/core/tests/fixture/server-actions/server/25/output.js @@ -0,0 +1,41 @@ +/* __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 ; + })(); + 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(); + id1++; + temp.push(); + 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); +} diff --git a/packages/next-swc/crates/core/tests/fixture/server-actions/server/26/input.js b/packages/next-swc/crates/core/tests/fixture/server-actions/server/26/input.js new file mode 100644 index 0000000000000..771f2f8bd5e02 --- /dev/null +++ b/packages/next-swc/crates/core/tests/fixture/server-actions/server/26/input.js @@ -0,0 +1,6 @@ +const noop = (action) => action + +export const log = noop(async (data) => { + 'use server' + console.log(data) +}) diff --git a/packages/next-swc/crates/core/tests/fixture/server-actions/server/26/output.js b/packages/next-swc/crates/core/tests/fixture/server-actions/server/26/output.js new file mode 100644 index 0000000000000..7b59b9896387e --- /dev/null +++ b/packages/next-swc/crates/core/tests/fixture/server-actions/server/26/output.js @@ -0,0 +1,7 @@ +/* __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); +} diff --git a/packages/next-swc/crates/core/tests/fixture/server-actions/server/3/output.js b/packages/next-swc/crates/core/tests/fixture/server-actions/server/3/output.js index 26b543c50a0ce..7bde2d0604efd 100644 --- a/packages/next-swc/crates/core/tests/fixture/server-actions/server/3/output.js +++ b/packages/next-swc/crates/core/tests/fixture/server-actions/server/3/output.js @@ -8,4 +8,4 @@ import { ensureServerEntryExports } from "private-next-rsc-action-validate"; ensureServerEntryExports([ myAction ]); -createActionProxy("e10665baac148856374b2789aceb970f66fec33e", null, myAction); +createActionProxy("e10665baac148856374b2789aceb970f66fec33e", myAction); diff --git a/packages/next-swc/crates/core/tests/fixture/server-actions/server/4/output.js b/packages/next-swc/crates/core/tests/fixture/server-actions/server/4/output.js index 0aaa4cc657a06..06a5bfa7ac9a6 100644 --- a/packages/next-swc/crates/core/tests/fixture/server-actions/server/4/output.js +++ b/packages/next-swc/crates/core/tests/fixture/server-actions/server/4/output.js @@ -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); diff --git a/packages/next-swc/crates/core/tests/fixture/server-actions/server/5/output.js b/packages/next-swc/crates/core/tests/fixture/server-actions/server/5/output.js index 2ffa42c88e809..607ec4b203741 100644 --- a/packages/next-swc/crates/core/tests/fixture/server-actions/server/5/output.js +++ b/packages/next-swc/crates/core/tests/fixture/server-actions/server/5/output.js @@ -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 ; + function deleteItem() {} + return ; } 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); diff --git a/packages/next-swc/crates/core/tests/fixture/server-actions/server/6/output.js b/packages/next-swc/crates/core/tests/fixture/server-actions/server/6/output.js index 50ea347905162..c9c87a090ebb6 100644 --- a/packages/next-swc/crates/core/tests/fixture/server-actions/server/6/output.js +++ b/packages/next-swc/crates/core/tests/fixture/server-actions/server/6/output.js @@ -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 ; + function action() {} + return ; } 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); diff --git a/packages/next-swc/crates/core/tests/fixture/server-actions/server/7/input.js b/packages/next-swc/crates/core/tests/fixture/server-actions/server/7/input.js index ce85dc4194495..4185109b0e194 100644 --- a/packages/next-swc/crates/core/tests/fixture/server-actions/server/7/input.js +++ b/packages/next-swc/crates/core/tests/fixture/server-actions/server/7/input.js @@ -1,7 +1,7 @@ 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 + return +} + +export function Item2(product, foo, bar) { + async function deleteItem2() { + 'use server' + await deleteFromDb( + product.id, + product?.foo, + product.bar.baz, + product[(foo, bar)] + ) + } + return +} + +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 +} + +export function Item4(product, foo, bar) { + const deleteItem4 = async () => { + 'use server' + await deleteFromDb( + product.id, + product?.foo, + product.bar.baz, + product[(foo, bar)] + ) + } + return } diff --git a/packages/next-swc/crates/core/tests/fixture/server-actions/server/7/output.js b/packages/next-swc/crates/core/tests/fixture/server-actions/server/7/output.js index 8b539ce494620..b83a85c6f8fa1 100644 --- a/packages/next-swc/crates/core/tests/fixture/server-actions/server/7/output.js +++ b/packages/next-swc/crates/core/tests/fixture/server-actions/server/7/output.js @@ -1,23 +1,63 @@ -/* __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 ; +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 ; } 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 ; +} +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 ; +} +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 ; +} +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]); +} diff --git a/packages/next-swc/crates/core/tests/fixture/server-actions/server/8/output.js b/packages/next-swc/crates/core/tests/fixture/server-actions/server/8/output.js index 93358366e844f..2ba116bc7de3c 100644 --- a/packages/next-swc/crates/core/tests/fixture/server-actions/server/8/output.js +++ b/packages/next-swc/crates/core/tests/fixture/server-actions/server/8/output.js @@ -1,14 +1,11 @@ /* __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 ; + return ; } diff --git a/packages/next-swc/crates/core/tests/fixture/server-actions/server/9/output.js b/packages/next-swc/crates/core/tests/fixture/server-actions/server/9/output.js index 38682c5fd5672..9d61cc907880f 100644 --- a/packages/next-swc/crates/core/tests/fixture/server-actions/server/9/output.js +++ b/packages/next-swc/crates/core/tests/fixture/server-actions/server/9/output.js @@ -1,5 +1,5 @@ // 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); diff --git a/packages/next/src/build/webpack/loaders/next-flight-loader/action-proxy.ts b/packages/next/src/build/webpack/loaders/next-flight-loader/action-proxy.ts index 0fe5ef99f21fb..0975e2fcc7080 100644 --- a/packages/next/src/build/webpack/loaders/next-flight-loader/action-proxy.ts +++ b/packages/next/src/build/webpack/loaders/next-flight-loader/action-proxy.ts @@ -1,49 +1,6 @@ -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) }