From bf6460e985c0ff8e41c03e000cbcb2638bcf99c7 Mon Sep 17 00:00:00 2001 From: Shu Ding Date: Wed, 24 Jan 2024 10:33:22 -0800 Subject: [PATCH 01/10] Improve the Server Actions SWC transform (#61001) This PR improves the Server Actions SWC transform to make it able to handle nested Action declarations (check `fixture/server-actions/server/28/input.js` for more details). It is also a simplification of that transform's internal states and methods, with the removal of an extra AST pass (`stmts.visit_mut_with(&mut ClosureActionReplacer { replaced_action_proxies: &self.replaced_action_proxies, })`). The generated code is also smaller in some cases. So overall I'd expect the compilation and runtime performance to improve as well. ## Details With this change, we're now using `self.declared_idents` and `self.names` to track closure arguments. `declared_idents` keeps the identifiers **declared** in the current closure and above. `names` keeps identifiers **appeared** in the current closure and above. In an example of the following cursor: ```ts let x async function foo() { "use server" let y async function bar() { "use server" let z console.log(x, y, z) } // <- cursor } ``` `declared_idents` would be `y` (`x` isn't in a closure), and `names` would be `x, y, z`. By manipulating these two states we're able to track closure closed-up variables recursively. Closes NEXT-2189 --- .../src/transforms/server_actions.rs | 358 +++++++----------- .../server-actions/server-graph/6/output.js | 3 +- .../server-actions/server-graph/7/output.js | 6 +- .../server-actions/server-graph/8/output.js | 6 +- .../fixture/server-actions/server/1/output.js | 13 +- .../server-actions/server/15/output.js | 7 +- .../server-actions/server/16/output.js | 20 +- .../server-actions/server/17/output.js | 3 +- .../server-actions/server/18/output.js | 14 +- .../server-actions/server/19/output.js | 8 +- .../fixture/server-actions/server/2/output.js | 8 +- .../server-actions/server/21/output.js | 8 +- .../server-actions/server/22/output.js | 12 +- .../server-actions/server/23/output.js | 12 +- .../server-actions/server/25/output.js | 15 +- .../server-actions/server/26/output.js | 6 +- .../server-actions/server/27/output.js | 11 +- .../fixture/server-actions/server/28/input.js | 24 ++ .../server-actions/server/28/output.js | 41 ++ .../fixture/server-actions/server/5/output.js | 7 +- .../fixture/server-actions/server/6/output.js | 9 +- .../fixture/server-actions/server/7/output.js | 17 +- .../fixture/server-actions/server/8/output.js | 2 +- 23 files changed, 284 insertions(+), 326 deletions(-) create mode 100644 packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/28/input.js create mode 100644 packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/28/output.js diff --git a/packages/next-swc/crates/next-custom-transforms/src/transforms/server_actions.rs b/packages/next-swc/crates/next-custom-transforms/src/transforms/server_actions.rs index 37dc34673cdd3..56ceb657b0f3f 100644 --- a/packages/next-swc/crates/next-custom-transforms/src/transforms/server_actions.rs +++ b/packages/next-swc/crates/next-custom-transforms/src/transforms/server_actions.rs @@ -47,23 +47,24 @@ pub fn server_actions( in_default_export_decl: false, has_action: false, - ident_cnt: 0, - in_module: true, + action_cnt: 0, + in_module_level: true, in_action_fn: false, - in_action_closure: false, - closure_idents: Default::default(), - action_closure_idents: Default::default(), + should_track_names: false, + + names: Default::default(), + declared_idents: Default::default(), + exported_idents: Default::default(), - inlined_action_closure_idents: Default::default(), // This flag allows us to rewrite `function foo() {}` to `const foo = createProxy(...)`. rewrite_fn_decl_to_proxy_decl: None, rewrite_default_fn_expr_to_proxy_expr: None, + rewrite_expr_to_proxy_expr: None, annotations: Default::default(), extra_items: Default::default(), export_actions: Default::default(), - replaced_action_proxies: Default::default(), }) } @@ -88,21 +89,21 @@ struct ServerActions { in_default_export_decl: bool, has_action: bool, - ident_cnt: u32, - in_module: bool, + action_cnt: u32, + in_module_level: bool, in_action_fn: bool, - in_action_closure: bool, - closure_idents: Vec, - action_closure_idents: Vec, - inlined_action_closure_idents: Vec<(Id, Id)>, + should_track_names: bool, + + names: Vec, + declared_idents: Vec, // This flag allows us to rewrite `function foo() {}` to `const foo = createProxy(...)`. rewrite_fn_decl_to_proxy_decl: Option, rewrite_default_fn_expr_to_proxy_expr: Option>, + rewrite_expr_to_proxy_expr: Option>, // (ident, export name) exported_idents: Vec<(Id, String)>, - replaced_action_proxies: Vec<(Ident, Box)>, annotations: Vec, extra_items: Vec, @@ -149,39 +150,17 @@ impl ServerActions { fn maybe_hoist_and_create_proxy( &mut self, - ident: &Ident, + ids_from_closure: Vec, function: Option<&mut Box>, arrow: Option<&mut ArrowExpr>, - ) -> (Option>, Option>) { - let action_name: JsWord = gen_ident(&mut self.ident_cnt); + ) -> Option> { + let action_name: JsWord = gen_ident(&mut self.action_cnt); let action_ident = private_ident!(action_name.clone()); - - if !self.in_action_file { - self.inlined_action_closure_idents - .push((ident.to_id(), action_ident.to_id())); - } - let export_name: JsWord = action_name; self.has_action = true; self.export_actions.push(export_name.to_string()); - // Hoist the function to the top level and export it. To hoist it, we need to - // first Collect all the identifiers defined in the closure and used - // in the action function. Dedup the identifiers. - let mut added_ids = Vec::new(); - let mut ids_from_closure = self.action_closure_idents.clone(); - ids_from_closure.retain(|id| { - if added_ids.contains(id) { - false - } else if self.closure_idents.contains(&id.0) { - added_ids.push(id.clone()); - true - } else { - false - } - }); - if let Some(a) = arrow { let register_action_expr = annotate_ident_as_action( action_ident.clone(), @@ -198,9 +177,6 @@ impl ServerActions { block.visit_mut_with(&mut ClosureReplacer { used_ids: &ids_from_closure, }); - - self.replaced_action_proxies - .push((ident.clone(), Box::new(register_action_expr.clone()))); } // export const $ACTION_myAction = async () => {} @@ -309,10 +285,7 @@ impl ServerActions { .into(), }))); - return ( - Some(Box::new(Expr::Ident(ident.clone()))), - Some(Box::new(register_action_expr)), - ); + return Some(Box::new(register_action_expr.clone())); } else if let Some(f) = function { let register_action_expr = annotate_ident_as_action( action_ident.clone(), @@ -329,9 +302,6 @@ impl ServerActions { used_ids: &ids_from_closure, }); - self.replaced_action_proxies - .push((ident.clone(), Box::new(register_action_expr.clone()))); - // export async function $ACTION_myAction () {} let mut new_params: Vec = vec![]; let mut new_body: Option = f.body.clone(); @@ -411,13 +381,10 @@ impl ServerActions { .into(), }))); - return ( - Some(Box::new(Expr::Ident(ident.clone()))), - Some(Box::new(register_action_expr)), - ); + return Some(Box::new(register_action_expr)); } - (None, None) + None } } @@ -451,30 +418,35 @@ impl VisitMut for ServerActions { } fn visit_mut_fn_expr(&mut self, f: &mut FnExpr) { - let is_action_fn = self.get_action_info(f.function.body.as_mut(), false); + let is_action_fn = self.get_action_info(f.function.body.as_mut(), true); + let current_declared_idents = self.declared_idents.clone(); + let current_names = self.names.clone(); + self.names = vec![]; + + // Visit children { - // Visit children let old_in_action_fn = self.in_action_fn; - let old_in_module = self.in_module; - let old_in_action_closure = self.in_action_closure; + let old_in_module = self.in_module_level; + let old_should_track_names = self.should_track_names; let old_in_export_decl = self.in_export_decl; let old_in_default_export_decl = self.in_default_export_decl; - let old_closure_idents = self.closure_idents.clone(); self.in_action_fn = is_action_fn; - self.in_module = false; - self.in_action_closure = true; + self.in_module_level = false; + self.should_track_names = true; self.in_export_decl = false; self.in_default_export_decl = false; f.visit_mut_children_with(self); self.in_action_fn = old_in_action_fn; - self.in_module = old_in_module; - self.in_action_closure = old_in_action_closure; + self.in_module_level = old_in_module; + self.should_track_names = old_should_track_names; self.in_export_decl = old_in_export_decl; self.in_default_export_decl = old_in_default_export_decl; - self.closure_idents = old_closure_idents; } + let mut child_names = self.names.clone(); + self.names.extend(current_names); + if !is_action_fn { return; } @@ -487,25 +459,32 @@ impl VisitMut for ServerActions { }); } - if !self.in_action_file && self.in_default_export_decl { - // This function expression is also the default export: - // `export default async function() {}` - // In this case, we need to collect the action and hoist, because this specific - // case (default export) isn't handled by `visit_mut_expr`. - let ident = match f.ident.as_mut() { + if !self.in_action_file { + match f.ident.as_mut() { None => { - let action_name = gen_ident(&mut self.ident_cnt); + let action_name = gen_ident(&mut self.action_cnt); let ident = Ident::new(action_name, DUMMY_SP); f.ident.insert(ident) } Some(i) => i, }; - let (_, register_action_expr) = - self.maybe_hoist_and_create_proxy(ident, Some(&mut f.function), None); + // Collect all the identifiers defined inside the closure and used + // in the action function. With deduplication. + retain_names_from_declared_idents(&mut child_names, ¤t_declared_idents); + + let maybe_new_expr = + self.maybe_hoist_and_create_proxy(child_names, Some(&mut f.function), None); - // Replace the original function expr with a action proxy expr. - self.rewrite_default_fn_expr_to_proxy_expr = register_action_expr; + if self.in_default_export_decl { + // This function expression is also the default export: + // `export default async function() {}` + // This specific case (default export) isn't handled by `visit_mut_expr`. + // Replace the original function expr with a action proxy expr. + self.rewrite_default_fn_expr_to_proxy_expr = maybe_new_expr; + } else { + self.rewrite_expr_to_proxy_expr = maybe_new_expr; + } } } @@ -523,28 +502,33 @@ impl VisitMut for ServerActions { fn visit_mut_fn_decl(&mut self, f: &mut FnDecl) { let is_action_fn = self.get_action_info(f.function.body.as_mut(), true); + let current_declared_idents = self.declared_idents.clone(); + let current_names = self.names.clone(); + self.names = vec![]; + { // Visit children let old_in_action_fn = self.in_action_fn; - let old_in_module = self.in_module; - let old_in_action_closure = self.in_action_closure; + let old_in_module = self.in_module_level; + let old_should_track_names = self.should_track_names; let old_in_export_decl = self.in_export_decl; let old_in_default_export_decl = self.in_default_export_decl; - let old_closure_idents = self.closure_idents.clone(); self.in_action_fn = is_action_fn; - self.in_module = false; - self.in_action_closure = true; + self.in_module_level = false; + self.should_track_names = true; self.in_export_decl = false; self.in_default_export_decl = false; f.visit_mut_children_with(self); self.in_action_fn = old_in_action_fn; - self.in_module = old_in_module; - self.in_action_closure = old_in_action_closure; + self.in_module_level = old_in_module; + self.should_track_names = old_should_track_names; self.in_export_decl = old_in_export_decl; self.in_default_export_decl = old_in_default_export_decl; - self.closure_idents = old_closure_idents; } + let mut child_names = self.names.clone(); + self.names.extend(current_names); + if !is_action_fn { return; } @@ -555,9 +539,15 @@ impl VisitMut for ServerActions { .struct_span_err(f.ident.span, "Server actions must be async functions") .emit(); }); - } else if !self.in_action_file { - let (_, register_action_expr) = - self.maybe_hoist_and_create_proxy(&f.ident, Some(&mut f.function), None); + } + + if !self.in_action_file { + // Collect all the identifiers defined inside the closure and used + // in the action function. With deduplication. + retain_names_from_declared_idents(&mut child_names, ¤t_declared_idents); + + let maybe_new_expr = + self.maybe_hoist_and_create_proxy(child_names, Some(&mut f.function), None); // Replace the original function declaration with a action proxy declaration // expr. @@ -568,7 +558,7 @@ impl VisitMut for ServerActions { decls: vec![VarDeclarator { span: DUMMY_SP, name: Pat::Ident(f.ident.clone().into()), - init: register_action_expr, + init: maybe_new_expr, definite: false, }], }); @@ -584,38 +574,41 @@ impl VisitMut for ServerActions { } else { None }, - false, + true, ); + let current_declared_idents = self.declared_idents.clone(); + let current_names = self.names.clone(); + self.names = vec![]; + { // Visit children let old_in_action_fn = self.in_action_fn; - let old_in_module = self.in_module; - let old_in_action_closure = self.in_action_closure; + let old_in_module = self.in_module_level; + let old_should_track_names = self.should_track_names; let old_in_export_decl = self.in_export_decl; let old_in_default_export_decl = self.in_default_export_decl; - let old_closure_idents = self.closure_idents.clone(); self.in_action_fn = is_action_fn; - self.in_module = false; - self.in_action_closure = true; + self.in_module_level = false; + self.should_track_names = true; self.in_export_decl = false; self.in_default_export_decl = false; { - if !self.in_action_fn && !self.in_action_file { - for n in &mut a.params { - collect_pat_idents(n, &mut self.closure_idents); - } + for n in &mut a.params { + collect_pat_idents(n, &mut self.declared_idents); } } a.visit_mut_children_with(self); self.in_action_fn = old_in_action_fn; - self.in_module = old_in_module; - self.in_action_closure = old_in_action_closure; + self.in_module_level = old_in_module; + self.should_track_names = old_should_track_names; self.in_export_decl = old_in_export_decl; self.in_default_export_decl = old_in_default_export_decl; - self.closure_idents = old_closure_idents; } + let mut child_names = self.names.clone(); + self.names.extend(current_names); + if !is_action_fn { return; } @@ -627,6 +620,13 @@ impl VisitMut for ServerActions { .emit(); }); } + + // Collect all the identifiers defined inside the closure and used + // in the action function. With deduplication. + retain_names_from_declared_idents(&mut child_names, ¤t_declared_idents); + + let maybe_new_expr = self.maybe_hoist_and_create_proxy(child_names, None, Some(a)); + self.rewrite_expr_to_proxy_expr = maybe_new_expr; } fn visit_mut_module(&mut self, m: &mut Module) { @@ -637,31 +637,32 @@ impl VisitMut for ServerActions { fn visit_mut_stmt(&mut self, n: &mut Stmt) { n.visit_mut_children_with(self); - if self.in_module { + if self.in_module_level { return; } - let ids = collect_idents_in_stmt(n); - if !self.in_action_fn && !self.in_action_file { - self.closure_idents.extend(ids); - } + // If it's a closure (not in the module level), we need to collect + // identifiers defined in the closure. + self.declared_idents.extend(collect_decl_idents_in_stmt(n)); } fn visit_mut_param(&mut self, n: &mut Param) { n.visit_mut_children_with(self); - if !self.in_action_fn && !self.in_action_file { - collect_pat_idents(&n.pat, &mut self.closure_idents); + if self.in_module_level { + return; } + + collect_pat_idents(&n.pat, &mut self.declared_idents); } fn visit_mut_prop_or_spread(&mut self, n: &mut PropOrSpread) { - if self.in_action_fn && self.in_action_closure { + if !self.in_module_level && self.should_track_names { if let PropOrSpread::Prop(box Prop::Shorthand(i)) = n { - self.in_action_closure = false; - self.action_closure_idents.push(Name::from(&*i)); + self.names.push(Name::from(&*i)); + self.should_track_names = false; n.visit_mut_children_with(self); - self.in_action_closure = true; + self.should_track_names = true; return; } } @@ -670,73 +671,21 @@ impl VisitMut for ServerActions { } fn visit_mut_expr(&mut self, n: &mut Expr) { - if self.in_action_fn && self.in_action_closure { + if !self.in_module_level && self.should_track_names { if let Ok(name) = Name::try_from(&*n) { - self.in_action_closure = false; - self.action_closure_idents.push(name); + self.names.push(name); + self.should_track_names = false; n.visit_mut_children_with(self); - self.in_action_closure = true; + self.should_track_names = true; return; } } + self.rewrite_expr_to_proxy_expr = None; n.visit_mut_children_with(self); - - if self.in_action_file { - return; - } - - match n { - Expr::Arrow(a) => { - let is_action_fn = self.get_action_info( - if let BlockStmtOrExpr::BlockStmt(block) = &mut *a.body { - Some(block) - } else { - None - }, - true, - ); - - if !is_action_fn { - return; - } - - // We need to give a name to the arrow function - // action and hoist it to the top. - let action_name = gen_ident(&mut self.ident_cnt); - let ident = private_ident!(action_name); - - let (maybe_new_expr, _) = self.maybe_hoist_and_create_proxy(&ident, None, Some(a)); - - *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); - - if !is_action_fn { - return; - } - let ident = match f.ident.as_mut() { - None => { - let action_name = gen_ident(&mut self.ident_cnt); - let ident = Ident::new(action_name, DUMMY_SP); - f.ident.insert(ident) - } - Some(i) => i, - }; - - let (maybe_new_expr, _) = - self.maybe_hoist_and_create_proxy(ident, Some(&mut f.function), None); - - if let Some(new_expr) = maybe_new_expr { - *n = *new_expr; - } - } - _ => {} + if let Some(expr) = &self.rewrite_expr_to_proxy_expr { + *n = (**expr).clone(); + self.rewrite_expr_to_proxy_expr = None; } } @@ -833,7 +782,7 @@ impl VisitMut for ServerActions { } else { // export default function() {} let new_ident = - Ident::new(gen_ident(&mut self.ident_cnt), DUMMY_SP); + Ident::new(gen_ident(&mut self.action_cnt), DUMMY_SP); f.ident = Some(new_ident.clone()); self.exported_idents .push((new_ident.to_id(), "default".into())); @@ -852,7 +801,7 @@ impl VisitMut for ServerActions { } else { // export default async () => {} let new_ident = - Ident::new(gen_ident(&mut self.ident_cnt), DUMMY_SP); + Ident::new(gen_ident(&mut self.action_cnt), DUMMY_SP); self.exported_idents .push((new_ident.to_id(), "default".into())); @@ -871,7 +820,7 @@ impl VisitMut for ServerActions { Expr::Call(call) => { // export default fn() let new_ident = - Ident::new(gen_ident(&mut self.ident_cnt), DUMMY_SP); + Ident::new(gen_ident(&mut self.action_cnt), DUMMY_SP); self.exported_idents .push((new_ident.to_id(), "default".into())); @@ -1150,10 +1099,6 @@ impl VisitMut for ServerActions { *stmts = new; - stmts.visit_mut_with(&mut ClosureActionReplacer { - replaced_action_proxies: &self.replaced_action_proxies, - }); - self.annotations = old_annotations; } @@ -1176,6 +1121,22 @@ impl VisitMut for ServerActions { noop_visit_mut_type!(); } +fn retain_names_from_declared_idents(child_names: &mut Vec, current_declared_idents: &[Id]) { + // Collect all the identifiers defined inside the closure and used + // in the action function. With deduplication. + let mut added_names = Vec::new(); + child_names.retain(|name| { + if added_names.contains(name) { + false + } else if current_declared_idents.contains(&name.0) { + added_names.push(name.clone()); + true + } else { + false + } + }); +} + fn gen_ident(cnt: &mut u32) -> JsWord { let id: JsWord = format!("$$ACTION_{}", cnt).into(); *cnt += 1; @@ -1574,7 +1535,7 @@ fn collect_idents_in_var_decls(decls: &[VarDeclarator]) -> Vec { ids } -fn collect_idents_in_stmt(stmt: &Stmt) -> Vec { +fn collect_decl_idents_in_stmt(stmt: &Stmt) -> Vec { let mut ids = Vec::new(); if let Stmt::Decl(Decl::Var(var)) = &stmt { @@ -1584,45 +1545,6 @@ 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/next-custom-transforms/tests/errors/server-actions/server-graph/6/output.js b/packages/next-swc/crates/next-custom-transforms/tests/errors/server-actions/server-graph/6/output.js index 1e748e173380f..0e36704ddd70f 100644 --- a/packages/next-swc/crates/next-custom-transforms/tests/errors/server-actions/server-graph/6/output.js +++ b/packages/next-swc/crates/next-custom-transforms/tests/errors/server-actions/server-graph/6/output.js @@ -1,5 +1,6 @@ /* __next_internal_action_entry_do_not_use__ {} */ import { createActionProxy } from "private-next-rsc-action-proxy"; import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption"; -export default (()=>{}); +export default createActionProxy("6d53ce510b2e36499b8f56038817b9bad86cabb4", $$ACTION_0); +export async function $$ACTION_0() {} import { ensureServerEntryExports } from "private-next-rsc-action-validate"; ensureServerEntryExports([]); diff --git a/packages/next-swc/crates/next-custom-transforms/tests/errors/server-actions/server-graph/7/output.js b/packages/next-swc/crates/next-custom-transforms/tests/errors/server-actions/server-graph/7/output.js index a20e6da44a5b2..8b7105a3190db 100644 --- a/packages/next-swc/crates/next-custom-transforms/tests/errors/server-actions/server-graph/7/output.js +++ b/packages/next-swc/crates/next-custom-transforms/tests/errors/server-actions/server-graph/7/output.js @@ -1,4 +1,4 @@ -/* __next_internal_action_entry_do_not_use__ {"188d5d945750dc32e2c842b93c75a65763d4a922":"$$ACTION_1"} */ import { createActionProxy } from "private-next-rsc-action-proxy"; +/* __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"; -const foo = createActionProxy("188d5d945750dc32e2c842b93c75a65763d4a922", $$ACTION_1); -export async function $$ACTION_1() {} +const foo = createActionProxy("6d53ce510b2e36499b8f56038817b9bad86cabb4", $$ACTION_0); +export async function $$ACTION_0() {} diff --git a/packages/next-swc/crates/next-custom-transforms/tests/errors/server-actions/server-graph/8/output.js b/packages/next-swc/crates/next-custom-transforms/tests/errors/server-actions/server-graph/8/output.js index 257ea035bb64a..ac8f4884a4ef1 100644 --- a/packages/next-swc/crates/next-custom-transforms/tests/errors/server-actions/server-graph/8/output.js +++ b/packages/next-swc/crates/next-custom-transforms/tests/errors/server-actions/server-graph/8/output.js @@ -1,7 +1,7 @@ -/* __next_internal_action_entry_do_not_use__ {"188d5d945750dc32e2c842b93c75a65763d4a922":"$$ACTION_1"} */ import { createActionProxy } from "private-next-rsc-action-proxy"; +/* __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"; -const foo = createActionProxy("188d5d945750dc32e2c842b93c75a65763d4a922", $$ACTION_1); -export async function $$ACTION_1() { +const foo = createActionProxy("6d53ce510b2e36499b8f56038817b9bad86cabb4", $$ACTION_0); +export async function $$ACTION_0() { 'use strict'; } const bar = async ()=>{ diff --git a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/1/output.js b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/1/output.js index 652a0e2eb6618..083fae9175ab1 100644 --- a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/1/output.js +++ b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/1/output.js @@ -1,4 +1,4 @@ -/* __next_internal_action_entry_do_not_use__ {"6d53ce510b2e36499b8f56038817b9bad86cabb4":"$$ACTION_0","9878bfa39811ca7650992850a8751f9591b6a557":"$$ACTION_2"} */ import { createActionProxy } from "private-next-rsc-action-proxy"; +/* __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 }) { @@ -6,10 +6,7 @@ export function Item({ id1, id2 }) { id1, id2 ])); - return ; + return ; } export async function $$ACTION_0($$ACTION_CLOSURE_BOUND) { var [$$ACTION_ARG_0, $$ACTION_ARG_1] = await decryptActionBoundArgs("6d53ce510b2e36499b8f56038817b9bad86cabb4", $$ACTION_CLOSURE_BOUND); @@ -21,14 +18,14 @@ export default function Home() { name: 'John', test: 'test' }; - const action = createActionProxy("9878bfa39811ca7650992850a8751f9591b6a557", $$ACTION_2).bind(null, encryptActionBoundArgs("9878bfa39811ca7650992850a8751f9591b6a557", [ + const action = createActionProxy("188d5d945750dc32e2c842b93c75a65763d4a922", $$ACTION_1).bind(null, encryptActionBoundArgs("188d5d945750dc32e2c842b93c75a65763d4a922", [ info.name, info.test ])); return null; } -export async function $$ACTION_2($$ACTION_CLOSURE_BOUND) { - var [$$ACTION_ARG_0, $$ACTION_ARG_1] = await decryptActionBoundArgs("9878bfa39811ca7650992850a8751f9591b6a557", $$ACTION_CLOSURE_BOUND); +export async function $$ACTION_1($$ACTION_CLOSURE_BOUND) { + var [$$ACTION_ARG_0, $$ACTION_ARG_1] = await decryptActionBoundArgs("188d5d945750dc32e2c842b93c75a65763d4a922", $$ACTION_CLOSURE_BOUND); console.log($$ACTION_ARG_0); console.log($$ACTION_ARG_1); } diff --git a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/15/output.js b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/15/output.js index 8aeb838a9c956..3d6f28013d537 100644 --- a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/15/output.js +++ b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/15/output.js @@ -1,9 +1,10 @@ /* __next_internal_action_entry_do_not_use__ {"c18c215a6b7cdc64bf709f3a714ffdef1bf9651d":"default"} */ import { createActionProxy } from "private-next-rsc-action-proxy"; import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption"; -export default $$ACTION_0 = async (a, b)=>{ - console.log(a, b); -}; +export default $$ACTION_0 = createActionProxy("188d5d945750dc32e2c842b93c75a65763d4a922", $$ACTION_1); var $$ACTION_0; +export async function $$ACTION_1(a, b) { + console.log(a, b); +} import { ensureServerEntryExports } from "private-next-rsc-action-validate"; ensureServerEntryExports([ $$ACTION_0 diff --git a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/16/output.js b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/16/output.js index 8e06a112553ff..2d6955320a27a 100644 --- a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/16/output.js +++ b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/16/output.js @@ -1,36 +1,36 @@ -/* __next_internal_action_entry_do_not_use__ {"188d5d945750dc32e2c842b93c75a65763d4a922":"$$ACTION_1","9878bfa39811ca7650992850a8751f9591b6a557":"$$ACTION_2","9c0dd1f7c2b3f41d32e10f5c437de3d67ad32c6c":"$$ACTION_4"} */ import { createActionProxy } from "private-next-rsc-action-proxy"; +/* __next_internal_action_entry_do_not_use__ {"188d5d945750dc32e2c842b93c75a65763d4a922":"$$ACTION_1","6d53ce510b2e36499b8f56038817b9bad86cabb4":"$$ACTION_0","9878bfa39811ca7650992850a8751f9591b6a557":"$$ACTION_2"} */ 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 = createActionProxy("188d5d945750dc32e2c842b93c75a65763d4a922", $$ACTION_1).bind(null, encryptActionBoundArgs("188d5d945750dc32e2c842b93c75a65763d4a922", [ + const deleteItem = createActionProxy("6d53ce510b2e36499b8f56038817b9bad86cabb4", $$ACTION_0).bind(null, encryptActionBoundArgs("6d53ce510b2e36499b8f56038817b9bad86cabb4", [ id1, v2 ])); return ; } -export async function $$ACTION_1($$ACTION_CLOSURE_BOUND) { - var [$$ACTION_ARG_0, $$ACTION_ARG_1] = await decryptActionBoundArgs("188d5d945750dc32e2c842b93c75a65763d4a922", $$ACTION_CLOSURE_BOUND); +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(v1); await deleteFromDb($$ACTION_ARG_1); } const f = (x)=>{ - var g = createActionProxy("9878bfa39811ca7650992850a8751f9591b6a557", $$ACTION_2).bind(null, encryptActionBoundArgs("9878bfa39811ca7650992850a8751f9591b6a557", [ + var g = createActionProxy("188d5d945750dc32e2c842b93c75a65763d4a922", $$ACTION_1).bind(null, encryptActionBoundArgs("188d5d945750dc32e2c842b93c75a65763d4a922", [ x ])); }; -export async function $$ACTION_2($$ACTION_CLOSURE_BOUND, y, ...z) { - var [$$ACTION_ARG_0] = await decryptActionBoundArgs("9878bfa39811ca7650992850a8751f9591b6a557", $$ACTION_CLOSURE_BOUND); +export async function $$ACTION_1($$ACTION_CLOSURE_BOUND, y, ...z) { + var [$$ACTION_ARG_0] = await decryptActionBoundArgs("188d5d945750dc32e2c842b93c75a65763d4a922", $$ACTION_CLOSURE_BOUND); return $$ACTION_ARG_0 + y + z[0]; } const g = (x)=>{ - f = createActionProxy("9c0dd1f7c2b3f41d32e10f5c437de3d67ad32c6c", $$ACTION_4).bind(null, encryptActionBoundArgs("9c0dd1f7c2b3f41d32e10f5c437de3d67ad32c6c", [ + f = createActionProxy("9878bfa39811ca7650992850a8751f9591b6a557", $$ACTION_2).bind(null, encryptActionBoundArgs("9878bfa39811ca7650992850a8751f9591b6a557", [ x ])); }; -export async function $$ACTION_4($$ACTION_CLOSURE_BOUND, y, ...z) { - var [$$ACTION_ARG_0] = await decryptActionBoundArgs("9c0dd1f7c2b3f41d32e10f5c437de3d67ad32c6c", $$ACTION_CLOSURE_BOUND); +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]; } diff --git a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/17/output.js b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/17/output.js index 655766407d050..6ed57d551917a 100644 --- a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/17/output.js +++ b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/17/output.js @@ -1,6 +1,7 @@ /* __next_internal_action_entry_do_not_use__ {"ab21efdafbe611287bc25c0462b1e0510d13e48b":"foo","ac840dcaf5e8197cb02b7f3a43c119b7a770b272":"bar"} */ import { createActionProxy } from "private-next-rsc-action-proxy"; import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption"; -export const foo = async ()=>{}; +export const foo = createActionProxy("6d53ce510b2e36499b8f56038817b9bad86cabb4", $$ACTION_0); +export async function $$ACTION_0() {} const bar = async ()=>{}; export { bar }; import { ensureServerEntryExports } from "private-next-rsc-action-validate"; diff --git a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/18/output.js b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/18/output.js index b4628bf98efd3..a05b92ee24856 100644 --- a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/18/output.js +++ b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/18/output.js @@ -1,4 +1,4 @@ -/* __next_internal_action_entry_do_not_use__ {"188d5d945750dc32e2c842b93c75a65763d4a922":"$$ACTION_1","56a859f462d35a297c46a1bbd1e6a9058c104ab8":"$$ACTION_3"} */ import { createActionProxy } from "private-next-rsc-action-proxy"; +/* __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"; import deleteFromDb from 'db'; const v1 = 'v1'; @@ -6,7 +6,7 @@ export function Item({ id1, id2 }) { const v2 = id2; return <> - - ; + return ; } -export const action = withValidate(createActionProxy("9878bfa39811ca7650992850a8751f9591b6a557", $$ACTION_2)); -export async function $$ACTION_2() {} +export const action = withValidate(createActionProxy("188d5d945750dc32e2c842b93c75a65763d4a922", $$ACTION_1)); +export async function $$ACTION_1() {} diff --git a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/21/output.js b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/21/output.js index 9962a9e0f8bfd..faea436604bdf 100644 --- a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/21/output.js +++ b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/21/output.js @@ -1,4 +1,4 @@ -/* __next_internal_action_entry_do_not_use__ {"1383664d1dc2d9cfe33b88df3fa0eaffef8b99bc":"$$ACTION_5","188d5d945750dc32e2c842b93c75a65763d4a922":"$$ACTION_1","56a859f462d35a297c46a1bbd1e6a9058c104ab8":"$$ACTION_3"} */ import { createActionProxy } from "private-next-rsc-action-proxy"; +/* __next_internal_action_entry_do_not_use__ {"188d5d945750dc32e2c842b93c75a65763d4a922":"$$ACTION_1","56a859f462d35a297c46a1bbd1e6a9058c104ab8":"$$ACTION_3","9878bfa39811ca7650992850a8751f9591b6a557":"$$ACTION_2"} */ 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; @@ -12,7 +12,7 @@ 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; } -validator(createActionProxy("56a859f462d35a297c46a1bbd1e6a9058c104ab8", $$ACTION_3)); +validator(createActionProxy("9878bfa39811ca7650992850a8751f9591b6a557", $$ACTION_2)); +export async function $$ACTION_2() {} +another(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/next-custom-transforms/tests/fixture/server-actions/server/22/output.js b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/22/output.js index 94f01484799aa..5d7eaff021748 100644 --- a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/22/output.js +++ b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/22/output.js @@ -1,13 +1,15 @@ /* __next_internal_action_entry_do_not_use__ {"c18c215a6b7cdc64bf709f3a714ffdef1bf9651d":"default","f14702b5a021dd117f7ec7a3c838f397c2046d3b":"action"} */ import { createActionProxy } from "private-next-rsc-action-proxy"; import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption"; import { validator } from 'auth'; -export const action = validator(async ()=>{}); -export default $$ACTION_0 = validator(async ()=>{}); -var $$ACTION_0; +export const action = validator(createActionProxy("6d53ce510b2e36499b8f56038817b9bad86cabb4", $$ACTION_0)); +export async function $$ACTION_0() {} +export default $$ACTION_1 = validator(createActionProxy("9878bfa39811ca7650992850a8751f9591b6a557", $$ACTION_2)); +var $$ACTION_1; +export async function $$ACTION_2() {} import { ensureServerEntryExports } from "private-next-rsc-action-validate"; ensureServerEntryExports([ action, - $$ACTION_0 + $$ACTION_1 ]); createActionProxy("f14702b5a021dd117f7ec7a3c838f397c2046d3b", action); -createActionProxy("c18c215a6b7cdc64bf709f3a714ffdef1bf9651d", $$ACTION_0); +createActionProxy("c18c215a6b7cdc64bf709f3a714ffdef1bf9651d", $$ACTION_1); diff --git a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/23/output.js b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/23/output.js index 13255f232d77e..4d8250f54d807 100644 --- a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/23/output.js +++ b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/23/output.js @@ -1,13 +1,11 @@ -/* __next_internal_action_entry_do_not_use__ {"6d53ce510b2e36499b8f56038817b9bad86cabb4":"$$ACTION_0","9878bfa39811ca7650992850a8751f9591b6a557":"$$ACTION_2"} */ import { createActionProxy } from "private-next-rsc-action-proxy"; +/* __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"; export default function Page({ foo, x, y }) { var action = createActionProxy("6d53ce510b2e36499b8f56038817b9bad86cabb4", $$ACTION_0).bind(null, encryptActionBoundArgs("6d53ce510b2e36499b8f56038817b9bad86cabb4", [ x ])); - 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", [ + action.bind(null, foo[0], foo[1], foo.x, foo[y]); + const action2 = createActionProxy("188d5d945750dc32e2c842b93c75a65763d4a922", $$ACTION_1).bind(null, encryptActionBoundArgs("188d5d945750dc32e2c842b93c75a65763d4a922", [ x ])); action2.bind(null, foo[0], foo[1], foo.x, foo[y]); @@ -16,7 +14,7 @@ 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 async function $$ACTION_2($$ACTION_CLOSURE_BOUND, a, b, c, d) { - var [$$ACTION_ARG_0] = await decryptActionBoundArgs("9878bfa39811ca7650992850a8751f9591b6a557", $$ACTION_CLOSURE_BOUND); +export async function $$ACTION_1($$ACTION_CLOSURE_BOUND, a, b, c, d) { + var [$$ACTION_ARG_0] = await decryptActionBoundArgs("188d5d945750dc32e2c842b93c75a65763d4a922", $$ACTION_CLOSURE_BOUND); console.log(a, b, $$ACTION_ARG_0, c, d); } diff --git a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/25/output.js b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/25/output.js index 11f8d4c4a28af..7bb149f668f25 100644 --- a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/25/output.js +++ b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/25/output.js @@ -5,10 +5,7 @@ export function Item({ id1, id2 }) { id1++; return (()=>{ id1++; - return ; + return ; })(); var deleteItem = createActionProxy("6d53ce510b2e36499b8f56038817b9bad86cabb4", $$ACTION_0).bind(null, encryptActionBoundArgs("6d53ce510b2e36499b8f56038817b9bad86cabb4", [ id1, @@ -25,15 +22,9 @@ export async function $$ACTION_0($$ACTION_CLOSURE_BOUND) { export function Item2({ id1, id2 }) { id1++; const temp = []; - temp.push(); + temp.push(); id1++; - temp.push(); + temp.push(); return temp; var deleteItem = createActionProxy("188d5d945750dc32e2c842b93c75a65763d4a922", $$ACTION_1).bind(null, encryptActionBoundArgs("188d5d945750dc32e2c842b93c75a65763d4a922", [ id1, diff --git a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/26/output.js b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/26/output.js index 7b59b9896387e..0ac1137e64668 100644 --- a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/26/output.js +++ b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/26/output.js @@ -1,7 +1,7 @@ -/* __next_internal_action_entry_do_not_use__ {"188d5d945750dc32e2c842b93c75a65763d4a922":"$$ACTION_1"} */ import { createActionProxy } from "private-next-rsc-action-proxy"; +/* __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"; const noop = (action)=>action; -export const log = noop(createActionProxy("188d5d945750dc32e2c842b93c75a65763d4a922", $$ACTION_1)); -export async function $$ACTION_1(data) { +export const log = noop(createActionProxy("6d53ce510b2e36499b8f56038817b9bad86cabb4", $$ACTION_0)); +export async function $$ACTION_0(data) { console.log(data); } diff --git a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/27/output.js b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/27/output.js index 59bdfa4eb8f4e..86065e1d8551e 100644 --- a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/27/output.js +++ b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/27/output.js @@ -1,7 +1,7 @@ // Rules here: // 1. Each exported function should still be exported, but as a reference `createActionProxy(...)`. // 2. Actual action functions should be renamed to `$$ACTION_...` and got exported. -/* __next_internal_action_entry_do_not_use__ {"1383664d1dc2d9cfe33b88df3fa0eaffef8b99bc":"$$ACTION_5","188d5d945750dc32e2c842b93c75a65763d4a922":"$$ACTION_1","6d53ce510b2e36499b8f56038817b9bad86cabb4":"$$ACTION_0","9878bfa39811ca7650992850a8751f9591b6a557":"$$ACTION_2","9c0dd1f7c2b3f41d32e10f5c437de3d67ad32c6c":"$$ACTION_4"} */ import { createActionProxy } from "private-next-rsc-action-proxy"; +/* __next_internal_action_entry_do_not_use__ {"188d5d945750dc32e2c842b93c75a65763d4a922":"$$ACTION_1","56a859f462d35a297c46a1bbd1e6a9058c104ab8":"$$ACTION_3","6d53ce510b2e36499b8f56038817b9bad86cabb4":"$$ACTION_0","9878bfa39811ca7650992850a8751f9591b6a557":"$$ACTION_2","9c0dd1f7c2b3f41d32e10f5c437de3d67ad32c6c":"$$ACTION_4"} */ import { createActionProxy } from "private-next-rsc-action-proxy"; import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption"; var foo = createActionProxy("6d53ce510b2e36499b8f56038817b9bad86cabb4", $$ACTION_0); export async function $$ACTION_0() { @@ -14,14 +14,13 @@ export async function $$ACTION_1() { } export default createActionProxy("9878bfa39811ca7650992850a8751f9591b6a557", $$ACTION_2); export async function $$ACTION_2() { - 'use server'; console.log(3); } -export const qux = createActionProxy("9c0dd1f7c2b3f41d32e10f5c437de3d67ad32c6c", $$ACTION_4); -export async function $$ACTION_4() { +export const qux = createActionProxy("56a859f462d35a297c46a1bbd1e6a9058c104ab8", $$ACTION_3); +export async function $$ACTION_3() { console.log(4); } -export const quux = createActionProxy("1383664d1dc2d9cfe33b88df3fa0eaffef8b99bc", $$ACTION_5); -export async function $$ACTION_5() { +export const quux = createActionProxy("9c0dd1f7c2b3f41d32e10f5c437de3d67ad32c6c", $$ACTION_4); +export async function $$ACTION_4() { console.log(5); } diff --git a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/28/input.js b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/28/input.js new file mode 100644 index 0000000000000..e1dc32d14c1cd --- /dev/null +++ b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/28/input.js @@ -0,0 +1,24 @@ +let a, f + +function Comp(b, c, ...g) { + return async function action1(d) { + 'use server' + let f + console.log(...window, { window }) + console.log(a, b, action2) + + async function action2(e) { + 'use server' + console.log(a, c, d, e, f, g) + } + + return [ + action2, + async function action3(e) { + 'use server' + action2(e) + console.log(a, c, d, e) + }, + ] + } +} diff --git a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/28/output.js b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/28/output.js new file mode 100644 index 0000000000000..4287ca9b2e77e --- /dev/null +++ b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/28/output.js @@ -0,0 +1,41 @@ +/* __next_internal_action_entry_do_not_use__ {"188d5d945750dc32e2c842b93c75a65763d4a922":"$$ACTION_1","6d53ce510b2e36499b8f56038817b9bad86cabb4":"$$ACTION_0","9878bfa39811ca7650992850a8751f9591b6a557":"$$ACTION_2"} */ import { createActionProxy } from "private-next-rsc-action-proxy"; +import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption"; +let a, f; +function Comp(b, c, ...g) { + return createActionProxy("9878bfa39811ca7650992850a8751f9591b6a557", $$ACTION_2).bind(null, encryptActionBoundArgs("9878bfa39811ca7650992850a8751f9591b6a557", [ + c, + g, + b + ])); +} +export async function $$ACTION_0($$ACTION_CLOSURE_BOUND, e) { + var [$$ACTION_ARG_0, $$ACTION_ARG_1, $$ACTION_ARG_2, $$ACTION_ARG_3] = await decryptActionBoundArgs("6d53ce510b2e36499b8f56038817b9bad86cabb4", $$ACTION_CLOSURE_BOUND); + console.log(a, $$ACTION_ARG_0, $$ACTION_ARG_1, e, $$ACTION_ARG_2, $$ACTION_ARG_3); +} +export async function $$ACTION_1($$ACTION_CLOSURE_BOUND, e) { + var [$$ACTION_ARG_0, $$ACTION_ARG_1, $$ACTION_ARG_2] = await decryptActionBoundArgs("188d5d945750dc32e2c842b93c75a65763d4a922", $$ACTION_CLOSURE_BOUND); + $$ACTION_ARG_0(e); + console.log(a, $$ACTION_ARG_1, $$ACTION_ARG_2, e); +} +export async function $$ACTION_2($$ACTION_CLOSURE_BOUND, d) { + var [$$ACTION_ARG_0, $$ACTION_ARG_1, $$ACTION_ARG_2] = await decryptActionBoundArgs("9878bfa39811ca7650992850a8751f9591b6a557", $$ACTION_CLOSURE_BOUND); + let f; + console.log(...window, { + window + }); + console.log(a, $$ACTION_ARG_2, action2); + var action2 = createActionProxy("6d53ce510b2e36499b8f56038817b9bad86cabb4", $$ACTION_0).bind(null, encryptActionBoundArgs("6d53ce510b2e36499b8f56038817b9bad86cabb4", [ + $$ACTION_ARG_0, + d, + f, + $$ACTION_ARG_1 + ])); + return [ + action2, + createActionProxy("188d5d945750dc32e2c842b93c75a65763d4a922", $$ACTION_1).bind(null, encryptActionBoundArgs("188d5d945750dc32e2c842b93c75a65763d4a922", [ + action2, + $$ACTION_ARG_0, + d + ])) + ]; +} \ No newline at end of file diff --git a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/5/output.js b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/5/output.js index dc9ad009a8a90..b2b5eb3c9352c 100644 --- a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/5/output.js +++ b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/5/output.js @@ -10,12 +10,7 @@ export function Item({ id1, id2, id3, id4 }) { id3, id4.x ])); - return ; + 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/next-custom-transforms/tests/fixture/server-actions/server/6/output.js b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/6/output.js index f352df45615e0..488d0c2c7c2fa 100644 --- a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/6/output.js +++ b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/6/output.js @@ -27,14 +27,7 @@ export function y(p, [p1, { p2 }], ...p3) { p2, p3 ])); - return ; + 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/next-custom-transforms/tests/fixture/server-actions/server/7/output.js b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/7/output.js index 4146e4430e7ab..c4bb17515a058 100644 --- a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/7/output.js +++ b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/7/output.js @@ -1,4 +1,4 @@ -/* __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"; +/* __next_internal_action_entry_do_not_use__ {"188d5d945750dc32e2c842b93c75a65763d4a922":"$$ACTION_1","56a859f462d35a297c46a1bbd1e6a9058c104ab8":"$$ACTION_3","6d53ce510b2e36499b8f56038817b9bad86cabb4":"$$ACTION_0","9c0dd1f7c2b3f41d32e10f5c437de3d67ad32c6c":"$$ACTION_4"} */ import { createActionProxy } from "private-next-rsc-action-proxy"; import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption"; import deleteFromDb from 'db'; export function Item1(product, foo, bar) { @@ -25,14 +25,7 @@ export function Item2(product, foo, bar) { foo, bar ])); - return ; + 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); @@ -54,7 +47,7 @@ export async function $$ACTION_3($$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", [ + const deleteItem4 = createActionProxy("9c0dd1f7c2b3f41d32e10f5c437de3d67ad32c6c", $$ACTION_4).bind(null, encryptActionBoundArgs("9c0dd1f7c2b3f41d32e10f5c437de3d67ad32c6c", [ product.id, product?.foo, product.bar.baz, @@ -64,7 +57,7 @@ export function Item4(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); +export async function $$ACTION_4($$ACTION_CLOSURE_BOUND) { + var [$$ACTION_ARG_0, $$ACTION_ARG_1, $$ACTION_ARG_2, $$ACTION_ARG_3, $$ACTION_ARG_4, $$ACTION_ARG_5] = await decryptActionBoundArgs("9c0dd1f7c2b3f41d32e10f5c437de3d67ad32c6c", $$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/next-custom-transforms/tests/fixture/server-actions/server/8/output.js b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/8/output.js index 99ec52535dd38..20cd837d2f823 100644 --- a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/8/output.js +++ b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/8/output.js @@ -7,5 +7,5 @@ export async function $$ACTION_0(a, b, c) { console.log('a'); } export default function Page() { - return ; + return ; } From ef81b1099856bc7918dfa39e6d272cce53451eaf Mon Sep 17 00:00:00 2001 From: Shu Ding Date: Sat, 27 Jan 2024 05:15:24 -0800 Subject: [PATCH 02/10] Fix Server Reference being double registered (#61244) When we apply `createActionProxy` twice to the same value, it currently errors because we can't override the ID of it. This PR makes sure that 1) when the value already have an ID defined, we skip setting it again; 2) all the action IDs are being tracked even for duplicated ones. Note that it's technically impossible to "detect" the duplication here (via static analyzation) and only set it once. For example: ```ts 'use server' export async function foo () {} export const bar = a_value_we_dont_know_yet ? foo : async () => {} ``` So, the compiler will always wrap `createActionProxy` for every exported value and assume they're different Server Actions (hence different IDs). With this fix, if we find that it's already defined before, we just return the defined reference as they're strictly identical so the ID does't matter. Closes #54655, closes #61183. Closes NEXT-2264 --- .../src/transforms/server_actions.rs | 8 ++++---- .../server-actions/server-graph/6/output.js | 2 +- .../fixture/server-actions/server/15/output.js | 2 +- .../fixture/server-actions/server/17/output.js | 2 +- .../fixture/server-actions/server/22/output.js | 2 +- .../fixture/server-actions/server/29/input.js | 8 ++++++++ .../fixture/server-actions/server/29/output.js | 15 +++++++++++++++ .../loaders/next-flight-loader/action-proxy.ts | 11 +++++++++++ test/e2e/app-dir/actions/app/server/actions.js | 8 +++++++- 9 files changed, 49 insertions(+), 9 deletions(-) create mode 100644 packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/29/input.js create mode 100644 packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/29/output.js diff --git a/packages/next-swc/crates/next-custom-transforms/src/transforms/server_actions.rs b/packages/next-swc/crates/next-custom-transforms/src/transforms/server_actions.rs index 56ceb657b0f3f..41bacc208c6eb 100644 --- a/packages/next-swc/crates/next-custom-transforms/src/transforms/server_actions.rs +++ b/packages/next-swc/crates/next-custom-transforms/src/transforms/server_actions.rs @@ -1021,11 +1021,11 @@ impl VisitMut for ServerActions { } if self.has_action { - let actions = if self.in_action_file { - self.exported_idents.iter().map(|e| e.1.clone()).collect() - } else { - self.export_actions.clone() + let mut actions = self.export_actions.clone(); + if self.in_action_file { + actions.extend(self.exported_idents.iter().map(|e| e.1.clone())); }; + let actions = actions .into_iter() .map(|name| (generate_action_id(&self.file_name, &name), name)) diff --git a/packages/next-swc/crates/next-custom-transforms/tests/errors/server-actions/server-graph/6/output.js b/packages/next-swc/crates/next-custom-transforms/tests/errors/server-actions/server-graph/6/output.js index 0e36704ddd70f..3b12261603df4 100644 --- a/packages/next-swc/crates/next-custom-transforms/tests/errors/server-actions/server-graph/6/output.js +++ b/packages/next-swc/crates/next-custom-transforms/tests/errors/server-actions/server-graph/6/output.js @@ -1,4 +1,4 @@ -/* __next_internal_action_entry_do_not_use__ {} */ import { createActionProxy } from "private-next-rsc-action-proxy"; +/* __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 createActionProxy("6d53ce510b2e36499b8f56038817b9bad86cabb4", $$ACTION_0); export async function $$ACTION_0() {} diff --git a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/15/output.js b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/15/output.js index 3d6f28013d537..6f9c9865c243e 100644 --- a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/15/output.js +++ b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/15/output.js @@ -1,4 +1,4 @@ -/* __next_internal_action_entry_do_not_use__ {"c18c215a6b7cdc64bf709f3a714ffdef1bf9651d":"default"} */ import { createActionProxy } from "private-next-rsc-action-proxy"; +/* __next_internal_action_entry_do_not_use__ {"188d5d945750dc32e2c842b93c75a65763d4a922":"$$ACTION_1","c18c215a6b7cdc64bf709f3a714ffdef1bf9651d":"default"} */ import { createActionProxy } from "private-next-rsc-action-proxy"; import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption"; export default $$ACTION_0 = createActionProxy("188d5d945750dc32e2c842b93c75a65763d4a922", $$ACTION_1); var $$ACTION_0; diff --git a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/17/output.js b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/17/output.js index 6ed57d551917a..740fbdfab43fd 100644 --- a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/17/output.js +++ b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/17/output.js @@ -1,4 +1,4 @@ -/* __next_internal_action_entry_do_not_use__ {"ab21efdafbe611287bc25c0462b1e0510d13e48b":"foo","ac840dcaf5e8197cb02b7f3a43c119b7a770b272":"bar"} */ import { createActionProxy } from "private-next-rsc-action-proxy"; +/* __next_internal_action_entry_do_not_use__ {"6d53ce510b2e36499b8f56038817b9bad86cabb4":"$$ACTION_0","ab21efdafbe611287bc25c0462b1e0510d13e48b":"foo","ac840dcaf5e8197cb02b7f3a43c119b7a770b272":"bar"} */ import { createActionProxy } from "private-next-rsc-action-proxy"; import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption"; export const foo = createActionProxy("6d53ce510b2e36499b8f56038817b9bad86cabb4", $$ACTION_0); export async function $$ACTION_0() {} diff --git a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/22/output.js b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/22/output.js index 5d7eaff021748..084fe21f6f201 100644 --- a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/22/output.js +++ b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/22/output.js @@ -1,4 +1,4 @@ -/* __next_internal_action_entry_do_not_use__ {"c18c215a6b7cdc64bf709f3a714ffdef1bf9651d":"default","f14702b5a021dd117f7ec7a3c838f397c2046d3b":"action"} */ import { createActionProxy } from "private-next-rsc-action-proxy"; +/* __next_internal_action_entry_do_not_use__ {"6d53ce510b2e36499b8f56038817b9bad86cabb4":"$$ACTION_0","9878bfa39811ca7650992850a8751f9591b6a557":"$$ACTION_2","c18c215a6b7cdc64bf709f3a714ffdef1bf9651d":"default","f14702b5a021dd117f7ec7a3c838f397c2046d3b":"action"} */ import { createActionProxy } from "private-next-rsc-action-proxy"; import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption"; import { validator } from 'auth'; export const action = validator(createActionProxy("6d53ce510b2e36499b8f56038817b9bad86cabb4", $$ACTION_0)); diff --git a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/29/input.js b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/29/input.js new file mode 100644 index 0000000000000..42024ee44afbe --- /dev/null +++ b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/29/input.js @@ -0,0 +1,8 @@ +'use server' + +export const dec = async (value) => { + return value - 1 +} + +// Test case for https://github.com/vercel/next.js/issues/54655 +export default dec diff --git a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/29/output.js b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/29/output.js new file mode 100644 index 0000000000000..4addc633d84a5 --- /dev/null +++ b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/29/output.js @@ -0,0 +1,15 @@ +/* __next_internal_action_entry_do_not_use__ {"28baf972d345b86b747ad0df73d75a0088a42214":"dec","6d53ce510b2e36499b8f56038817b9bad86cabb4":"$$ACTION_0","c18c215a6b7cdc64bf709f3a714ffdef1bf9651d":"default"} */ import { createActionProxy } from "private-next-rsc-action-proxy"; +import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption"; +export const dec = createActionProxy("6d53ce510b2e36499b8f56038817b9bad86cabb4", $$ACTION_0); +export async function $$ACTION_0(value) { + return value - 1; +} +// Test case for https://github.com/vercel/next.js/issues/54655 +export default dec; +import { ensureServerEntryExports } from "private-next-rsc-action-validate"; +ensureServerEntryExports([ + dec, + dec +]); +createActionProxy("28baf972d345b86b747ad0df73d75a0088a42214", dec); +createActionProxy("c18c215a6b7cdc64bf709f3a714ffdef1bf9651d", dec); \ No newline at end of file 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 0975e2fcc7080..9e442cfa4effc 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,6 +1,17 @@ /* eslint-disable import/no-extraneous-dependencies */ import { registerServerReference } from 'react-server-dom-webpack/server.edge' +const SERVER_REFERENCE_TAG = Symbol.for('react.server.reference') + +function isServerReference(reference: any) { + return reference && reference.$$typeof === SERVER_REFERENCE_TAG +} + export function createActionProxy(id: string, action: any) { + // Avoid registering the same action twice + if (isServerReference(action)) { + return action + } + return registerServerReference(action, id, null) } diff --git a/test/e2e/app-dir/actions/app/server/actions.js b/test/e2e/app-dir/actions/app/server/actions.js index f6f54112a944d..4b350ab41eebd 100644 --- a/test/e2e/app-dir/actions/app/server/actions.js +++ b/test/e2e/app-dir/actions/app/server/actions.js @@ -7,10 +7,13 @@ export async function slowInc(value) { return value + 1 } -export default async function dec(value) { +export const dec = async (value) => { return value - 1 } +// Test case for https://github.com/vercel/next.js/issues/54655 +export default dec + export async function redirectAction(formData) { 'use server' redirect( @@ -20,3 +23,6 @@ export async function redirectAction(formData) { formData.get('hidden-info') ) } + +// Test case for https://github.com/vercel/next.js/issues/61183 +export const dummyServerAction = () => new Promise((r) => setTimeout(r, 2000)) From 6e59c222a84f48edfc958d3327eb5448431e7784 Mon Sep 17 00:00:00 2001 From: Shu Ding Date: Thu, 15 Feb 2024 23:41:52 +0100 Subject: [PATCH 03/10] Improve the Server Actions SWC transform (part 2) (#62052) This fills the last piece in the puzzle and it's based on #61001. In "use server" file. And this PR extends that to a "use server" file so exported values are automatically handled just like before, but any other definitions including nested ones will be hoisted and marked correctly now. ```ts 'use server' let a, f export async function action0(b, c, ...g) { // <- Handled like before. return async function action1(d) { // <- Renamed, marked and hoisted. 'use server' let f console.log(...window, { window }) console.log(a, b, action2) async function action2(e) { // <- Renamed, marked and hoisted. 'use server' console.log(a, c, d, e, f, g) } return [ action2, async function action3(e) { // <- Renamed, marked and hoisted. 'use server' action2(e) console.log(a, c, d, e) }, ] } } ``` Closes NEXT-2491 --- .../src/transforms/server_actions.rs | 9 ++-- .../fixture/server-actions/client/5/input.js | 26 +++++++++++ .../fixture/server-actions/client/5/output.js | 2 + .../fixture/server-actions/server/30/input.js | 26 +++++++++++ .../server-actions/server/30/output.js | 46 +++++++++++++++++++ .../fixture/server-actions/server/4/output.js | 11 +++-- 6 files changed, 112 insertions(+), 8 deletions(-) create mode 100644 packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/client/5/input.js create mode 100644 packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/client/5/output.js create mode 100644 packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/30/input.js create mode 100644 packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/30/output.js diff --git a/packages/next-swc/crates/next-custom-transforms/src/transforms/server_actions.rs b/packages/next-swc/crates/next-custom-transforms/src/transforms/server_actions.rs index 41bacc208c6eb..20a684b35414c 100644 --- a/packages/next-swc/crates/next-custom-transforms/src/transforms/server_actions.rs +++ b/packages/next-swc/crates/next-custom-transforms/src/transforms/server_actions.rs @@ -132,7 +132,7 @@ impl ServerActions { self.config.enabled, ); - if is_action_fn && !self.config.is_react_server_layer { + if is_action_fn && !self.config.is_react_server_layer && !self.in_action_file { HANDLER.with(|handler| { handler .struct_span_err( @@ -459,7 +459,8 @@ impl VisitMut for ServerActions { }); } - if !self.in_action_file { + if !(self.in_action_file && self.in_export_decl) { + // It's an action function. If it doesn't have a name, give it one. match f.ident.as_mut() { None => { let action_name = gen_ident(&mut self.action_cnt); @@ -541,7 +542,7 @@ impl VisitMut for ServerActions { }); } - if !self.in_action_file { + if !(self.in_action_file && self.in_export_decl) { // Collect all the identifiers defined inside the closure and used // in the action function. With deduplication. retain_names_from_declared_idents(&mut child_names, ¤t_declared_idents); @@ -1022,6 +1023,8 @@ impl VisitMut for ServerActions { if self.has_action { let mut actions = self.export_actions.clone(); + + // All exported values are considered as actions if the file is an action file. if self.in_action_file { actions.extend(self.exported_idents.iter().map(|e| e.1.clone())); }; diff --git a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/client/5/input.js b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/client/5/input.js new file mode 100644 index 0000000000000..e1b3b4b5162e1 --- /dev/null +++ b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/client/5/input.js @@ -0,0 +1,26 @@ +'use server' + +let a, f + +export async function action0(b, c, ...g) { + return async function action1(d) { + 'use server' + let f + console.log(...window, { window }) + console.log(a, b, action2) + + async function action2(e) { + 'use server' + console.log(a, c, d, e, f, g) + } + + return [ + action2, + async function action3(e) { + 'use server' + action2(e) + console.log(a, c, d, e) + }, + ] + } +} diff --git a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/client/5/output.js b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/client/5/output.js new file mode 100644 index 0000000000000..9ec2f8eb26a0b --- /dev/null +++ b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/client/5/output.js @@ -0,0 +1,2 @@ +/* __next_internal_action_entry_do_not_use__ {"0090eaf4e1f08a2d94f6be401e54a2ded399b87c":"action0","188d5d945750dc32e2c842b93c75a65763d4a922":"$$ACTION_1","6d53ce510b2e36499b8f56038817b9bad86cabb4":"$$ACTION_0","9878bfa39811ca7650992850a8751f9591b6a557":"$$ACTION_2"} */ export var action0 = createServerReference("0090eaf4e1f08a2d94f6be401e54a2ded399b87c"); +import { createServerReference } from "private-next-rsc-action-client-wrapper"; diff --git a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/30/input.js b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/30/input.js new file mode 100644 index 0000000000000..e1b3b4b5162e1 --- /dev/null +++ b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/30/input.js @@ -0,0 +1,26 @@ +'use server' + +let a, f + +export async function action0(b, c, ...g) { + return async function action1(d) { + 'use server' + let f + console.log(...window, { window }) + console.log(a, b, action2) + + async function action2(e) { + 'use server' + console.log(a, c, d, e, f, g) + } + + return [ + action2, + async function action3(e) { + 'use server' + action2(e) + console.log(a, c, d, e) + }, + ] + } +} diff --git a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/30/output.js b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/30/output.js new file mode 100644 index 0000000000000..1a04f8c57eca6 --- /dev/null +++ b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/30/output.js @@ -0,0 +1,46 @@ +/* __next_internal_action_entry_do_not_use__ {"0090eaf4e1f08a2d94f6be401e54a2ded399b87c":"action0","188d5d945750dc32e2c842b93c75a65763d4a922":"$$ACTION_1","6d53ce510b2e36499b8f56038817b9bad86cabb4":"$$ACTION_0","9878bfa39811ca7650992850a8751f9591b6a557":"$$ACTION_2"} */ import { registerServerReference } from "private-next-rsc-server-reference"; +import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption"; +let a, f; +export async function action0(b, c, ...g) { + return registerServerReference("9878bfa39811ca7650992850a8751f9591b6a557", $$ACTION_2).bind(null, encryptActionBoundArgs("9878bfa39811ca7650992850a8751f9591b6a557", [ + c, + g, + b + ])); +} +export async function $$ACTION_0($$ACTION_CLOSURE_BOUND, e) { + var [$$ACTION_ARG_0, $$ACTION_ARG_1, $$ACTION_ARG_2, $$ACTION_ARG_3] = await decryptActionBoundArgs("6d53ce510b2e36499b8f56038817b9bad86cabb4", $$ACTION_CLOSURE_BOUND); + console.log(a, $$ACTION_ARG_0, $$ACTION_ARG_1, e, $$ACTION_ARG_2, $$ACTION_ARG_3); +} +export async function $$ACTION_1($$ACTION_CLOSURE_BOUND, e) { + var [$$ACTION_ARG_0, $$ACTION_ARG_1, $$ACTION_ARG_2] = await decryptActionBoundArgs("188d5d945750dc32e2c842b93c75a65763d4a922", $$ACTION_CLOSURE_BOUND); + $$ACTION_ARG_0(e); + console.log(a, $$ACTION_ARG_1, $$ACTION_ARG_2, e); +} +export async function $$ACTION_2($$ACTION_CLOSURE_BOUND, d) { + var [$$ACTION_ARG_0, $$ACTION_ARG_1, $$ACTION_ARG_2] = await decryptActionBoundArgs("9878bfa39811ca7650992850a8751f9591b6a557", $$ACTION_CLOSURE_BOUND); + let f; + console.log(...window, { + window + }); + console.log(a, $$ACTION_ARG_2, action2); + var action2 = registerServerReference("6d53ce510b2e36499b8f56038817b9bad86cabb4", $$ACTION_0).bind(null, encryptActionBoundArgs("6d53ce510b2e36499b8f56038817b9bad86cabb4", [ + $$ACTION_ARG_0, + d, + f, + $$ACTION_ARG_1 + ])); + return [ + action2, + registerServerReference("188d5d945750dc32e2c842b93c75a65763d4a922", $$ACTION_1).bind(null, encryptActionBoundArgs("188d5d945750dc32e2c842b93c75a65763d4a922", [ + action2, + $$ACTION_ARG_0, + d + ])) + ]; +} +import { ensureServerEntryExports } from "private-next-rsc-action-validate"; +ensureServerEntryExports([ + action0 +]); +registerServerReference("0090eaf4e1f08a2d94f6be401e54a2ded399b87c", action0); diff --git a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/4/output.js b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/4/output.js index 06a5bfa7ac9a6..28bb526dc3754 100644 --- a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/4/output.js +++ b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/4/output.js @@ -1,18 +1,19 @@ -/* __next_internal_action_entry_do_not_use__ {"1ab723c80dcca470e0410b4b2a2fc2bf21f41476":"c","6e7bc104e4d6e7fda190c4a51be969cfd0be6d6d":"a","d1f7eb64271d7c601dfef7d4d7053de1c2ca4338":"b"} */ import { createActionProxy } from "private-next-rsc-action-proxy"; +/* __next_internal_action_entry_do_not_use__ {"1ab723c80dcca470e0410b4b2a2fc2bf21f41476":"c","6d53ce510b2e36499b8f56038817b9bad86cabb4":"$$ACTION_0","6e7bc104e4d6e7fda190c4a51be969cfd0be6d6d":"a","d1f7eb64271d7c601dfef7d4d7053de1c2ca4338":"b"} */ import { registerServerReference } from "private-next-rsc-server-reference"; import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption"; export async function a() {} export async function b() {} export async function c() {} function d() {} function Foo() { - async function e() {} + var e = registerServerReference("6d53ce510b2e36499b8f56038817b9bad86cabb4", $$ACTION_0); } +export async function $$ACTION_0() {} import { ensureServerEntryExports } from "private-next-rsc-action-validate"; ensureServerEntryExports([ a, b, c ]); -createActionProxy("6e7bc104e4d6e7fda190c4a51be969cfd0be6d6d", a); -createActionProxy("d1f7eb64271d7c601dfef7d4d7053de1c2ca4338", b); -createActionProxy("1ab723c80dcca470e0410b4b2a2fc2bf21f41476", c); +registerServerReference("6e7bc104e4d6e7fda190c4a51be969cfd0be6d6d", a); +registerServerReference("d1f7eb64271d7c601dfef7d4d7053de1c2ca4338", b); +registerServerReference("1ab723c80dcca470e0410b4b2a2fc2bf21f41476", c); \ No newline at end of file From 51c6a07ec6a373eca3425ef565a53f4105112099 Mon Sep 17 00:00:00 2001 From: Shu Ding Date: Fri, 23 Feb 2024 12:00:24 +0100 Subject: [PATCH 04/10] Fix module-level Server Action creation with closure-closed values (#62437) With Server Actions, a module-level encryption can happen when you do: ```js function wrapAction(value) { return async function () { 'use server' console.log(value) } } const action = wrapAction('some-module-level-encryption-value') ``` ...as that action will be created when requiring this module, and it contains an encrypted argument from its closure (`value`). This currently throws an error during build: ``` Error: Missing manifest for Server Actions. This is a bug in Next.js at d (/Users/shu/Documents/git/next.js/test/e2e/app-dir/actions/.next/server/chunks/1772.js:1:15202) at f (/Users/shu/Documents/git/next.js/test/e2e/app-dir/actions/.next/server/chunks/1772.js:1:16917) at 714 (/Users/shu/Documents/git/next.js/test/e2e/app-dir/actions/.next/server/app/encryption/page.js:1:2806) at t (/Users/shu/Documents/git/next.js/test/e2e/app-dir/actions/.next/server/webpack-runtime.js:1:127) at 7940 (/Users/shu/Documents/git/next.js/test/e2e/app-dir/actions/.next/server/app/encryption/page.js:1:941) at t (/Users/shu/Documents/git/next.js/test/e2e/app-dir/actions/.next/server/webpack-runtime.js:1:127) at r (/Users/shu/Documents/git/next.js/test/e2e/app-dir/actions/.next/server/app/encryption/page.js:1:4529) at /Users/shu/Documents/git/next.js/test/e2e/app-dir/actions/.next/server/app/encryption/page.js:1:4572 at t.X (/Users/shu/Documents/git/next.js/test/e2e/app-dir/actions/.next/server/webpack-runtime.js:1:1181) at /Users/shu/Documents/git/next.js/test/e2e/app-dir/actions/.next/server/app/encryption/page.js:1:4542 ``` Because during module require phase, the encryption logic can't run as it doesn't have Server/Client references available yet (which are set during the rendering phase). Since both references are global singletons to the server and are already loaded early, this fix makes sure that they're registered via `setReferenceManifestsSingleton` before requiring the module. Closes NEXT-2579 --- .../next/src/build/templates/edge-ssr-app.ts | 13 ++++++++ .../src/server/app-render/action-utils.ts | 28 +++++++++++++++++ .../next/src/server/app-render/app-render.tsx | 26 ++++------------ packages/next/src/server/load-components.ts | 30 +++++++++++++++---- test/e2e/app-dir/actions/app-action.test.ts | 1 + .../app-dir/actions/app/encryption/page.js | 12 ++++++++ 6 files changed, 84 insertions(+), 26 deletions(-) create mode 100644 packages/next/src/server/app-render/action-utils.ts diff --git a/packages/next/src/build/templates/edge-ssr-app.ts b/packages/next/src/build/templates/edge-ssr-app.ts index 8b7fe317537d5..bdc066b9e9271 100644 --- a/packages/next/src/build/templates/edge-ssr-app.ts +++ b/packages/next/src/build/templates/edge-ssr-app.ts @@ -11,6 +11,8 @@ import type { BuildManifest } from '../../server/get-page-files' import type { RequestData } from '../../server/web/types' import type { NextConfigComplete } from '../../server/config-shared' import { PAGE_TYPES } from '../../lib/page-types' +import { setReferenceManifestsSingleton } from '../../server/app-render/action-encryption-utils' +import { createServerModuleMap } from '../../server/app-render/action-utils' declare const incrementalCacheHandler: any // OPTIONAL_IMPORT:incrementalCacheHandler @@ -44,6 +46,17 @@ const subresourceIntegrityManifest = sriEnabled : undefined const nextFontManifest = maybeJSONParse(self.__NEXT_FONT_MANIFEST) +if (rscManifest && rscServerManifest) { + setReferenceManifestsSingleton({ + clientReferenceManifest: rscManifest, + serverActionsManifest: rscServerManifest, + serverModuleMap: createServerModuleMap({ + serverActionsManifest: rscServerManifest, + pageName: 'VAR_PAGE', + }), + }) +} + const render = getRender({ pagesType: PAGE_TYPES.APP, dev, diff --git a/packages/next/src/server/app-render/action-utils.ts b/packages/next/src/server/app-render/action-utils.ts new file mode 100644 index 0000000000000..001b85b9ff1ff --- /dev/null +++ b/packages/next/src/server/app-render/action-utils.ts @@ -0,0 +1,28 @@ +import type { ActionManifest } from '../../build/webpack/plugins/flight-client-entry-plugin' + +// This function creates a Flight-acceptable server module map proxy from our +// Server Reference Manifest similar to our client module map. +// This is because our manifest contains a lot of internal Next.js data that +// are relevant to the runtime, workers, etc. that React doesn't need to know. +export function createServerModuleMap({ + serverActionsManifest, + pageName, +}: { + serverActionsManifest: ActionManifest + pageName: string +}) { + return new Proxy( + {}, + { + get: (_, id: string) => { + return { + id: serverActionsManifest[ + process.env.NEXT_RUNTIME === 'edge' ? 'edge' : 'node' + ][id].workers['app' + pageName], + name: id, + chunks: [], + } + }, + } + ) +} diff --git a/packages/next/src/server/app-render/app-render.tsx b/packages/next/src/server/app-render/app-render.tsx index a88c869987db7..5f83c8d675120 100644 --- a/packages/next/src/server/app-render/app-render.tsx +++ b/packages/next/src/server/app-render/app-render.tsx @@ -80,6 +80,7 @@ import { DetachedPromise } from '../../lib/detached-promise' import { isDynamicServerError } from '../../client/components/hooks-server-context' import { useFlightResponse } from './use-flight-response' import { isStaticGenBailoutError } from '../../client/components/static-generation-bailout' +import { createServerModuleMap } from './action-utils' export type GetDynamicParamFromSegment = ( // [slug] / [[slug]] / [...slug] @@ -586,27 +587,10 @@ async function renderToHTMLOrFlightImpl( // TODO: fix this typescript const clientReferenceManifest = renderOpts.clientReferenceManifest! - const workerName = 'app' + renderOpts.page - const serverModuleMap: { - [id: string]: { - id: string - chunks: string[] - name: string - } - } = new Proxy( - {}, - { - get: (_, id: string) => { - return { - id: serverActionsManifest[ - process.env.NEXT_RUNTIME === 'edge' ? 'edge' : 'node' - ][id].workers[workerName], - name: id, - chunks: [], - } - }, - } - ) + const serverModuleMap = createServerModuleMap({ + serverActionsManifest, + pageName: renderOpts.page, + }) setReferenceManifestsSingleton({ clientReferenceManifest, diff --git a/packages/next/src/server/load-components.ts b/packages/next/src/server/load-components.ts index ad5ef1c7c2832..75b004b75f0e3 100644 --- a/packages/next/src/server/load-components.ts +++ b/packages/next/src/server/load-components.ts @@ -12,6 +12,7 @@ import type { } from 'next/types' import type { RouteModule } from './future/route-modules/route-module' import type { BuildManifest } from './get-page-files' +import type { ActionManifest } from '../build/webpack/plugins/flight-client-entry-plugin' import { BUILD_MANIFEST, @@ -26,6 +27,9 @@ import { getTracer } from './lib/trace/tracer' import { LoadComponentsSpan } from './lib/trace/constants' import { evalManifest, loadManifest } from './load-manifest' import { wait } from '../lib/wait' +import { setReferenceManifestsSingleton } from './app-render/action-encryption-utils' +import { createServerModuleMap } from './app-render/action-utils' + export type ManifestItem = { id: number | string files: string[] @@ -132,15 +136,13 @@ async function loadComponentsImpl({ Promise.resolve().then(() => requirePage('/_app', distDir, false)), ]) } - const ComponentMod = await Promise.resolve().then(() => - requirePage(page, distDir, isAppPath) - ) // Make sure to avoid loading the manifest for Route Handlers const hasClientManifest = isAppPath && (page.endsWith('/page') || page === '/not-found' || page === '/_not-found') + // Load the manifest files first const [ buildManifest, reactLoadableManifest, @@ -165,12 +167,30 @@ async function loadComponentsImpl({ ) : undefined, isAppPath - ? loadManifestWithRetries( + ? (loadManifestWithRetries( join(distDir, 'server', SERVER_REFERENCE_MANIFEST + '.json') - ).catch(() => null) + ).catch(() => null) as Promise) : null, ]) + // Before requring the actual page module, we have to set the reference manifests + // to our global store so Server Action's encryption util can access to them + // at the top level of the page module. + if (serverActionsManifest && clientReferenceManifest) { + setReferenceManifestsSingleton({ + clientReferenceManifest, + serverActionsManifest, + serverModuleMap: createServerModuleMap({ + serverActionsManifest, + pageName: page, + }), + }) + } + + const ComponentMod = await Promise.resolve().then(() => + requirePage(page, distDir, isAppPath) + ) + const Component = interopDefault(ComponentMod) const Document = interopDefault(DocumentMod) const App = interopDefault(AppMod) diff --git a/test/e2e/app-dir/actions/app-action.test.ts b/test/e2e/app-dir/actions/app-action.test.ts index b832e407b866e..c89c3710518d5 100644 --- a/test/e2e/app-dir/actions/app-action.test.ts +++ b/test/e2e/app-dir/actions/app-action.test.ts @@ -981,6 +981,7 @@ createNextDescribe( const res = await next.fetch('/encryption') const html = await res.text() expect(html).not.toContain('qwerty123') + expect(html).not.toContain('some-module-level-encryption-value') }) }) diff --git a/test/e2e/app-dir/actions/app/encryption/page.js b/test/e2e/app-dir/actions/app/encryption/page.js index 77b8c56111e53..822d5a9fa1288 100644 --- a/test/e2e/app-dir/actions/app/encryption/page.js +++ b/test/e2e/app-dir/actions/app/encryption/page.js @@ -1,3 +1,14 @@ +// Test top-level encryption (happens during the module load phase) +function wrapAction(value) { + return async function () { + 'use server' + console.log(value) + } +} + +const action = wrapAction('some-module-level-encryption-value') + +// Test runtime encryption (happens during the rendering phase) export default function Page() { const secret = 'my password is qwerty123' @@ -6,6 +17,7 @@ export default function Page() { action={async () => { 'use server' console.log(secret) + await action() return 'success' }} > From 8fe0a3673a61d5696adad3d30a45392bb3631b8d Mon Sep 17 00:00:00 2001 From: Max Leiter Date: Wed, 28 Feb 2024 12:05:22 -0800 Subject: [PATCH 05/10] build-and-test: run on PRs against canary and next-14-1 --- .github/workflows/build_and_test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index 3c610cedd136e..697bd06980cf9 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -5,6 +5,7 @@ on: branches: ['canary', 'next-14-1'] pull_request: types: [opened, synchronize] + branches: ['canary', 'next-14-1'] env: NAPI_CLI_VERSION: 2.14.7 From 6d49731ba2f1182cb68d01f35acceedd1d78bffc Mon Sep 17 00:00:00 2001 From: Max Leiter Date: Wed, 28 Feb 2024 13:10:35 -0800 Subject: [PATCH 06/10] tests/switchable-runtime: fix test failure due to cherry-pick --- test/e2e/switchable-runtime/index.test.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/e2e/switchable-runtime/index.test.ts b/test/e2e/switchable-runtime/index.test.ts index 831c5141ef5b7..433e2e2bafd37 100644 --- a/test/e2e/switchable-runtime/index.test.ts +++ b/test/e2e/switchable-runtime/index.test.ts @@ -189,6 +189,7 @@ describe('Switchable runtime', () => { '/api/hello': { files: [ 'server/edge-runtime-webpack.js', + 'server/edge-chunks/189.js', 'server/pages/api/hello.js', ], name: 'pages/api/hello', @@ -624,6 +625,7 @@ describe('Switchable runtime', () => { files: [ 'prerender-manifest.js', 'server/edge-runtime-webpack.js', + 'server/edge-chunks/189.js', 'server/pages/api/hello.js', ], name: 'pages/api/hello', From 0131b7fef16a2d4610a02ae9d0747b79e131507f Mon Sep 17 00:00:00 2001 From: Max Leiter Date: Wed, 28 Feb 2024 13:37:31 -0800 Subject: [PATCH 07/10] fix test? --- test/e2e/switchable-runtime/index.test.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/test/e2e/switchable-runtime/index.test.ts b/test/e2e/switchable-runtime/index.test.ts index 433e2e2bafd37..7442b75aab2e5 100644 --- a/test/e2e/switchable-runtime/index.test.ts +++ b/test/e2e/switchable-runtime/index.test.ts @@ -625,7 +625,6 @@ describe('Switchable runtime', () => { files: [ 'prerender-manifest.js', 'server/edge-runtime-webpack.js', - 'server/edge-chunks/189.js', 'server/pages/api/hello.js', ], name: 'pages/api/hello', From 00d8e6e0612b7afddbce5f944a7330413e548871 Mon Sep 17 00:00:00 2001 From: Shu Ding Date: Wed, 14 Feb 2024 14:09:27 +0100 Subject: [PATCH 08/10] Rename internal utility naming for clarification (#62048) `createActionProxy` isn't the accurate name here - the function doesn't return anything new but only mark the value as registered. And also, it might not be a proxy (which is implementation detail) and might not be used for Server Actions only. `registerServerReference` is a better name here. There's no functionality change in this PR, only a few renames. Closes NEXT-2490 --- .../crates/next-core/src/next_import_map.rs | 4 ++-- .../crates/next-core/src/next_server/resolve.rs | 2 +- .../src/transforms/server_actions.rs | 12 ++++++------ .../errors/server-actions/client-graph/1/output.js | 2 +- .../errors/server-actions/server-graph/1/output.js | 4 ++-- .../errors/server-actions/server-graph/2/output.js | 4 ++-- .../errors/server-actions/server-graph/3/output.js | 4 ++-- .../errors/server-actions/server-graph/4/output.js | 2 +- .../errors/server-actions/server-graph/5/output.js | 2 +- .../errors/server-actions/server-graph/6/output.js | 4 ++-- .../errors/server-actions/server-graph/7/output.js | 4 ++-- .../errors/server-actions/server-graph/8/output.js | 4 ++-- .../fixture/server-actions/server/1/output.js | 6 +++--- .../fixture/server-actions/server/10/output.js | 4 ++-- .../fixture/server-actions/server/11/output.js | 4 ++-- .../fixture/server-actions/server/12/output.js | 4 ++-- .../fixture/server-actions/server/13/output.js | 6 +++--- .../fixture/server-actions/server/14/output.js | 4 ++-- .../fixture/server-actions/server/15/output.js | 6 +++--- .../fixture/server-actions/server/16/output.js | 8 ++++---- .../fixture/server-actions/server/17/output.js | 8 ++++---- .../fixture/server-actions/server/18/output.js | 6 +++--- .../fixture/server-actions/server/19/output.js | 4 ++-- .../fixture/server-actions/server/2/output.js | 6 +++--- .../fixture/server-actions/server/20/output.js | 4 ++-- .../fixture/server-actions/server/21/output.js | 8 ++++---- .../fixture/server-actions/server/22/output.js | 10 +++++----- .../fixture/server-actions/server/23/output.js | 6 +++--- .../fixture/server-actions/server/24/output.js | 4 ++-- .../fixture/server-actions/server/25/output.js | 6 +++--- .../fixture/server-actions/server/26/output.js | 4 ++-- .../fixture/server-actions/server/27/input.js | 2 +- .../fixture/server-actions/server/27/output.js | 14 +++++++------- .../fixture/server-actions/server/28/output.js | 8 ++++---- .../fixture/server-actions/server/29/output.js | 8 ++++---- .../fixture/server-actions/server/3/output.js | 4 ++-- .../fixture/server-actions/server/4/output.js | 4 ++-- .../fixture/server-actions/server/5/output.js | 4 ++-- .../fixture/server-actions/server/6/output.js | 4 ++-- .../fixture/server-actions/server/7/output.js | 10 +++++----- .../fixture/server-actions/server/8/output.js | 4 ++-- .../fixture/server-actions/server/9/output.js | 8 ++++---- packages/next/src/build/create-compiler-aliases.ts | 2 +- packages/next/src/build/handle-externals.ts | 2 +- .../{action-proxy.ts => server-reference.ts} | 6 +++--- packages/next/src/lib/constants.ts | 2 +- 46 files changed, 119 insertions(+), 119 deletions(-) rename packages/next/src/build/webpack/loaders/next-flight-loader/{action-proxy.ts => server-reference.ts} (59%) diff --git a/packages/next-swc/crates/next-core/src/next_import_map.rs b/packages/next-swc/crates/next-core/src/next_import_map.rs index 0891e132b9df6..c8d15cfc4b17d 100644 --- a/packages/next-swc/crates/next-core/src/next_import_map.rs +++ b/packages/next-swc/crates/next-core/src/next_import_map.rs @@ -829,10 +829,10 @@ async fn insert_next_shared_aliases( ); import_map.insert_exact_alias( - "private-next-rsc-action-proxy", + "private-next-rsc-server-reference", request_to_import_mapping( project_path, - "next/dist/build/webpack/loaders/next-flight-loader/action-proxy", + "next/dist/build/webpack/loaders/next-flight-loader/server-reference", ), ); import_map.insert_exact_alias( diff --git a/packages/next-swc/crates/next-core/src/next_server/resolve.rs b/packages/next-swc/crates/next-core/src/next_server/resolve.rs index 985d8e952501e..c89eb51619774 100644 --- a/packages/next-swc/crates/next-core/src/next_server/resolve.rs +++ b/packages/next-swc/crates/next-core/src/next_server/resolve.rs @@ -86,7 +86,7 @@ impl ResolvePlugin for ExternalCjsModulesResolvePlugin { } // from https://github.com/vercel/next.js/blob/8d1c619ad650f5d147207f267441caf12acd91d1/packages/next/src/build/handle-externals.ts#L188 - let never_external_regex = lazy_regex::regex!("^(?:private-next-pages\\/|next\\/(?:dist\\/pages\\/|(?:app|document|link|image|legacy\\/image|constants|dynamic|script|navigation|headers|router)$)|string-hash|private-next-rsc-action-validate|private-next-rsc-action-client-wrapper|private-next-rsc-action-proxy$)"); + let never_external_regex = lazy_regex::regex!("^(?:private-next-pages\\/|next\\/(?:dist\\/pages\\/|(?:app|document|link|image|legacy\\/image|constants|dynamic|script|navigation|headers|router)$)|string-hash|private-next-rsc-action-validate|private-next-rsc-action-client-wrapper|private-next-rsc-server-reference$)"); if never_external_regex.is_match(&request_value.request().unwrap_or_default()) { return Ok(ResolveResultOption::none()); diff --git a/packages/next-swc/crates/next-custom-transforms/src/transforms/server_actions.rs b/packages/next-swc/crates/next-custom-transforms/src/transforms/server_actions.rs index 20a684b35414c..3edf437e44740 100644 --- a/packages/next-swc/crates/next-custom-transforms/src/transforms/server_actions.rs +++ b/packages/next-swc/crates/next-custom-transforms/src/transforms/server_actions.rs @@ -1045,19 +1045,19 @@ impl VisitMut for ServerActions { 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") + // import { registerServerReference } from 'private-next-rsc-server-reference' + // registerServerReference("action_id") new.push(ModuleItem::ModuleDecl(ModuleDecl::Import(ImportDecl { span: DUMMY_SP, specifiers: vec![ImportSpecifier::Named(ImportNamedSpecifier { span: DUMMY_SP, - local: quote_ident!("createActionProxy"), + local: quote_ident!("registerServerReference"), imported: None, is_type_only: false, })], src: Box::new(Str { span: DUMMY_SP, - value: "private-next-rsc-action-proxy".into(), + value: "private-next-rsc-server-reference".into(), raw: None, }), type_only: false, @@ -1214,13 +1214,13 @@ fn annotate_ident_as_action( file_name: &str, export_name: String, ) -> Expr { - // Add the proxy wrapper call `createActionProxy($$id, $$bound, myAction, + // Add the proxy wrapper call `registerServerReference($$id, $$bound, myAction, // maybe_orig_action)`. let action_id = generate_action_id(file_name, &export_name); let proxy_expr = Expr::Call(CallExpr { span: DUMMY_SP, - callee: quote_ident!("createActionProxy").as_callee(), + callee: quote_ident!("registerServerReference").as_callee(), args: vec![ // $$id ExprOrSpread { diff --git a/packages/next-swc/crates/next-custom-transforms/tests/errors/server-actions/client-graph/1/output.js b/packages/next-swc/crates/next-custom-transforms/tests/errors/server-actions/client-graph/1/output.js index e9c17d048e0c3..0b804567eaaa7 100644 --- a/packages/next-swc/crates/next-custom-transforms/tests/errors/server-actions/client-graph/1/output.js +++ b/packages/next-swc/crates/next-custom-transforms/tests/errors/server-actions/client-graph/1/output.js @@ -1,5 +1,5 @@ /* __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() { - var fn = createActionProxy("6d53ce510b2e36499b8f56038817b9bad86cabb4", $$ACTION_0); + var fn = registerServerReference("6d53ce510b2e36499b8f56038817b9bad86cabb4", $$ACTION_0); return
App
; } diff --git a/packages/next-swc/crates/next-custom-transforms/tests/errors/server-actions/server-graph/1/output.js b/packages/next-swc/crates/next-custom-transforms/tests/errors/server-actions/server-graph/1/output.js index 9e261dd7b291e..ecba6f9f39448 100644 --- a/packages/next-swc/crates/next-custom-transforms/tests/errors/server-actions/server-graph/1/output.js +++ b/packages/next-swc/crates/next-custom-transforms/tests/errors/server-actions/server-graph/1/output.js @@ -1,8 +1,8 @@ -/* __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"} */ import { registerServerReference } from "private-next-rsc-server-reference"; import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption"; export function foo() {} import { ensureServerEntryExports } from "private-next-rsc-action-validate"; ensureServerEntryExports([ foo ]); -createActionProxy("ab21efdafbe611287bc25c0462b1e0510d13e48b", foo); +registerServerReference("ab21efdafbe611287bc25c0462b1e0510d13e48b", foo); diff --git a/packages/next-swc/crates/next-custom-transforms/tests/errors/server-actions/server-graph/2/output.js b/packages/next-swc/crates/next-custom-transforms/tests/errors/server-actions/server-graph/2/output.js index 97d918daabba0..1dd3034f34616 100644 --- a/packages/next-swc/crates/next-custom-transforms/tests/errors/server-actions/server-graph/2/output.js +++ b/packages/next-swc/crates/next-custom-transforms/tests/errors/server-actions/server-graph/2/output.js @@ -1,4 +1,4 @@ -/* __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"} */ import { registerServerReference } from "private-next-rsc-server-reference"; import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption"; 'use strict'; export function bar() {} @@ -6,4 +6,4 @@ import { ensureServerEntryExports } from "private-next-rsc-action-validate"; ensureServerEntryExports([ bar ]); -createActionProxy("ac840dcaf5e8197cb02b7f3a43c119b7a770b272", bar); +registerServerReference("ac840dcaf5e8197cb02b7f3a43c119b7a770b272", bar); diff --git a/packages/next-swc/crates/next-custom-transforms/tests/errors/server-actions/server-graph/3/output.js b/packages/next-swc/crates/next-custom-transforms/tests/errors/server-actions/server-graph/3/output.js index c6a9e115ec00f..29d945f830519 100644 --- a/packages/next-swc/crates/next-custom-transforms/tests/errors/server-actions/server-graph/3/output.js +++ b/packages/next-swc/crates/next-custom-transforms/tests/errors/server-actions/server-graph/3/output.js @@ -1,8 +1,8 @@ -/* __next_internal_action_entry_do_not_use__ {"b78c261f135a7a852508c2920bd7228020ff4bd7":"x"} */ import { createActionProxy } from "private-next-rsc-action-proxy"; +/* __next_internal_action_entry_do_not_use__ {"b78c261f135a7a852508c2920bd7228020ff4bd7":"x"} */ import { registerServerReference } from "private-next-rsc-server-reference"; import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption"; export const x = 1; import { ensureServerEntryExports } from "private-next-rsc-action-validate"; ensureServerEntryExports([ x ]); -createActionProxy("b78c261f135a7a852508c2920bd7228020ff4bd7", x); +registerServerReference("b78c261f135a7a852508c2920bd7228020ff4bd7", x); diff --git a/packages/next-swc/crates/next-custom-transforms/tests/errors/server-actions/server-graph/4/output.js b/packages/next-swc/crates/next-custom-transforms/tests/errors/server-actions/server-graph/4/output.js index f8dc21b9d8ae5..1e4e2d5ded6f3 100644 --- a/packages/next-swc/crates/next-custom-transforms/tests/errors/server-actions/server-graph/4/output.js +++ b/packages/next-swc/crates/next-custom-transforms/tests/errors/server-actions/server-graph/4/output.js @@ -1,4 +1,4 @@ -/* __next_internal_action_entry_do_not_use__ {} */ import { createActionProxy } from "private-next-rsc-action-proxy"; +/* __next_internal_action_entry_do_not_use__ {} */ import { registerServerReference } from "private-next-rsc-server-reference"; import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption"; export default class Component { render() { diff --git a/packages/next-swc/crates/next-custom-transforms/tests/errors/server-actions/server-graph/5/output.js b/packages/next-swc/crates/next-custom-transforms/tests/errors/server-actions/server-graph/5/output.js index fe4d3fb0ac3fe..f0d232472bf84 100644 --- a/packages/next-swc/crates/next-custom-transforms/tests/errors/server-actions/server-graph/5/output.js +++ b/packages/next-swc/crates/next-custom-transforms/tests/errors/server-actions/server-graph/5/output.js @@ -1,4 +1,4 @@ -/* __next_internal_action_entry_do_not_use__ {} */ import { createActionProxy } from "private-next-rsc-action-proxy"; +/* __next_internal_action_entry_do_not_use__ {} */ import { registerServerReference } from "private-next-rsc-server-reference"; import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption"; export * from 'foo'; import { ensureServerEntryExports } from "private-next-rsc-action-validate"; diff --git a/packages/next-swc/crates/next-custom-transforms/tests/errors/server-actions/server-graph/6/output.js b/packages/next-swc/crates/next-custom-transforms/tests/errors/server-actions/server-graph/6/output.js index 3b12261603df4..8ef2648072c12 100644 --- a/packages/next-swc/crates/next-custom-transforms/tests/errors/server-actions/server-graph/6/output.js +++ b/packages/next-swc/crates/next-custom-transforms/tests/errors/server-actions/server-graph/6/output.js @@ -1,6 +1,6 @@ -/* __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__ {"6d53ce510b2e36499b8f56038817b9bad86cabb4":"$$ACTION_0"} */ import { registerServerReference } from "private-next-rsc-server-reference"; import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption"; -export default createActionProxy("6d53ce510b2e36499b8f56038817b9bad86cabb4", $$ACTION_0); +export default registerServerReference("6d53ce510b2e36499b8f56038817b9bad86cabb4", $$ACTION_0); export async function $$ACTION_0() {} import { ensureServerEntryExports } from "private-next-rsc-action-validate"; ensureServerEntryExports([]); diff --git a/packages/next-swc/crates/next-custom-transforms/tests/errors/server-actions/server-graph/7/output.js b/packages/next-swc/crates/next-custom-transforms/tests/errors/server-actions/server-graph/7/output.js index 8b7105a3190db..f9711506c40c6 100644 --- a/packages/next-swc/crates/next-custom-transforms/tests/errors/server-actions/server-graph/7/output.js +++ b/packages/next-swc/crates/next-custom-transforms/tests/errors/server-actions/server-graph/7/output.js @@ -1,4 +1,4 @@ -/* __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__ {"6d53ce510b2e36499b8f56038817b9bad86cabb4":"$$ACTION_0"} */ import { registerServerReference } from "private-next-rsc-server-reference"; import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption"; -const foo = createActionProxy("6d53ce510b2e36499b8f56038817b9bad86cabb4", $$ACTION_0); +const foo = registerServerReference("6d53ce510b2e36499b8f56038817b9bad86cabb4", $$ACTION_0); export async function $$ACTION_0() {} diff --git a/packages/next-swc/crates/next-custom-transforms/tests/errors/server-actions/server-graph/8/output.js b/packages/next-swc/crates/next-custom-transforms/tests/errors/server-actions/server-graph/8/output.js index ac8f4884a4ef1..400aef21835dc 100644 --- a/packages/next-swc/crates/next-custom-transforms/tests/errors/server-actions/server-graph/8/output.js +++ b/packages/next-swc/crates/next-custom-transforms/tests/errors/server-actions/server-graph/8/output.js @@ -1,6 +1,6 @@ -/* __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__ {"6d53ce510b2e36499b8f56038817b9bad86cabb4":"$$ACTION_0"} */ import { registerServerReference } from "private-next-rsc-server-reference"; import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption"; -const foo = createActionProxy("6d53ce510b2e36499b8f56038817b9bad86cabb4", $$ACTION_0); +const foo = registerServerReference("6d53ce510b2e36499b8f56038817b9bad86cabb4", $$ACTION_0); export async function $$ACTION_0() { 'use strict'; } diff --git a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/1/output.js b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/1/output.js index 083fae9175ab1..1d12a66e13ace 100644 --- a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/1/output.js +++ b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/1/output.js @@ -1,8 +1,8 @@ -/* __next_internal_action_entry_do_not_use__ {"188d5d945750dc32e2c842b93c75a65763d4a922":"$$ACTION_1","6d53ce510b2e36499b8f56038817b9bad86cabb4":"$$ACTION_0"} */ import { createActionProxy } from "private-next-rsc-action-proxy"; +/* __next_internal_action_entry_do_not_use__ {"188d5d945750dc32e2c842b93c75a65763d4a922":"$$ACTION_1","6d53ce510b2e36499b8f56038817b9bad86cabb4":"$$ACTION_0"} */ import { registerServerReference } from "private-next-rsc-server-reference"; import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption"; import deleteFromDb from 'db'; export function Item({ id1, id2 }) { - var deleteItem = createActionProxy("6d53ce510b2e36499b8f56038817b9bad86cabb4", $$ACTION_0).bind(null, encryptActionBoundArgs("6d53ce510b2e36499b8f56038817b9bad86cabb4", [ + var deleteItem = registerServerReference("6d53ce510b2e36499b8f56038817b9bad86cabb4", $$ACTION_0).bind(null, encryptActionBoundArgs("6d53ce510b2e36499b8f56038817b9bad86cabb4", [ id1, id2 ])); @@ -18,7 +18,7 @@ export default function Home() { name: 'John', test: 'test' }; - const action = createActionProxy("188d5d945750dc32e2c842b93c75a65763d4a922", $$ACTION_1).bind(null, encryptActionBoundArgs("188d5d945750dc32e2c842b93c75a65763d4a922", [ + const action = registerServerReference("188d5d945750dc32e2c842b93c75a65763d4a922", $$ACTION_1).bind(null, encryptActionBoundArgs("188d5d945750dc32e2c842b93c75a65763d4a922", [ info.name, info.test ])); diff --git a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/10/output.js b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/10/output.js index 8666bb1f6e985..871fdbb306f18 100644 --- a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/10/output.js +++ b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/10/output.js @@ -1,8 +1,8 @@ -/* __next_internal_action_entry_do_not_use__ {"c18c215a6b7cdc64bf709f3a714ffdef1bf9651d":"default"} */ import { createActionProxy } from "private-next-rsc-action-proxy"; +/* __next_internal_action_entry_do_not_use__ {"c18c215a6b7cdc64bf709f3a714ffdef1bf9651d":"default"} */ import { registerServerReference } from "private-next-rsc-server-reference"; import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption"; export default async function foo() {} import { ensureServerEntryExports } from "private-next-rsc-action-validate"; ensureServerEntryExports([ foo ]); -createActionProxy("c18c215a6b7cdc64bf709f3a714ffdef1bf9651d", foo); +registerServerReference("c18c215a6b7cdc64bf709f3a714ffdef1bf9651d", foo); diff --git a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/11/output.js b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/11/output.js index dab935ba484f6..4aac8b2676488 100644 --- a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/11/output.js +++ b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/11/output.js @@ -1,8 +1,8 @@ -/* __next_internal_action_entry_do_not_use__ {"c18c215a6b7cdc64bf709f3a714ffdef1bf9651d":"default"} */ import { createActionProxy } from "private-next-rsc-action-proxy"; +/* __next_internal_action_entry_do_not_use__ {"c18c215a6b7cdc64bf709f3a714ffdef1bf9651d":"default"} */ import { registerServerReference } from "private-next-rsc-server-reference"; import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption"; export default async function $$ACTION_0() {} import { ensureServerEntryExports } from "private-next-rsc-action-validate"; ensureServerEntryExports([ $$ACTION_0 ]); -createActionProxy("c18c215a6b7cdc64bf709f3a714ffdef1bf9651d", $$ACTION_0); +registerServerReference("c18c215a6b7cdc64bf709f3a714ffdef1bf9651d", $$ACTION_0); diff --git a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/12/output.js b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/12/output.js index 373f388b78dcb..9e5ece55cb20a 100644 --- a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/12/output.js +++ b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/12/output.js @@ -1,4 +1,4 @@ -/* __next_internal_action_entry_do_not_use__ {"c18c215a6b7cdc64bf709f3a714ffdef1bf9651d":"default"} */ import { createActionProxy } from "private-next-rsc-action-proxy"; +/* __next_internal_action_entry_do_not_use__ {"c18c215a6b7cdc64bf709f3a714ffdef1bf9651d":"default"} */ import { registerServerReference } from "private-next-rsc-server-reference"; import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption"; async function foo() {} export default foo; @@ -6,4 +6,4 @@ import { ensureServerEntryExports } from "private-next-rsc-action-validate"; ensureServerEntryExports([ foo ]); -createActionProxy("c18c215a6b7cdc64bf709f3a714ffdef1bf9651d", foo); +registerServerReference("c18c215a6b7cdc64bf709f3a714ffdef1bf9651d", foo); diff --git a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/13/output.js b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/13/output.js index c4db2124ab3cb..c958051367890 100644 --- a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/13/output.js +++ b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/13/output.js @@ -1,4 +1,4 @@ -/* __next_internal_action_entry_do_not_use__ {"ac840dcaf5e8197cb02b7f3a43c119b7a770b272":"bar","c18c215a6b7cdc64bf709f3a714ffdef1bf9651d":"default"} */ import { createActionProxy } from "private-next-rsc-action-proxy"; +/* __next_internal_action_entry_do_not_use__ {"ac840dcaf5e8197cb02b7f3a43c119b7a770b272":"bar","c18c215a6b7cdc64bf709f3a714ffdef1bf9651d":"default"} */ import { registerServerReference } from "private-next-rsc-server-reference"; import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption"; const foo = async function() {}; export default foo; @@ -9,5 +9,5 @@ ensureServerEntryExports([ foo, bar ]); -createActionProxy("c18c215a6b7cdc64bf709f3a714ffdef1bf9651d", foo); -createActionProxy("ac840dcaf5e8197cb02b7f3a43c119b7a770b272", bar); +registerServerReference("c18c215a6b7cdc64bf709f3a714ffdef1bf9651d", foo); +registerServerReference("ac840dcaf5e8197cb02b7f3a43c119b7a770b272", bar); diff --git a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/14/output.js b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/14/output.js index 1b1dbde5af657..fa283adc6262e 100644 --- a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/14/output.js +++ b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/14/output.js @@ -1,4 +1,4 @@ -/* __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"} */ import { registerServerReference } from "private-next-rsc-server-reference"; import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption"; export async function foo() { async function bar() {} @@ -7,4 +7,4 @@ import { ensureServerEntryExports } from "private-next-rsc-action-validate"; ensureServerEntryExports([ foo ]); -createActionProxy("ab21efdafbe611287bc25c0462b1e0510d13e48b", foo); +registerServerReference("ab21efdafbe611287bc25c0462b1e0510d13e48b", foo); diff --git a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/15/output.js b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/15/output.js index 6f9c9865c243e..bec01bcac7b93 100644 --- a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/15/output.js +++ b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/15/output.js @@ -1,6 +1,6 @@ -/* __next_internal_action_entry_do_not_use__ {"188d5d945750dc32e2c842b93c75a65763d4a922":"$$ACTION_1","c18c215a6b7cdc64bf709f3a714ffdef1bf9651d":"default"} */ import { createActionProxy } from "private-next-rsc-action-proxy"; +/* __next_internal_action_entry_do_not_use__ {"188d5d945750dc32e2c842b93c75a65763d4a922":"$$ACTION_1","c18c215a6b7cdc64bf709f3a714ffdef1bf9651d":"default"} */ import { registerServerReference } from "private-next-rsc-server-reference"; import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption"; -export default $$ACTION_0 = createActionProxy("188d5d945750dc32e2c842b93c75a65763d4a922", $$ACTION_1); +export default $$ACTION_0 = registerServerReference("188d5d945750dc32e2c842b93c75a65763d4a922", $$ACTION_1); var $$ACTION_0; export async function $$ACTION_1(a, b) { console.log(a, b); @@ -9,4 +9,4 @@ import { ensureServerEntryExports } from "private-next-rsc-action-validate"; ensureServerEntryExports([ $$ACTION_0 ]); -createActionProxy("c18c215a6b7cdc64bf709f3a714ffdef1bf9651d", $$ACTION_0); +registerServerReference("c18c215a6b7cdc64bf709f3a714ffdef1bf9651d", $$ACTION_0); diff --git a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/16/output.js b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/16/output.js index 2d6955320a27a..0631a83887aab 100644 --- a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/16/output.js +++ b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/16/output.js @@ -1,10 +1,10 @@ -/* __next_internal_action_entry_do_not_use__ {"188d5d945750dc32e2c842b93c75a65763d4a922":"$$ACTION_1","6d53ce510b2e36499b8f56038817b9bad86cabb4":"$$ACTION_0","9878bfa39811ca7650992850a8751f9591b6a557":"$$ACTION_2"} */ import { createActionProxy } from "private-next-rsc-action-proxy"; +/* __next_internal_action_entry_do_not_use__ {"188d5d945750dc32e2c842b93c75a65763d4a922":"$$ACTION_1","6d53ce510b2e36499b8f56038817b9bad86cabb4":"$$ACTION_0","9878bfa39811ca7650992850a8751f9591b6a557":"$$ACTION_2"} */ import { registerServerReference } from "private-next-rsc-server-reference"; 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 = createActionProxy("6d53ce510b2e36499b8f56038817b9bad86cabb4", $$ACTION_0).bind(null, encryptActionBoundArgs("6d53ce510b2e36499b8f56038817b9bad86cabb4", [ + const deleteItem = registerServerReference("6d53ce510b2e36499b8f56038817b9bad86cabb4", $$ACTION_0).bind(null, encryptActionBoundArgs("6d53ce510b2e36499b8f56038817b9bad86cabb4", [ id1, v2 ])); @@ -17,7 +17,7 @@ export async function $$ACTION_0($$ACTION_CLOSURE_BOUND) { await deleteFromDb($$ACTION_ARG_1); } const f = (x)=>{ - var g = createActionProxy("188d5d945750dc32e2c842b93c75a65763d4a922", $$ACTION_1).bind(null, encryptActionBoundArgs("188d5d945750dc32e2c842b93c75a65763d4a922", [ + var g = registerServerReference("188d5d945750dc32e2c842b93c75a65763d4a922", $$ACTION_1).bind(null, encryptActionBoundArgs("188d5d945750dc32e2c842b93c75a65763d4a922", [ x ])); }; @@ -26,7 +26,7 @@ export async function $$ACTION_1($$ACTION_CLOSURE_BOUND, y, ...z) { return $$ACTION_ARG_0 + y + z[0]; } const g = (x)=>{ - f = createActionProxy("9878bfa39811ca7650992850a8751f9591b6a557", $$ACTION_2).bind(null, encryptActionBoundArgs("9878bfa39811ca7650992850a8751f9591b6a557", [ + f = registerServerReference("9878bfa39811ca7650992850a8751f9591b6a557", $$ACTION_2).bind(null, encryptActionBoundArgs("9878bfa39811ca7650992850a8751f9591b6a557", [ x ])); }; diff --git a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/17/output.js b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/17/output.js index 740fbdfab43fd..f0318ce0ddee0 100644 --- a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/17/output.js +++ b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/17/output.js @@ -1,6 +1,6 @@ -/* __next_internal_action_entry_do_not_use__ {"6d53ce510b2e36499b8f56038817b9bad86cabb4":"$$ACTION_0","ab21efdafbe611287bc25c0462b1e0510d13e48b":"foo","ac840dcaf5e8197cb02b7f3a43c119b7a770b272":"bar"} */ import { createActionProxy } from "private-next-rsc-action-proxy"; +/* __next_internal_action_entry_do_not_use__ {"6d53ce510b2e36499b8f56038817b9bad86cabb4":"$$ACTION_0","ab21efdafbe611287bc25c0462b1e0510d13e48b":"foo","ac840dcaf5e8197cb02b7f3a43c119b7a770b272":"bar"} */ import { registerServerReference } from "private-next-rsc-server-reference"; import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption"; -export const foo = createActionProxy("6d53ce510b2e36499b8f56038817b9bad86cabb4", $$ACTION_0); +export const foo = registerServerReference("6d53ce510b2e36499b8f56038817b9bad86cabb4", $$ACTION_0); export async function $$ACTION_0() {} const bar = async ()=>{}; export { bar }; @@ -9,5 +9,5 @@ ensureServerEntryExports([ foo, bar ]); -createActionProxy("ab21efdafbe611287bc25c0462b1e0510d13e48b", foo); -createActionProxy("ac840dcaf5e8197cb02b7f3a43c119b7a770b272", bar); +registerServerReference("ab21efdafbe611287bc25c0462b1e0510d13e48b", foo); +registerServerReference("ac840dcaf5e8197cb02b7f3a43c119b7a770b272", bar); diff --git a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/18/output.js b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/18/output.js index a05b92ee24856..64f30fef36004 100644 --- a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/18/output.js +++ b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/18/output.js @@ -1,4 +1,4 @@ -/* __next_internal_action_entry_do_not_use__ {"6d53ce510b2e36499b8f56038817b9bad86cabb4":"$$ACTION_0","9878bfa39811ca7650992850a8751f9591b6a557":"$$ACTION_2"} */ import { createActionProxy } from "private-next-rsc-action-proxy"; +/* __next_internal_action_entry_do_not_use__ {"6d53ce510b2e36499b8f56038817b9bad86cabb4":"$$ACTION_0","9878bfa39811ca7650992850a8751f9591b6a557":"$$ACTION_2"} */ import { registerServerReference } from "private-next-rsc-server-reference"; import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption"; import deleteFromDb from 'db'; const v1 = 'v1'; @@ -6,7 +6,7 @@ export function Item({ id1, id2 }) { const v2 = id2; return <> - - ; } -export const action = withValidate(createActionProxy("188d5d945750dc32e2c842b93c75a65763d4a922", $$ACTION_1)); +export const action = withValidate(registerServerReference("188d5d945750dc32e2c842b93c75a65763d4a922", $$ACTION_1)); export async function $$ACTION_1() {} diff --git a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/20/output.js b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/20/output.js index bd3457e7b41a5..c12b50b3bd560 100644 --- a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/20/output.js +++ b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/20/output.js @@ -1,4 +1,4 @@ -/* __next_internal_action_entry_do_not_use__ {"c18c215a6b7cdc64bf709f3a714ffdef1bf9651d":"default"} */ import { createActionProxy } from "private-next-rsc-action-proxy"; +/* __next_internal_action_entry_do_not_use__ {"c18c215a6b7cdc64bf709f3a714ffdef1bf9651d":"default"} */ import { registerServerReference } from "private-next-rsc-server-reference"; import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption"; const [foo] = [ null @@ -8,4 +8,4 @@ import { ensureServerEntryExports } from "private-next-rsc-action-validate"; ensureServerEntryExports([ foo ]); -createActionProxy("c18c215a6b7cdc64bf709f3a714ffdef1bf9651d", foo); +registerServerReference("c18c215a6b7cdc64bf709f3a714ffdef1bf9651d", foo); diff --git a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/21/output.js b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/21/output.js index faea436604bdf..5b7bd12e50d13 100644 --- a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/21/output.js +++ b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/21/output.js @@ -1,10 +1,10 @@ -/* __next_internal_action_entry_do_not_use__ {"188d5d945750dc32e2c842b93c75a65763d4a922":"$$ACTION_1","56a859f462d35a297c46a1bbd1e6a9058c104ab8":"$$ACTION_3","9878bfa39811ca7650992850a8751f9591b6a557":"$$ACTION_2"} */ import { createActionProxy } from "private-next-rsc-action-proxy"; +/* __next_internal_action_entry_do_not_use__ {"188d5d945750dc32e2c842b93c75a65763d4a922":"$$ACTION_1","56a859f462d35a297c46a1bbd1e6a9058c104ab8":"$$ACTION_3","9878bfa39811ca7650992850a8751f9591b6a557":"$$ACTION_2"} */ import { registerServerReference } from "private-next-rsc-server-reference"; import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption"; import { validator, another } from 'auth'; const x = 1; export default function Page() { const y = 1; - return ; } @@ -12,7 +12,7 @@ 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; } -validator(createActionProxy("9878bfa39811ca7650992850a8751f9591b6a557", $$ACTION_2)); +validator(registerServerReference("9878bfa39811ca7650992850a8751f9591b6a557", $$ACTION_2)); export async function $$ACTION_2() {} -another(validator(createActionProxy("56a859f462d35a297c46a1bbd1e6a9058c104ab8", $$ACTION_3))); +another(validator(registerServerReference("56a859f462d35a297c46a1bbd1e6a9058c104ab8", $$ACTION_3))); export async function $$ACTION_3() {} diff --git a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/22/output.js b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/22/output.js index 084fe21f6f201..690e5f44d2682 100644 --- a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/22/output.js +++ b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/22/output.js @@ -1,9 +1,9 @@ -/* __next_internal_action_entry_do_not_use__ {"6d53ce510b2e36499b8f56038817b9bad86cabb4":"$$ACTION_0","9878bfa39811ca7650992850a8751f9591b6a557":"$$ACTION_2","c18c215a6b7cdc64bf709f3a714ffdef1bf9651d":"default","f14702b5a021dd117f7ec7a3c838f397c2046d3b":"action"} */ import { createActionProxy } from "private-next-rsc-action-proxy"; +/* __next_internal_action_entry_do_not_use__ {"6d53ce510b2e36499b8f56038817b9bad86cabb4":"$$ACTION_0","9878bfa39811ca7650992850a8751f9591b6a557":"$$ACTION_2","c18c215a6b7cdc64bf709f3a714ffdef1bf9651d":"default","f14702b5a021dd117f7ec7a3c838f397c2046d3b":"action"} */ import { registerServerReference } from "private-next-rsc-server-reference"; import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption"; import { validator } from 'auth'; -export const action = validator(createActionProxy("6d53ce510b2e36499b8f56038817b9bad86cabb4", $$ACTION_0)); +export const action = validator(registerServerReference("6d53ce510b2e36499b8f56038817b9bad86cabb4", $$ACTION_0)); export async function $$ACTION_0() {} -export default $$ACTION_1 = validator(createActionProxy("9878bfa39811ca7650992850a8751f9591b6a557", $$ACTION_2)); +export default $$ACTION_1 = validator(registerServerReference("9878bfa39811ca7650992850a8751f9591b6a557", $$ACTION_2)); var $$ACTION_1; export async function $$ACTION_2() {} import { ensureServerEntryExports } from "private-next-rsc-action-validate"; @@ -11,5 +11,5 @@ ensureServerEntryExports([ action, $$ACTION_1 ]); -createActionProxy("f14702b5a021dd117f7ec7a3c838f397c2046d3b", action); -createActionProxy("c18c215a6b7cdc64bf709f3a714ffdef1bf9651d", $$ACTION_1); +registerServerReference("f14702b5a021dd117f7ec7a3c838f397c2046d3b", action); +registerServerReference("c18c215a6b7cdc64bf709f3a714ffdef1bf9651d", $$ACTION_1); diff --git a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/23/output.js b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/23/output.js index 4d8250f54d807..27ef0fa4bfd83 100644 --- a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/23/output.js +++ b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/23/output.js @@ -1,11 +1,11 @@ -/* __next_internal_action_entry_do_not_use__ {"188d5d945750dc32e2c842b93c75a65763d4a922":"$$ACTION_1","6d53ce510b2e36499b8f56038817b9bad86cabb4":"$$ACTION_0"} */ import { createActionProxy } from "private-next-rsc-action-proxy"; +/* __next_internal_action_entry_do_not_use__ {"188d5d945750dc32e2c842b93c75a65763d4a922":"$$ACTION_1","6d53ce510b2e36499b8f56038817b9bad86cabb4":"$$ACTION_0"} */ import { registerServerReference } from "private-next-rsc-server-reference"; import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption"; export default function Page({ foo, x, y }) { - var action = createActionProxy("6d53ce510b2e36499b8f56038817b9bad86cabb4", $$ACTION_0).bind(null, encryptActionBoundArgs("6d53ce510b2e36499b8f56038817b9bad86cabb4", [ + var action = registerServerReference("6d53ce510b2e36499b8f56038817b9bad86cabb4", $$ACTION_0).bind(null, encryptActionBoundArgs("6d53ce510b2e36499b8f56038817b9bad86cabb4", [ x ])); action.bind(null, foo[0], foo[1], foo.x, foo[y]); - const action2 = createActionProxy("188d5d945750dc32e2c842b93c75a65763d4a922", $$ACTION_1).bind(null, encryptActionBoundArgs("188d5d945750dc32e2c842b93c75a65763d4a922", [ + const action2 = registerServerReference("188d5d945750dc32e2c842b93c75a65763d4a922", $$ACTION_1).bind(null, encryptActionBoundArgs("188d5d945750dc32e2c842b93c75a65763d4a922", [ x ])); action2.bind(null, foo[0], foo[1], foo.x, foo[y]); diff --git a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/24/output.js b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/24/output.js index 4e5be7b14ebb4..04ce8bf12269f 100644 --- a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/24/output.js +++ b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/24/output.js @@ -1,7 +1,7 @@ -/* __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__ {"6d53ce510b2e36499b8f56038817b9bad86cabb4":"$$ACTION_0"} */ import { registerServerReference } from "private-next-rsc-server-reference"; import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption"; export default function Page({ foo, x, y }) { - var action = createActionProxy("6d53ce510b2e36499b8f56038817b9bad86cabb4", $$ACTION_0).bind(null, encryptActionBoundArgs("6d53ce510b2e36499b8f56038817b9bad86cabb4", [ + var action = registerServerReference("6d53ce510b2e36499b8f56038817b9bad86cabb4", $$ACTION_0).bind(null, encryptActionBoundArgs("6d53ce510b2e36499b8f56038817b9bad86cabb4", [ foo ])); } diff --git a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/25/output.js b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/25/output.js index 7bb149f668f25..6785d57893fc7 100644 --- a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/25/output.js +++ b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/25/output.js @@ -1,4 +1,4 @@ -/* __next_internal_action_entry_do_not_use__ {"188d5d945750dc32e2c842b93c75a65763d4a922":"$$ACTION_1","6d53ce510b2e36499b8f56038817b9bad86cabb4":"$$ACTION_0"} */ import { createActionProxy } from "private-next-rsc-action-proxy"; +/* __next_internal_action_entry_do_not_use__ {"188d5d945750dc32e2c842b93c75a65763d4a922":"$$ACTION_1","6d53ce510b2e36499b8f56038817b9bad86cabb4":"$$ACTION_0"} */ import { registerServerReference } from "private-next-rsc-server-reference"; import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption"; import deleteFromDb from 'db'; export function Item({ id1, id2 }) { @@ -7,7 +7,7 @@ export function Item({ id1, id2 }) { id1++; return ; })(); - var deleteItem = createActionProxy("6d53ce510b2e36499b8f56038817b9bad86cabb4", $$ACTION_0).bind(null, encryptActionBoundArgs("6d53ce510b2e36499b8f56038817b9bad86cabb4", [ + var deleteItem = registerServerReference("6d53ce510b2e36499b8f56038817b9bad86cabb4", $$ACTION_0).bind(null, encryptActionBoundArgs("6d53ce510b2e36499b8f56038817b9bad86cabb4", [ id1, id2 ])); @@ -26,7 +26,7 @@ export function Item2({ id1, id2 }) { id1++; temp.push(); return temp; - var deleteItem = createActionProxy("188d5d945750dc32e2c842b93c75a65763d4a922", $$ACTION_1).bind(null, encryptActionBoundArgs("188d5d945750dc32e2c842b93c75a65763d4a922", [ + var deleteItem = registerServerReference("188d5d945750dc32e2c842b93c75a65763d4a922", $$ACTION_1).bind(null, encryptActionBoundArgs("188d5d945750dc32e2c842b93c75a65763d4a922", [ id1, id2 ])); diff --git a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/26/output.js b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/26/output.js index 0ac1137e64668..fd8b22458d80f 100644 --- a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/26/output.js +++ b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/26/output.js @@ -1,7 +1,7 @@ -/* __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__ {"6d53ce510b2e36499b8f56038817b9bad86cabb4":"$$ACTION_0"} */ import { registerServerReference } from "private-next-rsc-server-reference"; import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption"; const noop = (action)=>action; -export const log = noop(createActionProxy("6d53ce510b2e36499b8f56038817b9bad86cabb4", $$ACTION_0)); +export const log = noop(registerServerReference("6d53ce510b2e36499b8f56038817b9bad86cabb4", $$ACTION_0)); export async function $$ACTION_0(data) { console.log(data); } diff --git a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/27/input.js b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/27/input.js index 02e4dc5af170b..36a038fe9d2e8 100644 --- a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/27/input.js +++ b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/27/input.js @@ -1,5 +1,5 @@ // Rules here: -// 1. Each exported function should still be exported, but as a reference `createActionProxy(...)`. +// 1. Each exported function should still be exported, but as a reference `registerServerReference(...)`. // 2. Actual action functions should be renamed to `$$ACTION_...` and got exported. async function foo() { diff --git a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/27/output.js b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/27/output.js index 86065e1d8551e..57b02081d277c 100644 --- a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/27/output.js +++ b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/27/output.js @@ -1,26 +1,26 @@ // Rules here: -// 1. Each exported function should still be exported, but as a reference `createActionProxy(...)`. +// 1. Each exported function should still be exported, but as a reference `registerServerReference(...)`. // 2. Actual action functions should be renamed to `$$ACTION_...` and got exported. -/* __next_internal_action_entry_do_not_use__ {"188d5d945750dc32e2c842b93c75a65763d4a922":"$$ACTION_1","56a859f462d35a297c46a1bbd1e6a9058c104ab8":"$$ACTION_3","6d53ce510b2e36499b8f56038817b9bad86cabb4":"$$ACTION_0","9878bfa39811ca7650992850a8751f9591b6a557":"$$ACTION_2","9c0dd1f7c2b3f41d32e10f5c437de3d67ad32c6c":"$$ACTION_4"} */ import { createActionProxy } from "private-next-rsc-action-proxy"; +/* __next_internal_action_entry_do_not_use__ {"188d5d945750dc32e2c842b93c75a65763d4a922":"$$ACTION_1","56a859f462d35a297c46a1bbd1e6a9058c104ab8":"$$ACTION_3","6d53ce510b2e36499b8f56038817b9bad86cabb4":"$$ACTION_0","9878bfa39811ca7650992850a8751f9591b6a557":"$$ACTION_2","9c0dd1f7c2b3f41d32e10f5c437de3d67ad32c6c":"$$ACTION_4"} */ import { registerServerReference } from "private-next-rsc-server-reference"; import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption"; -var foo = createActionProxy("6d53ce510b2e36499b8f56038817b9bad86cabb4", $$ACTION_0); +var foo = registerServerReference("6d53ce510b2e36499b8f56038817b9bad86cabb4", $$ACTION_0); export async function $$ACTION_0() { console.log(1); } export { foo }; -export var bar = createActionProxy("188d5d945750dc32e2c842b93c75a65763d4a922", $$ACTION_1); +export var bar = registerServerReference("188d5d945750dc32e2c842b93c75a65763d4a922", $$ACTION_1); export async function $$ACTION_1() { console.log(2); } -export default createActionProxy("9878bfa39811ca7650992850a8751f9591b6a557", $$ACTION_2); +export default registerServerReference("9878bfa39811ca7650992850a8751f9591b6a557", $$ACTION_2); export async function $$ACTION_2() { console.log(3); } -export const qux = createActionProxy("56a859f462d35a297c46a1bbd1e6a9058c104ab8", $$ACTION_3); +export const qux = registerServerReference("56a859f462d35a297c46a1bbd1e6a9058c104ab8", $$ACTION_3); export async function $$ACTION_3() { console.log(4); } -export const quux = createActionProxy("9c0dd1f7c2b3f41d32e10f5c437de3d67ad32c6c", $$ACTION_4); +export const quux = registerServerReference("9c0dd1f7c2b3f41d32e10f5c437de3d67ad32c6c", $$ACTION_4); export async function $$ACTION_4() { console.log(5); } diff --git a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/28/output.js b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/28/output.js index 4287ca9b2e77e..715b8857175ab 100644 --- a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/28/output.js +++ b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/28/output.js @@ -1,8 +1,8 @@ -/* __next_internal_action_entry_do_not_use__ {"188d5d945750dc32e2c842b93c75a65763d4a922":"$$ACTION_1","6d53ce510b2e36499b8f56038817b9bad86cabb4":"$$ACTION_0","9878bfa39811ca7650992850a8751f9591b6a557":"$$ACTION_2"} */ import { createActionProxy } from "private-next-rsc-action-proxy"; +/* __next_internal_action_entry_do_not_use__ {"188d5d945750dc32e2c842b93c75a65763d4a922":"$$ACTION_1","6d53ce510b2e36499b8f56038817b9bad86cabb4":"$$ACTION_0","9878bfa39811ca7650992850a8751f9591b6a557":"$$ACTION_2"} */ import { registerServerReference } from "private-next-rsc-server-reference"; import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption"; let a, f; function Comp(b, c, ...g) { - return createActionProxy("9878bfa39811ca7650992850a8751f9591b6a557", $$ACTION_2).bind(null, encryptActionBoundArgs("9878bfa39811ca7650992850a8751f9591b6a557", [ + return registerServerReference("9878bfa39811ca7650992850a8751f9591b6a557", $$ACTION_2).bind(null, encryptActionBoundArgs("9878bfa39811ca7650992850a8751f9591b6a557", [ c, g, b @@ -24,7 +24,7 @@ export async function $$ACTION_2($$ACTION_CLOSURE_BOUND, d) { window }); console.log(a, $$ACTION_ARG_2, action2); - var action2 = createActionProxy("6d53ce510b2e36499b8f56038817b9bad86cabb4", $$ACTION_0).bind(null, encryptActionBoundArgs("6d53ce510b2e36499b8f56038817b9bad86cabb4", [ + var action2 = registerServerReference("6d53ce510b2e36499b8f56038817b9bad86cabb4", $$ACTION_0).bind(null, encryptActionBoundArgs("6d53ce510b2e36499b8f56038817b9bad86cabb4", [ $$ACTION_ARG_0, d, f, @@ -32,7 +32,7 @@ export async function $$ACTION_2($$ACTION_CLOSURE_BOUND, d) { ])); return [ action2, - createActionProxy("188d5d945750dc32e2c842b93c75a65763d4a922", $$ACTION_1).bind(null, encryptActionBoundArgs("188d5d945750dc32e2c842b93c75a65763d4a922", [ + registerServerReference("188d5d945750dc32e2c842b93c75a65763d4a922", $$ACTION_1).bind(null, encryptActionBoundArgs("188d5d945750dc32e2c842b93c75a65763d4a922", [ action2, $$ACTION_ARG_0, d diff --git a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/29/output.js b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/29/output.js index 4addc633d84a5..24cbb90c77261 100644 --- a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/29/output.js +++ b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/29/output.js @@ -1,6 +1,6 @@ -/* __next_internal_action_entry_do_not_use__ {"28baf972d345b86b747ad0df73d75a0088a42214":"dec","6d53ce510b2e36499b8f56038817b9bad86cabb4":"$$ACTION_0","c18c215a6b7cdc64bf709f3a714ffdef1bf9651d":"default"} */ import { createActionProxy } from "private-next-rsc-action-proxy"; +/* __next_internal_action_entry_do_not_use__ {"28baf972d345b86b747ad0df73d75a0088a42214":"dec","6d53ce510b2e36499b8f56038817b9bad86cabb4":"$$ACTION_0","c18c215a6b7cdc64bf709f3a714ffdef1bf9651d":"default"} */ import { registerServerReference } from "private-next-rsc-server-reference"; import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption"; -export const dec = createActionProxy("6d53ce510b2e36499b8f56038817b9bad86cabb4", $$ACTION_0); +export const dec = registerServerReference("6d53ce510b2e36499b8f56038817b9bad86cabb4", $$ACTION_0); export async function $$ACTION_0(value) { return value - 1; } @@ -11,5 +11,5 @@ ensureServerEntryExports([ dec, dec ]); -createActionProxy("28baf972d345b86b747ad0df73d75a0088a42214", dec); -createActionProxy("c18c215a6b7cdc64bf709f3a714ffdef1bf9651d", dec); \ No newline at end of file +registerServerReference("28baf972d345b86b747ad0df73d75a0088a42214", dec); +registerServerReference("c18c215a6b7cdc64bf709f3a714ffdef1bf9651d", dec); \ No newline at end of file diff --git a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/3/output.js b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/3/output.js index 7bde2d0604efd..6062a67476b01 100644 --- a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/3/output.js +++ b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/3/output.js @@ -1,5 +1,5 @@ // app/send.ts -/* __next_internal_action_entry_do_not_use__ {"e10665baac148856374b2789aceb970f66fec33e":"myAction"} */ import { createActionProxy } from "private-next-rsc-action-proxy"; +/* __next_internal_action_entry_do_not_use__ {"e10665baac148856374b2789aceb970f66fec33e":"myAction"} */ import { registerServerReference } from "private-next-rsc-server-reference"; import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption"; export async function myAction(a, b, c) { console.log('a'); @@ -8,4 +8,4 @@ import { ensureServerEntryExports } from "private-next-rsc-action-validate"; ensureServerEntryExports([ myAction ]); -createActionProxy("e10665baac148856374b2789aceb970f66fec33e", myAction); +registerServerReference("e10665baac148856374b2789aceb970f66fec33e", myAction); diff --git a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/4/output.js b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/4/output.js index 28bb526dc3754..0e9d3746d2765 100644 --- a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/4/output.js +++ b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/4/output.js @@ -1,4 +1,4 @@ -/* __next_internal_action_entry_do_not_use__ {"1ab723c80dcca470e0410b4b2a2fc2bf21f41476":"c","6d53ce510b2e36499b8f56038817b9bad86cabb4":"$$ACTION_0","6e7bc104e4d6e7fda190c4a51be969cfd0be6d6d":"a","d1f7eb64271d7c601dfef7d4d7053de1c2ca4338":"b"} */ import { registerServerReference } from "private-next-rsc-server-reference"; +/* __next_internal_action_entry_do_not_use__ {"1ab723c80dcca470e0410b4b2a2fc2bf21f41476":"c","6e7bc104e4d6e7fda190c4a51be969cfd0be6d6d":"a","d1f7eb64271d7c601dfef7d4d7053de1c2ca4338":"b"} */ import { registerServerReference } from "private-next-rsc-server-reference"; import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption"; export async function a() {} export async function b() {} @@ -16,4 +16,4 @@ ensureServerEntryExports([ ]); registerServerReference("6e7bc104e4d6e7fda190c4a51be969cfd0be6d6d", a); registerServerReference("d1f7eb64271d7c601dfef7d4d7053de1c2ca4338", b); -registerServerReference("1ab723c80dcca470e0410b4b2a2fc2bf21f41476", c); \ No newline at end of file +registerServerReference("1ab723c80dcca470e0410b4b2a2fc2bf21f41476", c); diff --git a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/5/output.js b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/5/output.js index b2b5eb3c9352c..294e584035451 100644 --- a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/5/output.js +++ b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/5/output.js @@ -1,10 +1,10 @@ -/* __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__ {"6d53ce510b2e36499b8f56038817b9bad86cabb4":"$$ACTION_0"} */ import { registerServerReference } from "private-next-rsc-server-reference"; import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption"; import deleteFromDb from 'db'; const v1 = 'v1'; export function Item({ id1, id2, id3, id4 }) { const v2 = id2; - var deleteItem = createActionProxy("6d53ce510b2e36499b8f56038817b9bad86cabb4", $$ACTION_0).bind(null, encryptActionBoundArgs("6d53ce510b2e36499b8f56038817b9bad86cabb4", [ + var deleteItem = registerServerReference("6d53ce510b2e36499b8f56038817b9bad86cabb4", $$ACTION_0).bind(null, encryptActionBoundArgs("6d53ce510b2e36499b8f56038817b9bad86cabb4", [ id1, v2, id3, diff --git a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/6/output.js b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/6/output.js index 488d0c2c7c2fa..bb1de432edb98 100644 --- a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/6/output.js +++ b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/6/output.js @@ -1,4 +1,4 @@ -/* __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__ {"6d53ce510b2e36499b8f56038817b9bad86cabb4":"$$ACTION_0"} */ import { registerServerReference } from "private-next-rsc-server-reference"; import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption"; import f, { f1, f2 } from 'foo'; const f3 = 1; @@ -19,7 +19,7 @@ export function y(p, [p1, { p2 }], ...p3) { if (true) { const f8 = 1; } - var action = createActionProxy("6d53ce510b2e36499b8f56038817b9bad86cabb4", $$ACTION_0).bind(null, encryptActionBoundArgs("6d53ce510b2e36499b8f56038817b9bad86cabb4", [ + var action = registerServerReference("6d53ce510b2e36499b8f56038817b9bad86cabb4", $$ACTION_0).bind(null, encryptActionBoundArgs("6d53ce510b2e36499b8f56038817b9bad86cabb4", [ f2, f11, p, diff --git a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/7/output.js b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/7/output.js index c4bb17515a058..1a8d3ff5e9cec 100644 --- a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/7/output.js +++ b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/7/output.js @@ -1,8 +1,8 @@ -/* __next_internal_action_entry_do_not_use__ {"188d5d945750dc32e2c842b93c75a65763d4a922":"$$ACTION_1","56a859f462d35a297c46a1bbd1e6a9058c104ab8":"$$ACTION_3","6d53ce510b2e36499b8f56038817b9bad86cabb4":"$$ACTION_0","9c0dd1f7c2b3f41d32e10f5c437de3d67ad32c6c":"$$ACTION_4"} */ import { createActionProxy } from "private-next-rsc-action-proxy"; +/* __next_internal_action_entry_do_not_use__ {"188d5d945750dc32e2c842b93c75a65763d4a922":"$$ACTION_1","56a859f462d35a297c46a1bbd1e6a9058c104ab8":"$$ACTION_3","6d53ce510b2e36499b8f56038817b9bad86cabb4":"$$ACTION_0","9c0dd1f7c2b3f41d32e10f5c437de3d67ad32c6c":"$$ACTION_4"} */ import { registerServerReference } from "private-next-rsc-server-reference"; import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption"; import deleteFromDb from 'db'; export function Item1(product, foo, bar) { - const a = createActionProxy("6d53ce510b2e36499b8f56038817b9bad86cabb4", $$ACTION_0).bind(null, encryptActionBoundArgs("6d53ce510b2e36499b8f56038817b9bad86cabb4", [ + const a = registerServerReference("6d53ce510b2e36499b8f56038817b9bad86cabb4", $$ACTION_0).bind(null, encryptActionBoundArgs("6d53ce510b2e36499b8f56038817b9bad86cabb4", [ product.id, product?.foo, product.bar.baz, @@ -17,7 +17,7 @@ export async function $$ACTION_0($$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) { - var deleteItem2 = createActionProxy("188d5d945750dc32e2c842b93c75a65763d4a922", $$ACTION_1).bind(null, encryptActionBoundArgs("188d5d945750dc32e2c842b93c75a65763d4a922", [ + var deleteItem2 = registerServerReference("188d5d945750dc32e2c842b93c75a65763d4a922", $$ACTION_1).bind(null, encryptActionBoundArgs("188d5d945750dc32e2c842b93c75a65763d4a922", [ product.id, product?.foo, product.bar.baz, @@ -32,7 +32,7 @@ export async function $$ACTION_1($$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", [ + const deleteItem3 = registerServerReference("56a859f462d35a297c46a1bbd1e6a9058c104ab8", $$ACTION_3).bind(null, encryptActionBoundArgs("56a859f462d35a297c46a1bbd1e6a9058c104ab8", [ product.id, product?.foo, product.bar.baz, @@ -47,7 +47,7 @@ export async function $$ACTION_3($$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("9c0dd1f7c2b3f41d32e10f5c437de3d67ad32c6c", $$ACTION_4).bind(null, encryptActionBoundArgs("9c0dd1f7c2b3f41d32e10f5c437de3d67ad32c6c", [ + const deleteItem4 = registerServerReference("9c0dd1f7c2b3f41d32e10f5c437de3d67ad32c6c", $$ACTION_4).bind(null, encryptActionBoundArgs("9c0dd1f7c2b3f41d32e10f5c437de3d67ad32c6c", [ product.id, product?.foo, product.bar.baz, diff --git a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/8/output.js b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/8/output.js index 20cd837d2f823..48ab4c0b8f84e 100644 --- a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/8/output.js +++ b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/8/output.js @@ -1,6 +1,6 @@ -/* __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__ {"6d53ce510b2e36499b8f56038817b9bad86cabb4":"$$ACTION_0"} */ import { registerServerReference } from "private-next-rsc-server-reference"; import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption"; -var myAction = createActionProxy("6d53ce510b2e36499b8f56038817b9bad86cabb4", $$ACTION_0); +var myAction = registerServerReference("6d53ce510b2e36499b8f56038817b9bad86cabb4", $$ACTION_0); export async function $$ACTION_0(a, b, c) { // comment 'use strict'; diff --git a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/9/output.js b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/9/output.js index 9d61cc907880f..f9bf82a68ed6f 100644 --- a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/9/output.js +++ b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/9/output.js @@ -1,5 +1,5 @@ // app/send.ts -/* __next_internal_action_entry_do_not_use__ {"050e3854b72b19e3c7e3966a67535543a90bf7e0":"baz","ab21efdafbe611287bc25c0462b1e0510d13e48b":"foo","c18c215a6b7cdc64bf709f3a714ffdef1bf9651d":"default"} */ import { createActionProxy } from "private-next-rsc-action-proxy"; +/* __next_internal_action_entry_do_not_use__ {"050e3854b72b19e3c7e3966a67535543a90bf7e0":"baz","ab21efdafbe611287bc25c0462b1e0510d13e48b":"foo","c18c215a6b7cdc64bf709f3a714ffdef1bf9651d":"default"} */ import { registerServerReference } from "private-next-rsc-server-reference"; import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption"; async function foo() {} export { foo }; @@ -13,6 +13,6 @@ ensureServerEntryExports([ bar, qux ]); -createActionProxy("ab21efdafbe611287bc25c0462b1e0510d13e48b", foo); -createActionProxy("050e3854b72b19e3c7e3966a67535543a90bf7e0", bar); -createActionProxy("c18c215a6b7cdc64bf709f3a714ffdef1bf9651d", qux); +registerServerReference("ab21efdafbe611287bc25c0462b1e0510d13e48b", foo); +registerServerReference("050e3854b72b19e3c7e3966a67535543a90bf7e0", bar); +registerServerReference("c18c215a6b7cdc64bf709f3a714ffdef1bf9651d", qux); diff --git a/packages/next/src/build/create-compiler-aliases.ts b/packages/next/src/build/create-compiler-aliases.ts index 6687056067525..74686391b9de0 100644 --- a/packages/next/src/build/create-compiler-aliases.ts +++ b/packages/next/src/build/create-compiler-aliases.ts @@ -148,7 +148,7 @@ export function createWebpackAliases({ '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', + 'next/dist/build/webpack/loaders/next-flight-loader/server-reference', [RSC_ACTION_ENCRYPTION_ALIAS]: 'next/dist/server/app-render/action-encryption', diff --git a/packages/next/src/build/handle-externals.ts b/packages/next/src/build/handle-externals.ts index a37f84ad33fbe..b2546b982b5d3 100644 --- a/packages/next/src/build/handle-externals.ts +++ b/packages/next/src/build/handle-externals.ts @@ -197,7 +197,7 @@ export function makeExternalHandler({ } const notExternalModules = - /^(?:private-next-pages\/|next\/(?:dist\/pages\/|(?:app|document|link|image|legacy\/image|constants|dynamic|script|navigation|headers|router)$)|string-hash|private-next-rsc-action-validate|private-next-rsc-action-client-wrapper|private-next-rsc-action-proxy$)/ + /^(?:private-next-pages\/|next\/(?:dist\/pages\/|(?:app|document|link|image|legacy\/image|constants|dynamic|script|navigation|headers|router)$)|string-hash|private-next-rsc-action-validate|private-next-rsc-action-client-wrapper|private-next-rsc-server-reference$)/ if (notExternalModules.test(request)) { return } 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/server-reference.ts similarity index 59% rename from packages/next/src/build/webpack/loaders/next-flight-loader/action-proxy.ts rename to packages/next/src/build/webpack/loaders/next-flight-loader/server-reference.ts index 9e442cfa4effc..52d2f6cab8d3b 100644 --- a/packages/next/src/build/webpack/loaders/next-flight-loader/action-proxy.ts +++ b/packages/next/src/build/webpack/loaders/next-flight-loader/server-reference.ts @@ -1,5 +1,5 @@ /* eslint-disable import/no-extraneous-dependencies */ -import { registerServerReference } from 'react-server-dom-webpack/server.edge' +import { registerServerReference as flightRegisterServerReference } from 'react-server-dom-webpack/server.edge' const SERVER_REFERENCE_TAG = Symbol.for('react.server.reference') @@ -7,11 +7,11 @@ function isServerReference(reference: any) { return reference && reference.$$typeof === SERVER_REFERENCE_TAG } -export function createActionProxy(id: string, action: any) { +export function registerServerReference(id: string, action: any) { // Avoid registering the same action twice if (isServerReference(action)) { return action } - return registerServerReference(action, id, null) + return flightRegisterServerReference(action, id, null) } diff --git a/packages/next/src/lib/constants.ts b/packages/next/src/lib/constants.ts index 6836627b1bc00..7c958fedc6c5b 100644 --- a/packages/next/src/lib/constants.ts +++ b/packages/next/src/lib/constants.ts @@ -40,7 +40,7 @@ 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_PROXY_ALIAS = 'private-next-rsc-server-reference' export const RSC_ACTION_ENCRYPTION_ALIAS = 'private-next-rsc-action-encryption' export const RSC_ACTION_CLIENT_WRAPPER_ALIAS = 'private-next-rsc-action-client-wrapper' From c1eb8aafe301b8874bd848e9de6b860887e25dcc Mon Sep 17 00:00:00 2001 From: JJ Kasper Date: Wed, 28 Feb 2024 14:03:19 -0800 Subject: [PATCH 09/10] update snapshot --- .../tests/fixture/server-actions/server/4/output.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/4/output.js b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/4/output.js index 0e9d3746d2765..fcabff24f65b1 100644 --- a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/4/output.js +++ b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/4/output.js @@ -1,4 +1,4 @@ -/* __next_internal_action_entry_do_not_use__ {"1ab723c80dcca470e0410b4b2a2fc2bf21f41476":"c","6e7bc104e4d6e7fda190c4a51be969cfd0be6d6d":"a","d1f7eb64271d7c601dfef7d4d7053de1c2ca4338":"b"} */ import { registerServerReference } from "private-next-rsc-server-reference"; +/* __next_internal_action_entry_do_not_use__ {"1ab723c80dcca470e0410b4b2a2fc2bf21f41476":"c","6d53ce510b2e36499b8f56038817b9bad86cabb4":"$$ACTION_0","6e7bc104e4d6e7fda190c4a51be969cfd0be6d6d":"a","d1f7eb64271d7c601dfef7d4d7053de1c2ca4338":"b"} */ import { registerServerReference } from "private-next-rsc-server-reference"; import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption"; export async function a() {} export async function b() {} From 57c0a496a12172aa6f64a18e1e12da474ad300e3 Mon Sep 17 00:00:00 2001 From: JJ Kasper Date: Wed, 28 Feb 2024 14:30:48 -0800 Subject: [PATCH 10/10] fix test --- test/e2e/switchable-runtime/index.test.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/test/e2e/switchable-runtime/index.test.ts b/test/e2e/switchable-runtime/index.test.ts index 0745a41a80746..f88ccf1045261 100644 --- a/test/e2e/switchable-runtime/index.test.ts +++ b/test/e2e/switchable-runtime/index.test.ts @@ -189,7 +189,6 @@ describe('Switchable runtime', () => { '/api/hello': { files: expect.arrayContaining([ 'server/edge-runtime-webpack.js', - 'server/edge-chunks/189.js', 'server/pages/api/hello.js', ]), name: 'pages/api/hello',