diff --git a/crates/next-custom-transforms/src/transforms/server_actions.rs b/crates/next-custom-transforms/src/transforms/server_actions.rs index adb4096f462ba5..baf839630c2923 100644 --- a/crates/next-custom-transforms/src/transforms/server_actions.rs +++ b/crates/next-custom-transforms/src/transforms/server_actions.rs @@ -352,12 +352,6 @@ impl ServerActions { id } - fn gen_ref_ident(&mut self) -> Atom { - let id: Atom = format!("$$RSC_SERVER_REF_{0}", self.reference_index).into(); - self.reference_index += 1; - id - } - fn create_bound_action_args_array_pat(&mut self, arg_len: usize) -> Pat { Pat::Array(ArrayPat { span: DUMMY_SP, @@ -467,16 +461,6 @@ impl ServerActions { self.export_actions .push((action_name.clone(), action_id.clone())); - let register_action_expr = bind_args_to_ref_expr( - annotate_ident_as_server_reference(action_ident.clone(), action_id.clone(), arrow.span), - ids_from_closure - .iter() - .cloned() - .map(|id| Some(id.as_arg())) - .collect(), - action_id.clone(), - ); - if let BlockStmtOrExpr::BlockStmt(block) = &mut *arrow.body { block.visit_mut_with(&mut ClosureReplacer { used_ids: &ids_from_closure, @@ -503,7 +487,7 @@ impl ServerActions { span: DUMMY_SP, callee: quote_ident!("decryptActionBoundArgs").as_callee(), args: vec![ - action_id.as_arg(), + action_id.clone().as_arg(), quote_ident!("$$ACTION_CLOSURE_BOUND").as_arg(), ], ..Default::default() @@ -575,7 +559,29 @@ impl ServerActions { .into(), }))); - Box::new(register_action_expr.clone()) + self.hoisted_extra_items + .push(ModuleItem::Stmt(Stmt::Expr(ExprStmt { + span: DUMMY_SP, + expr: Box::new(annotate_ident_as_server_reference( + action_ident.clone(), + action_id.clone(), + arrow.span, + )), + }))); + + if ids_from_closure.is_empty() { + Box::new(action_ident.clone().into()) + } else { + Box::new(bind_args_to_ident( + action_ident.clone(), + ids_from_closure + .iter() + .cloned() + .map(|id| Some(id.as_arg())) + .collect(), + action_id.clone(), + )) + } } fn maybe_hoist_and_create_proxy_for_server_action_function( @@ -609,20 +615,6 @@ impl ServerActions { self.export_actions .push((action_name.clone(), action_id.clone())); - let register_action_expr = bind_args_to_ref_expr( - annotate_ident_as_server_reference( - action_ident.clone(), - action_id.clone(), - function.span, - ), - ids_from_closure - .iter() - .cloned() - .map(|id| Some(id.as_arg())) - .collect(), - action_id.clone(), - ); - function.body.visit_mut_with(&mut ClosureReplacer { used_ids: &ids_from_closure, private_ctxt: self.private_ctxt, @@ -646,7 +638,7 @@ impl ServerActions { span: DUMMY_SP, callee: quote_ident!("decryptActionBoundArgs").as_callee(), args: vec![ - action_id.as_arg(), + action_id.clone().as_arg(), quote_ident!("$$ACTION_CLOSURE_BOUND").as_arg(), ], ..Default::default() @@ -695,7 +687,29 @@ impl ServerActions { .into(), }))); - Box::new(register_action_expr) + self.hoisted_extra_items + .push(ModuleItem::Stmt(Stmt::Expr(ExprStmt { + span: DUMMY_SP, + expr: Box::new(annotate_ident_as_server_reference( + action_ident.clone(), + action_id.clone(), + function.span, + )), + }))); + + if ids_from_closure.is_empty() { + Box::new(action_ident.clone().into()) + } else { + Box::new(bind_args_to_ident( + action_ident.clone(), + ids_from_closure + .iter() + .cloned() + .map(|id| Some(id.as_arg())) + .collect(), + action_id.clone(), + )) + } } fn maybe_hoist_and_create_proxy_for_cache_arrow_expr( @@ -783,6 +797,16 @@ impl ServerActions { .into(), }))); + self.hoisted_extra_items + .push(ModuleItem::Stmt(Stmt::Expr(ExprStmt { + span: DUMMY_SP, + expr: Box::new(annotate_ident_as_server_reference( + cache_ident.clone(), + reference_id.clone(), + arrow.span, + )), + }))); + if let Some(Ident { sym, .. }) = &self.arrow_or_fn_expr_ident { assign_name_to_ident(&cache_ident, sym.as_str(), &mut self.hoisted_extra_items); } @@ -793,41 +817,14 @@ impl ServerActions { .map(|id| Some(id.as_arg())) .collect(); - let register_action_expr = annotate_ident_as_server_reference( - cache_ident.clone(), - reference_id.clone(), - arrow.span, - ); - - // If there're any bound args from the closure, we need to hoist the - // register action expression to the top-level, and return the bind - // expression inline. - if !bound_args.is_empty() { - let ref_ident = private_ident!(self.gen_ref_ident()); - - let ref_decl = VarDecl { - span: DUMMY_SP, - kind: VarDeclKind::Var, - decls: vec![VarDeclarator { - span: DUMMY_SP, - name: Pat::Ident(ref_ident.clone().into()), - init: Some(Box::new(register_action_expr.clone())), - definite: false, - }], - ..Default::default() - }; - - // Hoist the register action expression to the top-level. - self.extra_items - .push(ModuleItem::Stmt(Stmt::Decl(Decl::Var(Box::new(ref_decl))))); - - Box::new(bind_args_to_ref_expr( - Expr::Ident(ref_ident.clone()), + if bound_args.is_empty() { + Box::new(cache_ident.clone().into()) + } else { + Box::new(bind_args_to_ident( + cache_ident.clone(), bound_args, reference_id.clone(), )) - } else { - Box::new(register_action_expr) } } @@ -864,12 +861,6 @@ impl ServerActions { self.export_actions .push((cache_name.clone(), reference_id.clone())); - let register_action_expr = annotate_ident_as_server_reference( - cache_ident.clone(), - reference_id.clone(), - function.span, - ); - function.body.visit_mut_with(&mut ClosureReplacer { used_ids: &ids_from_closure, private_ctxt: self.private_ctxt, @@ -904,6 +895,16 @@ impl ServerActions { .into(), }))); + self.hoisted_extra_items + .push(ModuleItem::Stmt(Stmt::Expr(ExprStmt { + span: DUMMY_SP, + expr: Box::new(annotate_ident_as_server_reference( + cache_ident.clone(), + reference_id.clone(), + function.span, + )), + }))); + if let Some(Ident { sym, .. }) = fn_name { assign_name_to_ident(&cache_ident, sym.as_str(), &mut self.hoisted_extra_items); } else if self.in_default_export_decl { @@ -916,35 +917,14 @@ impl ServerActions { .map(|id| Some(id.as_arg())) .collect(); - // If there're any bound args from the closure, we need to hoist the - // register action expression to the top-level, and return the bind - // expression inline. - if !bound_args.is_empty() { - let ref_ident = private_ident!(self.gen_ref_ident()); - - let ref_decl = VarDecl { - span: DUMMY_SP, - kind: VarDeclKind::Var, - decls: vec![VarDeclarator { - span: DUMMY_SP, - name: Pat::Ident(ref_ident.clone().into()), - init: Some(Box::new(register_action_expr.clone())), - definite: false, - }], - ..Default::default() - }; - - // Hoist the register action expression to the top-level. - self.extra_items - .push(ModuleItem::Stmt(Stmt::Decl(Decl::Var(Box::new(ref_decl))))); - - Box::new(bind_args_to_ref_expr( - Expr::Ident(ref_ident.clone()), + if bound_args.is_empty() { + Box::new(cache_ident.clone().into()) + } else { + Box::new(bind_args_to_ident( + cache_ident.clone(), bound_args, reference_id.clone(), )) - } else { - Box::new(register_action_expr) } } } @@ -2465,42 +2445,38 @@ fn annotate_ident_as_server_reference(ident: Ident, action_id: Atom, original_sp }) } -fn bind_args_to_ref_expr(expr: Expr, bound: Vec>, action_id: Atom) -> Expr { - if bound.is_empty() { - expr - } else { - // expr.bind(null, [encryptActionBoundArgs("id", arg1, arg2, ...)]) - Expr::Call(CallExpr { +fn bind_args_to_ident(ident: Ident, bound: Vec>, action_id: Atom) -> Expr { + // ident.bind(null, [encryptActionBoundArgs("id", arg1, arg2, ...)]) + Expr::Call(CallExpr { + span: DUMMY_SP, + callee: Expr::Member(MemberExpr { span: DUMMY_SP, - callee: Expr::Member(MemberExpr { - span: DUMMY_SP, - obj: Box::new(expr), - prop: MemberProp::Ident(quote_ident!("bind")), - }) - .as_callee(), - args: vec![ - ExprOrSpread { - spread: None, - expr: Box::new(Expr::Lit(Lit::Null(Null { span: DUMMY_SP }))), - }, - ExprOrSpread { - spread: None, - expr: Box::new(Expr::Call(CallExpr { - span: DUMMY_SP, - callee: quote_ident!("encryptActionBoundArgs").as_callee(), - args: std::iter::once(ExprOrSpread { - spread: None, - expr: Box::new(action_id.into()), - }) - .chain(bound.into_iter().flatten()) - .collect(), - ..Default::default() - })), - }, - ], - ..Default::default() + obj: Box::new(ident.into()), + prop: MemberProp::Ident(quote_ident!("bind")), }) - } + .as_callee(), + args: vec![ + ExprOrSpread { + spread: None, + expr: Box::new(Expr::Lit(Lit::Null(Null { span: DUMMY_SP }))), + }, + ExprOrSpread { + spread: None, + expr: Box::new(Expr::Call(CallExpr { + span: DUMMY_SP, + callee: quote_ident!("encryptActionBoundArgs").as_callee(), + args: std::iter::once(ExprOrSpread { + spread: None, + expr: Box::new(action_id.into()), + }) + .chain(bound.into_iter().flatten()) + .collect(), + ..Default::default() + })), + }, + ], + ..Default::default() + }) } // Detects if two strings are similar (but not the same). diff --git a/crates/next-custom-transforms/tests/errors/server-actions/server-graph/8/output.js b/crates/next-custom-transforms/tests/errors/server-actions/server-graph/8/output.js index 52754aa562f9f3..13f6ad1f1a4011 100644 --- a/crates/next-custom-transforms/tests/errors/server-actions/server-graph/8/output.js +++ b/crates/next-custom-transforms/tests/errors/server-actions/server-graph/8/output.js @@ -3,7 +3,8 @@ import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc export const $$RSC_SERVER_ACTION_0 = async function foo() { 'use strict'; }; -const foo = registerServerReference($$RSC_SERVER_ACTION_0, "006a88810ecce4a4e8b59d53b8327d7e98bbf251d7", null); +registerServerReference($$RSC_SERVER_ACTION_0, "006a88810ecce4a4e8b59d53b8327d7e98bbf251d7", null); +const foo = $$RSC_SERVER_ACTION_0; const bar = async ()=>{ const x = 1; // prettier-ignore diff --git a/crates/next-custom-transforms/tests/fixture/next-font-with-directive/use-cache/output.js b/crates/next-custom-transforms/tests/fixture/next-font-with-directive/use-cache/output.js index 6a0caf7a40e969..6fd4ffd10ac180 100644 --- a/crates/next-custom-transforms/tests/fixture/next-font-with-directive/use-cache/output.js +++ b/crates/next-custom-transforms/tests/fixture/next-font-with-directive/use-cache/output.js @@ -6,8 +6,9 @@ import inter from '@next/font/google/target.css?{"path":"app/test.tsx","import": export var $$RSC_SERVER_CACHE_0 = $$cache__("default", "c0dd5bb6fef67f5ab84327f5164ac2c3111a159337", 0, async function Cached({ children }) { return
{children}
; }); +registerServerReference($$RSC_SERVER_CACHE_0, "c0dd5bb6fef67f5ab84327f5164ac2c3111a159337", null); Object["defineProperty"]($$RSC_SERVER_CACHE_0, "name", { value: "Cached", writable: false }); -export var Cached = registerServerReference($$RSC_SERVER_CACHE_0, "c0dd5bb6fef67f5ab84327f5164ac2c3111a159337", null); +export var Cached = $$RSC_SERVER_CACHE_0; diff --git a/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/1/output.js b/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/1/output.js index b4a5289cb8a8ed..1432f4825f90bc 100644 --- a/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/1/output.js +++ b/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/1/output.js @@ -7,8 +7,9 @@ export const $$RSC_SERVER_ACTION_0 = async function deleteItem($$ACTION_CLOSURE_ await deleteFromDb($$ACTION_ARG_0); await deleteFromDb($$ACTION_ARG_1); }; +registerServerReference($$RSC_SERVER_ACTION_0, "406a88810ecce4a4e8b59d53b8327d7e98bbf251d7", null); export function Item({ id1, id2 }) { - var deleteItem = registerServerReference($$RSC_SERVER_ACTION_0, "406a88810ecce4a4e8b59d53b8327d7e98bbf251d7", null).bind(null, encryptActionBoundArgs("406a88810ecce4a4e8b59d53b8327d7e98bbf251d7", id1, id2)); + var deleteItem = $$RSC_SERVER_ACTION_0.bind(null, encryptActionBoundArgs("406a88810ecce4a4e8b59d53b8327d7e98bbf251d7", id1, id2)); return ; } export const $$RSC_SERVER_ACTION_1 = async function action($$ACTION_CLOSURE_BOUND) { @@ -16,11 +17,12 @@ export const $$RSC_SERVER_ACTION_1 = async function action($$ACTION_CLOSURE_BOUN console.log($$ACTION_ARG_0); console.log($$ACTION_ARG_1); }; +registerServerReference($$RSC_SERVER_ACTION_1, "4090b5db271335765a4b0eab01f044b381b5ebd5cd", null); export default function Home() { const info = { name: 'John', test: 'test' }; - const action = registerServerReference($$RSC_SERVER_ACTION_1, "4090b5db271335765a4b0eab01f044b381b5ebd5cd", null).bind(null, encryptActionBoundArgs("4090b5db271335765a4b0eab01f044b381b5ebd5cd", info.name, info.test)); + const action = $$RSC_SERVER_ACTION_1.bind(null, encryptActionBoundArgs("4090b5db271335765a4b0eab01f044b381b5ebd5cd", info.name, info.test)); return null; } diff --git a/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/16/output.js b/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/16/output.js index f045a7d19f5bf0..afe737df3456e0 100644 --- a/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/16/output.js +++ b/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/16/output.js @@ -9,17 +9,19 @@ export const $$RSC_SERVER_ACTION_0 = async function deleteItem($$ACTION_CLOSURE_ await deleteFromDb(v1); await deleteFromDb($$ACTION_ARG_1); }; +registerServerReference($$RSC_SERVER_ACTION_0, "406a88810ecce4a4e8b59d53b8327d7e98bbf251d7", null); export function Item({ id1, id2 }) { const v2 = id2; - const deleteItem = registerServerReference($$RSC_SERVER_ACTION_0, "406a88810ecce4a4e8b59d53b8327d7e98bbf251d7", null).bind(null, encryptActionBoundArgs("406a88810ecce4a4e8b59d53b8327d7e98bbf251d7", id1, v2)); + const deleteItem = $$RSC_SERVER_ACTION_0.bind(null, encryptActionBoundArgs("406a88810ecce4a4e8b59d53b8327d7e98bbf251d7", id1, v2)); return ; } export const $$RSC_SERVER_ACTION_1 = async function g($$ACTION_CLOSURE_BOUND, y, ...z) { var [$$ACTION_ARG_0] = await decryptActionBoundArgs("7f90b5db271335765a4b0eab01f044b381b5ebd5cd", $$ACTION_CLOSURE_BOUND); return $$ACTION_ARG_0 + y + z[0]; }; +registerServerReference($$RSC_SERVER_ACTION_1, "7f90b5db271335765a4b0eab01f044b381b5ebd5cd", null); let f = (x)=>{ - var g = registerServerReference($$RSC_SERVER_ACTION_1, "7f90b5db271335765a4b0eab01f044b381b5ebd5cd", null).bind(null, encryptActionBoundArgs("7f90b5db271335765a4b0eab01f044b381b5ebd5cd", x)); + var g = $$RSC_SERVER_ACTION_1.bind(null, encryptActionBoundArgs("7f90b5db271335765a4b0eab01f044b381b5ebd5cd", x)); }; export const $$RSC_SERVER_ACTION_2 = async function f($$ACTION_CLOSURE_BOUND, y, ...z) { var [$$ACTION_ARG_0] = await decryptActionBoundArgs("7f1c36b06e398c97abe5d5d7ae8c672bfddf4e1b91", $$ACTION_CLOSURE_BOUND); @@ -29,6 +31,7 @@ export const $$RSC_SERVER_ACTION_2 = async function f($$ACTION_CLOSURE_BOUND, y, // @ts-ignore: incompatible argument types z[0]; }; +registerServerReference($$RSC_SERVER_ACTION_2, "7f1c36b06e398c97abe5d5d7ae8c672bfddf4e1b91", null); const g = (x)=>{ - f = registerServerReference($$RSC_SERVER_ACTION_2, "7f1c36b06e398c97abe5d5d7ae8c672bfddf4e1b91", null).bind(null, encryptActionBoundArgs("7f1c36b06e398c97abe5d5d7ae8c672bfddf4e1b91", x)); + f = $$RSC_SERVER_ACTION_2.bind(null, encryptActionBoundArgs("7f1c36b06e398c97abe5d5d7ae8c672bfddf4e1b91", x)); }; diff --git a/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/18/output.js b/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/18/output.js index e513f7cbe7a2a8..2f097649c261f4 100644 --- a/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/18/output.js +++ b/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/18/output.js @@ -9,19 +9,21 @@ export const $$RSC_SERVER_ACTION_0 = async function action($$ACTION_CLOSURE_BOUN await deleteFromDb(v1); await deleteFromDb($$ACTION_ARG_1); }; +registerServerReference($$RSC_SERVER_ACTION_0, "406a88810ecce4a4e8b59d53b8327d7e98bbf251d7", null); export const $$RSC_SERVER_ACTION_1 = async function action($$ACTION_CLOSURE_BOUND) { var [$$ACTION_ARG_0, $$ACTION_ARG_1] = await decryptActionBoundArgs("4090b5db271335765a4b0eab01f044b381b5ebd5cd", $$ACTION_CLOSURE_BOUND); await deleteFromDb($$ACTION_ARG_0); await deleteFromDb(v1); await deleteFromDb($$ACTION_ARG_1); }; +registerServerReference($$RSC_SERVER_ACTION_1, "4090b5db271335765a4b0eab01f044b381b5ebd5cd", null); export function Item({ id1, id2 }) { const v2 = id2; return <> - - ; diff --git a/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/19/output.js b/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/19/output.js index 32f758bcf9a50a..790dab5a61566c 100644 --- a/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/19/output.js +++ b/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/19/output.js @@ -5,9 +5,10 @@ export const $$RSC_SERVER_ACTION_0 = async function action($$ACTION_CLOSURE_BOUN var [$$ACTION_ARG_0] = await decryptActionBoundArgs("606a88810ecce4a4e8b59d53b8327d7e98bbf251d7", $$ACTION_CLOSURE_BOUND); return $$ACTION_ARG_0 * value2; }; +registerServerReference($$RSC_SERVER_ACTION_0, "606a88810ecce4a4e8b59d53b8327d7e98bbf251d7", null); export function Item({ value }) { return <> - ; diff --git a/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/2/output.js b/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/2/output.js index cf11766429e9c7..2df4727280818a 100644 --- a/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/2/output.js +++ b/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/2/output.js @@ -5,10 +5,12 @@ import { Button } from 'components'; export const $$RSC_SERVER_ACTION_0 = async function myAction(a, b, c) { console.log('a'); }; -var myAction = registerServerReference($$RSC_SERVER_ACTION_0, "706a88810ecce4a4e8b59d53b8327d7e98bbf251d7", null); +registerServerReference($$RSC_SERVER_ACTION_0, "706a88810ecce4a4e8b59d53b8327d7e98bbf251d7", null); +var myAction = $$RSC_SERVER_ACTION_0; export default function Page() { return ; } export const $$RSC_SERVER_ACTION_1 = async function() {}; +registerServerReference($$RSC_SERVER_ACTION_1, "0090b5db271335765a4b0eab01f044b381b5ebd5cd", null); // TODO: should use `action` as function name? -export const action = validator(registerServerReference($$RSC_SERVER_ACTION_1, "0090b5db271335765a4b0eab01f044b381b5ebd5cd", null)); +export const action = validator($$RSC_SERVER_ACTION_1); diff --git a/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/21/output.js b/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/21/output.js index 9e7ded83cc3eb7..9e9d48e65a27ce 100644 --- a/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/21/output.js +++ b/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/21/output.js @@ -7,12 +7,15 @@ export const $$RSC_SERVER_ACTION_0 = async function($$ACTION_CLOSURE_BOUND, z) { var [$$ACTION_ARG_0] = await decryptActionBoundArgs("606a88810ecce4a4e8b59d53b8327d7e98bbf251d7", $$ACTION_CLOSURE_BOUND); return x + $$ACTION_ARG_0 + z; }; +registerServerReference($$RSC_SERVER_ACTION_0, "606a88810ecce4a4e8b59d53b8327d7e98bbf251d7", null); export default function Page() { const y = 1; return ; })(); - var deleteItem = registerServerReference($$RSC_SERVER_ACTION_0, "406a88810ecce4a4e8b59d53b8327d7e98bbf251d7", null).bind(null, encryptActionBoundArgs("406a88810ecce4a4e8b59d53b8327d7e98bbf251d7", id1, id2)); + var deleteItem = $$RSC_SERVER_ACTION_0.bind(null, encryptActionBoundArgs("406a88810ecce4a4e8b59d53b8327d7e98bbf251d7", id1, id2)); } export const // FIXME: invalid transformation of hoisted functions (https://github.com/vercel/next.js/issues/57392) // (remove output.js from `tsconfig.json#exclude` to see the error) @@ -22,6 +23,7 @@ $$RSC_SERVER_ACTION_1 = async function deleteItem($$ACTION_CLOSURE_BOUND) { await deleteFromDb($$ACTION_ARG_0); await deleteFromDb($$ACTION_ARG_1); }; +registerServerReference($$RSC_SERVER_ACTION_1, "4090b5db271335765a4b0eab01f044b381b5ebd5cd", null); // In this example, if Button immediately executes the action, different ids should // be passed. export function Item2({ id1, id2 }) { @@ -31,5 +33,5 @@ export function Item2({ id1, id2 }) { id1++; temp.push(); return temp; - var deleteItem = registerServerReference($$RSC_SERVER_ACTION_1, "4090b5db271335765a4b0eab01f044b381b5ebd5cd", null).bind(null, encryptActionBoundArgs("4090b5db271335765a4b0eab01f044b381b5ebd5cd", id1, id2)); + var deleteItem = $$RSC_SERVER_ACTION_1.bind(null, encryptActionBoundArgs("4090b5db271335765a4b0eab01f044b381b5ebd5cd", id1, id2)); } diff --git a/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/26/output.js b/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/26/output.js index 91e265804cbb6d..22e34cd54bcb79 100644 --- a/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/26/output.js +++ b/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/26/output.js @@ -4,5 +4,6 @@ const noop = (action)=>action; export const $$RSC_SERVER_ACTION_0 = async function(data) { console.log(data); }; +registerServerReference($$RSC_SERVER_ACTION_0, "406a88810ecce4a4e8b59d53b8327d7e98bbf251d7", null); // TODO: should use `log` as function name? -export const log = noop(registerServerReference($$RSC_SERVER_ACTION_0, "406a88810ecce4a4e8b59d53b8327d7e98bbf251d7", null)); +export const log = noop($$RSC_SERVER_ACTION_0); diff --git a/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/27/output.js b/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/27/output.js index 1c4ba8e67eab93..c45fafdd50528d 100644 --- a/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/27/output.js +++ b/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/27/output.js @@ -6,21 +6,26 @@ import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc export const $$RSC_SERVER_ACTION_0 = async function foo() { console.log(1); }; -var foo = registerServerReference($$RSC_SERVER_ACTION_0, "006a88810ecce4a4e8b59d53b8327d7e98bbf251d7", null); +registerServerReference($$RSC_SERVER_ACTION_0, "006a88810ecce4a4e8b59d53b8327d7e98bbf251d7", null); +var foo = $$RSC_SERVER_ACTION_0; export { foo }; export const $$RSC_SERVER_ACTION_1 = async function bar() { console.log(2); }; -export var bar = registerServerReference($$RSC_SERVER_ACTION_1, "0090b5db271335765a4b0eab01f044b381b5ebd5cd", null); +registerServerReference($$RSC_SERVER_ACTION_1, "0090b5db271335765a4b0eab01f044b381b5ebd5cd", null); +export var bar = $$RSC_SERVER_ACTION_1; export const $$RSC_SERVER_ACTION_2 = async function baz() { console.log(3); }; -export default registerServerReference($$RSC_SERVER_ACTION_2, "001c36b06e398c97abe5d5d7ae8c672bfddf4e1b91", null); +registerServerReference($$RSC_SERVER_ACTION_2, "001c36b06e398c97abe5d5d7ae8c672bfddf4e1b91", null); +export default $$RSC_SERVER_ACTION_2; export const $$RSC_SERVER_ACTION_3 = async function qux() { console.log(4); }; -export const qux = registerServerReference($$RSC_SERVER_ACTION_3, "009ed0cc47abc4e1c64320cf42b74ae60b58c40f00", null); +registerServerReference($$RSC_SERVER_ACTION_3, "009ed0cc47abc4e1c64320cf42b74ae60b58c40f00", null); +export const qux = $$RSC_SERVER_ACTION_3; export const $$RSC_SERVER_ACTION_4 = async function quuux() { console.log(5); }; -export const quux = registerServerReference($$RSC_SERVER_ACTION_4, "00a9b2939c1f39073a6bed227fd20233064c8b7869", null); +registerServerReference($$RSC_SERVER_ACTION_4, "00a9b2939c1f39073a6bed227fd20233064c8b7869", null); +export const quux = $$RSC_SERVER_ACTION_4; diff --git a/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/28/output.js b/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/28/output.js index 7ba65366426587..fc419fbf7d9cd0 100644 --- a/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/28/output.js +++ b/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/28/output.js @@ -7,11 +7,13 @@ $$RSC_SERVER_ACTION_0 = async function action2($$ACTION_CLOSURE_BOUND, e) { var [$$ACTION_ARG_0, $$ACTION_ARG_1, $$ACTION_ARG_2, $$ACTION_ARG_3] = await decryptActionBoundArgs("606a88810ecce4a4e8b59d53b8327d7e98bbf251d7", $$ACTION_CLOSURE_BOUND); console.log(a, $$ACTION_ARG_0, $$ACTION_ARG_1, e, $$ACTION_ARG_2, $$ACTION_ARG_3); }; +registerServerReference($$RSC_SERVER_ACTION_0, "606a88810ecce4a4e8b59d53b8327d7e98bbf251d7", null); export const $$RSC_SERVER_ACTION_1 = async function action3($$ACTION_CLOSURE_BOUND, e) { var [$$ACTION_ARG_0, $$ACTION_ARG_1, $$ACTION_ARG_2] = await decryptActionBoundArgs("6090b5db271335765a4b0eab01f044b381b5ebd5cd", $$ACTION_CLOSURE_BOUND); $$ACTION_ARG_0(e); console.log(a, $$ACTION_ARG_1, $$ACTION_ARG_2, e); }; +registerServerReference($$RSC_SERVER_ACTION_1, "6090b5db271335765a4b0eab01f044b381b5ebd5cd", null); export const $$RSC_SERVER_ACTION_2 = async function action1($$ACTION_CLOSURE_BOUND, d) { var [$$ACTION_ARG_0, $$ACTION_ARG_1, $$ACTION_ARG_2] = await decryptActionBoundArgs("601c36b06e398c97abe5d5d7ae8c672bfddf4e1b91", $$ACTION_CLOSURE_BOUND); let f; @@ -20,12 +22,13 @@ export const $$RSC_SERVER_ACTION_2 = async function action1($$ACTION_CLOSURE_BOU window }); console.log(a, $$ACTION_ARG_0, action2); - var action2 = registerServerReference($$RSC_SERVER_ACTION_0, "606a88810ecce4a4e8b59d53b8327d7e98bbf251d7", null).bind(null, encryptActionBoundArgs("606a88810ecce4a4e8b59d53b8327d7e98bbf251d7", $$ACTION_ARG_1, d, f, $$ACTION_ARG_2)); + var action2 = $$RSC_SERVER_ACTION_0.bind(null, encryptActionBoundArgs("606a88810ecce4a4e8b59d53b8327d7e98bbf251d7", $$ACTION_ARG_1, d, f, $$ACTION_ARG_2)); return [ action2, - registerServerReference($$RSC_SERVER_ACTION_1, "6090b5db271335765a4b0eab01f044b381b5ebd5cd", null).bind(null, encryptActionBoundArgs("6090b5db271335765a4b0eab01f044b381b5ebd5cd", action2, $$ACTION_ARG_1, d)) + $$RSC_SERVER_ACTION_1.bind(null, encryptActionBoundArgs("6090b5db271335765a4b0eab01f044b381b5ebd5cd", action2, $$ACTION_ARG_1, d)) ]; }; +registerServerReference($$RSC_SERVER_ACTION_2, "601c36b06e398c97abe5d5d7ae8c672bfddf4e1b91", null); function Comp(b, c, ...g) { - return registerServerReference($$RSC_SERVER_ACTION_2, "601c36b06e398c97abe5d5d7ae8c672bfddf4e1b91", null).bind(null, encryptActionBoundArgs("601c36b06e398c97abe5d5d7ae8c672bfddf4e1b91", b, c, g)); + return $$RSC_SERVER_ACTION_2.bind(null, encryptActionBoundArgs("601c36b06e398c97abe5d5d7ae8c672bfddf4e1b91", b, c, g)); } diff --git a/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/30/output.js b/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/30/output.js index 03342d56de7ed4..1b77b56e114ec2 100644 --- a/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/30/output.js +++ b/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/30/output.js @@ -7,11 +7,13 @@ $$RSC_SERVER_ACTION_0 = async function action2($$ACTION_CLOSURE_BOUND, e) { var [$$ACTION_ARG_0, $$ACTION_ARG_1, $$ACTION_ARG_2, $$ACTION_ARG_3] = await decryptActionBoundArgs("606a88810ecce4a4e8b59d53b8327d7e98bbf251d7", $$ACTION_CLOSURE_BOUND); console.log(a, $$ACTION_ARG_0, $$ACTION_ARG_1, e, $$ACTION_ARG_2, $$ACTION_ARG_3); }; +registerServerReference($$RSC_SERVER_ACTION_0, "606a88810ecce4a4e8b59d53b8327d7e98bbf251d7", null); export const $$RSC_SERVER_ACTION_1 = async function action3($$ACTION_CLOSURE_BOUND, e) { var [$$ACTION_ARG_0, $$ACTION_ARG_1, $$ACTION_ARG_2] = await decryptActionBoundArgs("6090b5db271335765a4b0eab01f044b381b5ebd5cd", $$ACTION_CLOSURE_BOUND); $$ACTION_ARG_0(e); console.log(a, $$ACTION_ARG_1, $$ACTION_ARG_2, e); }; +registerServerReference($$RSC_SERVER_ACTION_1, "6090b5db271335765a4b0eab01f044b381b5ebd5cd", null); export const $$RSC_SERVER_ACTION_2 = async function action1($$ACTION_CLOSURE_BOUND, d) { var [$$ACTION_ARG_0, $$ACTION_ARG_1, $$ACTION_ARG_2] = await decryptActionBoundArgs("601c36b06e398c97abe5d5d7ae8c672bfddf4e1b91", $$ACTION_CLOSURE_BOUND); let f; @@ -20,14 +22,15 @@ export const $$RSC_SERVER_ACTION_2 = async function action1($$ACTION_CLOSURE_BOU window }); console.log(a, $$ACTION_ARG_0, action2); - var action2 = registerServerReference($$RSC_SERVER_ACTION_0, "606a88810ecce4a4e8b59d53b8327d7e98bbf251d7", null).bind(null, encryptActionBoundArgs("606a88810ecce4a4e8b59d53b8327d7e98bbf251d7", $$ACTION_ARG_1, d, f, $$ACTION_ARG_2)); + var action2 = $$RSC_SERVER_ACTION_0.bind(null, encryptActionBoundArgs("606a88810ecce4a4e8b59d53b8327d7e98bbf251d7", $$ACTION_ARG_1, d, f, $$ACTION_ARG_2)); return [ action2, - registerServerReference($$RSC_SERVER_ACTION_1, "6090b5db271335765a4b0eab01f044b381b5ebd5cd", null).bind(null, encryptActionBoundArgs("6090b5db271335765a4b0eab01f044b381b5ebd5cd", action2, $$ACTION_ARG_1, d)) + $$RSC_SERVER_ACTION_1.bind(null, encryptActionBoundArgs("6090b5db271335765a4b0eab01f044b381b5ebd5cd", action2, $$ACTION_ARG_1, d)) ]; }; +registerServerReference($$RSC_SERVER_ACTION_2, "601c36b06e398c97abe5d5d7ae8c672bfddf4e1b91", null); export async function action0(b, c, ...g) { - return registerServerReference($$RSC_SERVER_ACTION_2, "601c36b06e398c97abe5d5d7ae8c672bfddf4e1b91", null).bind(null, encryptActionBoundArgs("601c36b06e398c97abe5d5d7ae8c672bfddf4e1b91", b, c, g)); + return $$RSC_SERVER_ACTION_2.bind(null, encryptActionBoundArgs("601c36b06e398c97abe5d5d7ae8c672bfddf4e1b91", b, c, g)); } import { ensureServerEntryExports } from "private-next-rsc-action-validate"; ensureServerEntryExports([ diff --git a/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/32/output.js b/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/32/output.js index 4f7c25dd4ef15f..03156e0ca76e13 100644 --- a/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/32/output.js +++ b/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/32/output.js @@ -5,6 +5,7 @@ export const $$RSC_SERVER_ACTION_0 = async function action($$ACTION_CLOSURE_BOUN console.log($$ACTION_ARG_0.at(1), $$ACTION_ARG_1, $$ACTION_ARG_1.current); console.log($$ACTION_ARG_2.push.call($$ACTION_ARG_2, 5)); }; +registerServerReference($$RSC_SERVER_ACTION_0, "406a88810ecce4a4e8b59d53b8327d7e98bbf251d7", null); export function Component() { const data = [ 1, @@ -21,6 +22,6 @@ export function Component() { current: 1 } }; - var action = registerServerReference($$RSC_SERVER_ACTION_0, "406a88810ecce4a4e8b59d53b8327d7e98bbf251d7", null).bind(null, encryptActionBoundArgs("406a88810ecce4a4e8b59d53b8327d7e98bbf251d7", data, baz.value, foo)); + var action = $$RSC_SERVER_ACTION_0.bind(null, encryptActionBoundArgs("406a88810ecce4a4e8b59d53b8327d7e98bbf251d7", data, baz.value, foo)); return
; } diff --git a/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/33/output.js b/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/33/output.js index e5a51584308507..3c6c43a7775b7a 100644 --- a/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/33/output.js +++ b/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/33/output.js @@ -5,11 +5,12 @@ const v = 'world'; export var $$RSC_SERVER_CACHE_0 = $$cache__("default", "803128060c414d59f8552e4788b846c0d2b7f74743", 0, async function fn() { return 'hello, ' + v; }); +registerServerReference($$RSC_SERVER_CACHE_0, "803128060c414d59f8552e4788b846c0d2b7f74743", null); Object["defineProperty"]($$RSC_SERVER_CACHE_0, "name", { value: "fn", writable: false }); -var fn = registerServerReference($$RSC_SERVER_CACHE_0, "803128060c414d59f8552e4788b846c0d2b7f74743", null); +var fn = $$RSC_SERVER_CACHE_0; export async function Component() { const data = await fn(); return
{data}
; diff --git a/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/34/output.js b/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/34/output.js index 1817ddf1587171..7d387cf83de751 100644 --- a/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/34/output.js +++ b/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/34/output.js @@ -4,20 +4,22 @@ import { cache as $$cache__ } from "private-next-rsc-cache-wrapper"; export var $$RSC_SERVER_CACHE_0 = $$cache__("default", "803128060c414d59f8552e4788b846c0d2b7f74743", 0, async function() { return 'foo'; }); +registerServerReference($$RSC_SERVER_CACHE_0, "803128060c414d59f8552e4788b846c0d2b7f74743", null); Object["defineProperty"]($$RSC_SERVER_CACHE_0, "name", { value: "foo", writable: false }); -const foo = registerServerReference($$RSC_SERVER_CACHE_0, "803128060c414d59f8552e4788b846c0d2b7f74743", null); +const foo = $$RSC_SERVER_CACHE_0; export { bar }; export var $$RSC_SERVER_CACHE_1 = $$cache__("default", "80951c375b4a6a6e89d67b743ec5808127cfde405d", 0, async function bar() { return 'bar'; }); +registerServerReference($$RSC_SERVER_CACHE_1, "80951c375b4a6a6e89d67b743ec5808127cfde405d", null); Object["defineProperty"]($$RSC_SERVER_CACHE_1, "name", { value: "bar", writable: false }); -var bar = registerServerReference($$RSC_SERVER_CACHE_1, "80951c375b4a6a6e89d67b743ec5808127cfde405d", null); +var bar = $$RSC_SERVER_CACHE_1; // Should not be wrapped in $$cache__. const qux = async function qux() { return 'qux'; @@ -25,18 +27,20 @@ const qux = async function qux() { export var $$RSC_SERVER_CACHE_2 = $$cache__("default", "8069348c79fce073bae2f70f139565a2fda1c74c74", 0, async function baz() { return qux() + 'baz'; }); +registerServerReference($$RSC_SERVER_CACHE_2, "8069348c79fce073bae2f70f139565a2fda1c74c74", null); Object["defineProperty"]($$RSC_SERVER_CACHE_2, "name", { value: "baz", writable: false }); -const baz = registerServerReference($$RSC_SERVER_CACHE_2, "8069348c79fce073bae2f70f139565a2fda1c74c74", null); +const baz = $$RSC_SERVER_CACHE_2; export var $$RSC_SERVER_CACHE_3 = $$cache__("default", "8012a8d21b6362b4cc8f5b15560525095bc48dba80", 0, async function() { return 'quux'; }); +registerServerReference($$RSC_SERVER_CACHE_3, "8012a8d21b6362b4cc8f5b15560525095bc48dba80", null); Object["defineProperty"]($$RSC_SERVER_CACHE_3, "name", { value: "quux", writable: false }); -const quux = registerServerReference($$RSC_SERVER_CACHE_3, "8012a8d21b6362b4cc8f5b15560525095bc48dba80", null); +const quux = $$RSC_SERVER_CACHE_3; export { foo, baz }; export default quux; diff --git a/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/35/output.js b/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/35/output.js index 4688f266f02477..23c08a193de83b 100644 --- a/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/35/output.js +++ b/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/35/output.js @@ -4,8 +4,9 @@ import { cache as $$cache__ } from "private-next-rsc-cache-wrapper"; export var $$RSC_SERVER_CACHE_0 = $$cache__("default", "803128060c414d59f8552e4788b846c0d2b7f74743", 0, async function() { return 'data'; }); +registerServerReference($$RSC_SERVER_CACHE_0, "803128060c414d59f8552e4788b846c0d2b7f74743", null); Object["defineProperty"]($$RSC_SERVER_CACHE_0, "name", { value: "my_fn", writable: false }); -export const my_fn = registerServerReference($$RSC_SERVER_CACHE_0, "803128060c414d59f8552e4788b846c0d2b7f74743", null); +export const my_fn = $$RSC_SERVER_CACHE_0; diff --git a/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/36/output.js b/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/36/output.js index 733416f6019885..0640df39823e7b 100644 --- a/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/36/output.js +++ b/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/36/output.js @@ -4,32 +4,36 @@ import { cache as $$cache__ } from "private-next-rsc-cache-wrapper"; export var $$RSC_SERVER_CACHE_0 = $$cache__("default", "803128060c414d59f8552e4788b846c0d2b7f74743", 0, async function foo() { return 'data A'; }); +registerServerReference($$RSC_SERVER_CACHE_0, "803128060c414d59f8552e4788b846c0d2b7f74743", null); Object["defineProperty"]($$RSC_SERVER_CACHE_0, "name", { value: "foo", writable: false }); -export var foo = registerServerReference($$RSC_SERVER_CACHE_0, "803128060c414d59f8552e4788b846c0d2b7f74743", null); +export var foo = $$RSC_SERVER_CACHE_0; export var $$RSC_SERVER_CACHE_1 = $$cache__("default", "80951c375b4a6a6e89d67b743ec5808127cfde405d", 0, async function bar() { return 'data B'; }); +registerServerReference($$RSC_SERVER_CACHE_1, "80951c375b4a6a6e89d67b743ec5808127cfde405d", null); Object["defineProperty"]($$RSC_SERVER_CACHE_1, "name", { value: "bar", writable: false }); -export var bar = registerServerReference($$RSC_SERVER_CACHE_1, "80951c375b4a6a6e89d67b743ec5808127cfde405d", null); +export var bar = $$RSC_SERVER_CACHE_1; export var $$RSC_SERVER_CACHE_2 = $$cache__("default", "c069348c79fce073bae2f70f139565a2fda1c74c74", 0, async function Cached({ children }) { return children; }); +registerServerReference($$RSC_SERVER_CACHE_2, "c069348c79fce073bae2f70f139565a2fda1c74c74", null); Object["defineProperty"]($$RSC_SERVER_CACHE_2, "name", { value: "Cached", writable: false }); -export default registerServerReference($$RSC_SERVER_CACHE_2, "c069348c79fce073bae2f70f139565a2fda1c74c74", null); +export default $$RSC_SERVER_CACHE_2; export var $$RSC_SERVER_CACHE_3 = $$cache__("default", "8012a8d21b6362b4cc8f5b15560525095bc48dba80", 0, async function baz() { return 'data C'; }); +registerServerReference($$RSC_SERVER_CACHE_3, "8012a8d21b6362b4cc8f5b15560525095bc48dba80", null); Object["defineProperty"]($$RSC_SERVER_CACHE_3, "name", { value: "baz", writable: false }); -export const baz = registerServerReference($$RSC_SERVER_CACHE_3, "8012a8d21b6362b4cc8f5b15560525095bc48dba80", null); +export const baz = $$RSC_SERVER_CACHE_3; diff --git a/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/37/output.js b/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/37/output.js index f3d42e8b71b61b..30e6223c88ba2b 100644 --- a/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/37/output.js +++ b/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/37/output.js @@ -4,11 +4,12 @@ import { cache as $$cache__ } from "private-next-rsc-cache-wrapper"; export var $$RSC_SERVER_CACHE_0 = $$cache__("default", "803128060c414d59f8552e4788b846c0d2b7f74743", 0, async function fn() { return 'foo'; }); +registerServerReference($$RSC_SERVER_CACHE_0, "803128060c414d59f8552e4788b846c0d2b7f74743", null); Object["defineProperty"]($$RSC_SERVER_CACHE_0, "name", { value: "fn", writable: false }); -var fn = registerServerReference($$RSC_SERVER_CACHE_0, "803128060c414d59f8552e4788b846c0d2b7f74743", null); +var fn = $$RSC_SERVER_CACHE_0; async function Component() { const data = await fn(); return
{data}
; diff --git a/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/38/output.js b/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/38/output.js index b2c2764c9f0b84..e0de6fb1bda5ae 100644 --- a/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/38/output.js +++ b/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/38/output.js @@ -4,8 +4,9 @@ import { cache as $$cache__ } from "private-next-rsc-cache-wrapper"; export var $$RSC_SERVER_CACHE_0 = $$cache__("x", "803128060c414d59f8552e4788b846c0d2b7f74743", 0, async function foo() { return 'data'; }); +registerServerReference($$RSC_SERVER_CACHE_0, "803128060c414d59f8552e4788b846c0d2b7f74743", null); Object["defineProperty"]($$RSC_SERVER_CACHE_0, "name", { value: "foo", writable: false }); -export var foo = registerServerReference($$RSC_SERVER_CACHE_0, "803128060c414d59f8552e4788b846c0d2b7f74743", null); +export var foo = $$RSC_SERVER_CACHE_0; diff --git a/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/39/output.js b/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/39/output.js index 565267d4a48c2e..3eb7a294011018 100644 --- a/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/39/output.js +++ b/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/39/output.js @@ -7,15 +7,15 @@ export var $$RSC_SERVER_CACHE_0 = $$cache__("default", "c03128060c414d59f8552e47 foo: $$ACTION_ARG_1 }; }); +registerServerReference($$RSC_SERVER_CACHE_0, "c03128060c414d59f8552e4788b846c0d2b7f74743", null); Object["defineProperty"]($$RSC_SERVER_CACHE_0, "name", { value: "fn", writable: false }); async function Component({ foo }) { const a = 123; - var fn = $$RSC_SERVER_REF_1.bind(null, encryptActionBoundArgs("c03128060c414d59f8552e4788b846c0d2b7f74743", a, foo)); + var fn = $$RSC_SERVER_CACHE_0.bind(null, encryptActionBoundArgs("c03128060c414d59f8552e4788b846c0d2b7f74743", a, foo)); const data = await fn(); // @ts-expect-error: data is not a valid react child return
{data}
; } -var $$RSC_SERVER_REF_1 = registerServerReference($$RSC_SERVER_CACHE_0, "c03128060c414d59f8552e4788b846c0d2b7f74743", null); diff --git a/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/4/output.js b/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/4/output.js index 9d426b74da7c09..ac98b3b46abe2a 100644 --- a/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/4/output.js +++ b/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/4/output.js @@ -5,8 +5,9 @@ export async function b() {} export async function c() {} function d() {} export const $$RSC_SERVER_ACTION_0 = async function e() {}; +registerServerReference($$RSC_SERVER_ACTION_0, "006a88810ecce4a4e8b59d53b8327d7e98bbf251d7", null); function Foo() { - var e = registerServerReference($$RSC_SERVER_ACTION_0, "006a88810ecce4a4e8b59d53b8327d7e98bbf251d7", null); + var e = $$RSC_SERVER_ACTION_0; } import { ensureServerEntryExports } from "private-next-rsc-action-validate"; ensureServerEntryExports([ diff --git a/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/40/output.js b/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/40/output.js index ed5cc76616d341..8f6dc9e32f95fd 100644 --- a/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/40/output.js +++ b/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/40/output.js @@ -1,4 +1,4 @@ -/* __next_internal_action_entry_do_not_use__ {"601c36b06e398c97abe5d5d7ae8c672bfddf4e1b91":"$$RSC_SERVER_ACTION_2","e03128060c414d59f8552e4788b846c0d2b7f74743":"$$RSC_SERVER_CACHE_0"} */ import { registerServerReference } from "private-next-rsc-server-reference"; +/* __next_internal_action_entry_do_not_use__ {"6090b5db271335765a4b0eab01f044b381b5ebd5cd":"$$RSC_SERVER_ACTION_1","e03128060c414d59f8552e4788b846c0d2b7f74743":"$$RSC_SERVER_CACHE_0"} */ import { registerServerReference } from "private-next-rsc-server-reference"; import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption"; import { cache as $$cache__ } from "private-next-rsc-cache-wrapper"; import { Form } from 'components'; @@ -11,21 +11,22 @@ export var $$RSC_SERVER_CACHE_0 = $$cache__("default", "e03128060c414d59f8552e47 } ]; }); +registerServerReference($$RSC_SERVER_CACHE_0, "e03128060c414d59f8552e4788b846c0d2b7f74743", null); Object["defineProperty"]($$RSC_SERVER_CACHE_0, "name", { value: "cache", writable: false }); -export const $$RSC_SERVER_ACTION_2 = async function action($$ACTION_CLOSURE_BOUND, c) { - var [$$ACTION_ARG_0, $$ACTION_ARG_1] = await decryptActionBoundArgs("601c36b06e398c97abe5d5d7ae8c672bfddf4e1b91", $$ACTION_CLOSURE_BOUND); +export const $$RSC_SERVER_ACTION_1 = async function action($$ACTION_CLOSURE_BOUND, c) { + var [$$ACTION_ARG_0, $$ACTION_ARG_1] = await decryptActionBoundArgs("6090b5db271335765a4b0eab01f044b381b5ebd5cd", $$ACTION_CLOSURE_BOUND); const d = $$ACTION_ARG_0 + $$ACTION_ARG_1 + c; - var cache = $$RSC_SERVER_REF_1.bind(null, encryptActionBoundArgs("e03128060c414d59f8552e4788b846c0d2b7f74743", d, $$ACTION_ARG_0)); + var cache = $$RSC_SERVER_CACHE_0.bind(null, encryptActionBoundArgs("e03128060c414d59f8552e4788b846c0d2b7f74743", d, $$ACTION_ARG_0)); return cache(d); }; +registerServerReference($$RSC_SERVER_ACTION_1, "6090b5db271335765a4b0eab01f044b381b5ebd5cd", null); async function Component({ a }) { const b = 1; - var action = registerServerReference($$RSC_SERVER_ACTION_2, "601c36b06e398c97abe5d5d7ae8c672bfddf4e1b91", null).bind(null, encryptActionBoundArgs("601c36b06e398c97abe5d5d7ae8c672bfddf4e1b91", a, b)); + var action = $$RSC_SERVER_ACTION_1.bind(null, encryptActionBoundArgs("6090b5db271335765a4b0eab01f044b381b5ebd5cd", a, b)); return
; } -var $$RSC_SERVER_REF_1 = registerServerReference($$RSC_SERVER_CACHE_0, "e03128060c414d59f8552e4788b846c0d2b7f74743", null); diff --git a/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/41/output.js b/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/41/output.js index bc8b351c1e5ba1..e52be8748e992b 100644 --- a/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/41/output.js +++ b/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/41/output.js @@ -8,15 +8,17 @@ export const $$RSC_SERVER_ACTION_0 = async function fn($$ACTION_CLOSURE_BOUND) { foo: $$ACTION_ARG_1 }; }; +registerServerReference($$RSC_SERVER_ACTION_0, "406a88810ecce4a4e8b59d53b8327d7e98bbf251d7", null); export var $$RSC_SERVER_CACHE_1 = $$cache__("default", "c0951c375b4a6a6e89d67b743ec5808127cfde405d", 0, async function Component({ foo }) { const a = 123; - var fn = registerServerReference($$RSC_SERVER_ACTION_0, "406a88810ecce4a4e8b59d53b8327d7e98bbf251d7", null).bind(null, encryptActionBoundArgs("406a88810ecce4a4e8b59d53b8327d7e98bbf251d7", a, foo)); + var fn = $$RSC_SERVER_ACTION_0.bind(null, encryptActionBoundArgs("406a88810ecce4a4e8b59d53b8327d7e98bbf251d7", a, foo)); const data = await fn(); // @ts-expect-error: data is not a valid react child return
{data}
; }); +registerServerReference($$RSC_SERVER_CACHE_1, "c0951c375b4a6a6e89d67b743ec5808127cfde405d", null); Object["defineProperty"]($$RSC_SERVER_CACHE_1, "name", { value: "Component", writable: false }); -export var Component = registerServerReference($$RSC_SERVER_CACHE_1, "c0951c375b4a6a6e89d67b743ec5808127cfde405d", null); +export var Component = $$RSC_SERVER_CACHE_1; diff --git a/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/42/output.js b/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/42/output.js index 41b1eba156e897..b22cae0e87eac2 100644 --- a/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/42/output.js +++ b/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/42/output.js @@ -7,15 +7,15 @@ export var $$RSC_SERVER_CACHE_0 = $$cache__("default", "c03128060c414d59f8552e47 foo: $$ACTION_ARG_1 }; }); +registerServerReference($$RSC_SERVER_CACHE_0, "c03128060c414d59f8552e4788b846c0d2b7f74743", null); Object["defineProperty"]($$RSC_SERVER_CACHE_0, "name", { value: "fn", writable: false }); async function Component({ foo }) { const a = 123; - const fn = $$RSC_SERVER_REF_1.bind(null, encryptActionBoundArgs("c03128060c414d59f8552e4788b846c0d2b7f74743", a, foo)); + const fn = $$RSC_SERVER_CACHE_0.bind(null, encryptActionBoundArgs("c03128060c414d59f8552e4788b846c0d2b7f74743", a, foo)); const data = await fn(); // @ts-expect-error: data is not a valid react child return
{data}
; } -var $$RSC_SERVER_REF_1 = registerServerReference($$RSC_SERVER_CACHE_0, "c03128060c414d59f8552e4788b846c0d2b7f74743", null); diff --git a/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/43/output.js b/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/43/output.js index 998c6006730a20..44e8130c1e01a1 100644 --- a/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/43/output.js +++ b/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/43/output.js @@ -7,16 +7,18 @@ export const $$RSC_SERVER_ACTION_0 = async function action($$ACTION_CLOSURE_BOUN var [$$ACTION_ARG_0] = await decryptActionBoundArgs("406a88810ecce4a4e8b59d53b8327d7e98bbf251d7", $$ACTION_CLOSURE_BOUND); console.log(secret, $$ACTION_ARG_0); }; +registerServerReference($$RSC_SERVER_ACTION_0, "406a88810ecce4a4e8b59d53b8327d7e98bbf251d7", null); export var $$RSC_SERVER_CACHE_1 = $$cache__("default", "e0951c375b4a6a6e89d67b743ec5808127cfde405d", 0, async function getCachedRandom(x, children) { return { x, y: Math.random(), - z: ; } diff --git a/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/50/output.js b/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/50/output.js index 34a2cf9bf8c65c..9b6edcdc48fc76 100644 --- a/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/50/output.js +++ b/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/50/output.js @@ -8,8 +8,9 @@ export var $$RSC_SERVER_CACHE_0 = $$cache__("default", "f03128060c414d59f8552e47 {c} ; }); +registerServerReference($$RSC_SERVER_CACHE_0, "f03128060c414d59f8552e4788b846c0d2b7f74743", null); Object["defineProperty"]($$RSC_SERVER_CACHE_0, "name", { value: "default", writable: false }); -export default registerServerReference($$RSC_SERVER_CACHE_0, "f03128060c414d59f8552e4788b846c0d2b7f74743", null); +export default $$RSC_SERVER_CACHE_0; diff --git a/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/51/output.js b/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/51/output.js index f5fe0067412056..6553c6b963c306 100644 --- a/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/51/output.js +++ b/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/51/output.js @@ -7,7 +7,8 @@ export const $$RSC_SERVER_ACTION_1 = async function $$RSC_SERVER_ACTION_0(a, b, {c} ; }; -export default registerServerReference($$RSC_SERVER_ACTION_1, "7090b5db271335765a4b0eab01f044b381b5ebd5cd", null); +registerServerReference($$RSC_SERVER_ACTION_1, "7090b5db271335765a4b0eab01f044b381b5ebd5cd", null); +export default $$RSC_SERVER_ACTION_1; Object["defineProperty"]($$RSC_SERVER_ACTION_0, "name", { value: "default", writable: false @@ -18,11 +19,13 @@ export const $$RSC_SERVER_ACTION_2 = async function foo(a, b) { {b} ; }; -export var foo = registerServerReference($$RSC_SERVER_ACTION_2, "601c36b06e398c97abe5d5d7ae8c672bfddf4e1b91", null); +registerServerReference($$RSC_SERVER_ACTION_2, "601c36b06e398c97abe5d5d7ae8c672bfddf4e1b91", null); +export var foo = $$RSC_SERVER_ACTION_2; export const $$RSC_SERVER_ACTION_3 = async function bar(a, b) { return
{a} {b}
; }; -export const bar = registerServerReference($$RSC_SERVER_ACTION_3, "609ed0cc47abc4e1c64320cf42b74ae60b58c40f00", null); +registerServerReference($$RSC_SERVER_ACTION_3, "609ed0cc47abc4e1c64320cf42b74ae60b58c40f00", null); +export const bar = $$RSC_SERVER_ACTION_3; diff --git a/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/52/output.js b/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/52/output.js index 4646429fd71cd2..f56368a4d010f1 100644 --- a/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/52/output.js +++ b/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/52/output.js @@ -1,40 +1,42 @@ -/* __next_internal_action_entry_do_not_use__ {"409651a98a9dccd7ffbe72ff5cf0f38546ca1252ab":"$$RSC_SERVER_ACTION_5","60a9b2939c1f39073a6bed227fd20233064c8b7869":"$$RSC_SERVER_ACTION_4","c069348c79fce073bae2f70f139565a2fda1c74c74":"$$RSC_SERVER_CACHE_2","e03128060c414d59f8552e4788b846c0d2b7f74743":"$$RSC_SERVER_CACHE_0"} */ import { registerServerReference } from "private-next-rsc-server-reference"; +/* __next_internal_action_entry_do_not_use__ {"409ed0cc47abc4e1c64320cf42b74ae60b58c40f00":"$$RSC_SERVER_ACTION_3","601c36b06e398c97abe5d5d7ae8c672bfddf4e1b91":"$$RSC_SERVER_ACTION_2","c0951c375b4a6a6e89d67b743ec5808127cfde405d":"$$RSC_SERVER_CACHE_1","e03128060c414d59f8552e4788b846c0d2b7f74743":"$$RSC_SERVER_CACHE_0"} */ import { registerServerReference } from "private-next-rsc-server-reference"; import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption"; import { cache as $$cache__ } from "private-next-rsc-cache-wrapper"; import { Client } from 'components'; export var $$RSC_SERVER_CACHE_0 = $$cache__("default", "e03128060c414d59f8552e4788b846c0d2b7f74743", 2, async function([$$ACTION_ARG_0, $$ACTION_ARG_1], c) { return $$ACTION_ARG_0 + $$ACTION_ARG_1 + c; }); +registerServerReference($$RSC_SERVER_CACHE_0, "e03128060c414d59f8552e4788b846c0d2b7f74743", null); Object["defineProperty"]($$RSC_SERVER_CACHE_0, "name", { value: "fn1", writable: false }); -export var $$RSC_SERVER_CACHE_2 = $$cache__("default", "c069348c79fce073bae2f70f139565a2fda1c74c74", 2, async function // Should be 1 100000 0, which is "c0" in hex (counts as one param, +export var $$RSC_SERVER_CACHE_1 = $$cache__("default", "c0951c375b4a6a6e89d67b743ec5808127cfde405d", 2, async function // Should be 1 100000 0, which is "c0" in hex (counts as one param, // because of the encrypted bound args param) fn2([$$ACTION_ARG_0, $$ACTION_ARG_1]) { return $$ACTION_ARG_0 + $$ACTION_ARG_1; }); -Object["defineProperty"]($$RSC_SERVER_CACHE_2, "name", { +registerServerReference($$RSC_SERVER_CACHE_1, "c0951c375b4a6a6e89d67b743ec5808127cfde405d", null); +Object["defineProperty"]($$RSC_SERVER_CACHE_1, "name", { value: "fn2", writable: false }); -export const $$RSC_SERVER_ACTION_4 = async function // Should be 0 110000 0, which is "60" in hex (counts as two params, +export const $$RSC_SERVER_ACTION_2 = async function // Should be 0 110000 0, which is "60" in hex (counts as two params, // because of the encrypted bound args param) fn3($$ACTION_CLOSURE_BOUND, c) { - var [$$ACTION_ARG_0, $$ACTION_ARG_1] = await decryptActionBoundArgs("60a9b2939c1f39073a6bed227fd20233064c8b7869", $$ACTION_CLOSURE_BOUND); + var [$$ACTION_ARG_0, $$ACTION_ARG_1] = await decryptActionBoundArgs("601c36b06e398c97abe5d5d7ae8c672bfddf4e1b91", $$ACTION_CLOSURE_BOUND); return $$ACTION_ARG_0 + $$ACTION_ARG_1 + c; }; -export const $$RSC_SERVER_ACTION_5 = async function // Should be 0 100000 0, which is "40" in hex (counts as one param, +registerServerReference($$RSC_SERVER_ACTION_2, "601c36b06e398c97abe5d5d7ae8c672bfddf4e1b91", null); +export const $$RSC_SERVER_ACTION_3 = async function // Should be 0 100000 0, which is "40" in hex (counts as one param, // because of the encrypted bound args param) fn4($$ACTION_CLOSURE_BOUND) { - var [$$ACTION_ARG_0, $$ACTION_ARG_1] = await decryptActionBoundArgs("409651a98a9dccd7ffbe72ff5cf0f38546ca1252ab", $$ACTION_CLOSURE_BOUND); + var [$$ACTION_ARG_0, $$ACTION_ARG_1] = await decryptActionBoundArgs("409ed0cc47abc4e1c64320cf42b74ae60b58c40f00", $$ACTION_CLOSURE_BOUND); return $$ACTION_ARG_0 + $$ACTION_ARG_1; }; +registerServerReference($$RSC_SERVER_ACTION_3, "409ed0cc47abc4e1c64320cf42b74ae60b58c40f00", null); export async function Component(a) { const b = 1; return ; + fn1={$$RSC_SERVER_CACHE_0.bind(null, encryptActionBoundArgs("e03128060c414d59f8552e4788b846c0d2b7f74743", a, b))} fn2={$$RSC_SERVER_CACHE_1.bind(null, encryptActionBoundArgs("c0951c375b4a6a6e89d67b743ec5808127cfde405d", a, b))} fn3={$$RSC_SERVER_ACTION_2.bind(null, encryptActionBoundArgs("601c36b06e398c97abe5d5d7ae8c672bfddf4e1b91", a, b))} fn4={$$RSC_SERVER_ACTION_3.bind(null, encryptActionBoundArgs("409ed0cc47abc4e1c64320cf42b74ae60b58c40f00", a, b))}/>; } -var $$RSC_SERVER_REF_1 = registerServerReference($$RSC_SERVER_CACHE_0, "e03128060c414d59f8552e4788b846c0d2b7f74743", null); -var $$RSC_SERVER_REF_3 = registerServerReference($$RSC_SERVER_CACHE_2, "c069348c79fce073bae2f70f139565a2fda1c74c74", null); diff --git a/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/53/output.js b/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/53/output.js index 375c9b503ae367..762ae07c98091d 100644 --- a/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/53/output.js +++ b/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/53/output.js @@ -2,12 +2,14 @@ import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption"; import { cache as $$cache__ } from "private-next-rsc-cache-wrapper"; export var $$RSC_SERVER_CACHE_0 = $$cache__("default", "803128060c414d59f8552e4788b846c0d2b7f74743", 0, async function foo() {}); +registerServerReference($$RSC_SERVER_CACHE_0, "803128060c414d59f8552e4788b846c0d2b7f74743", null); Object["defineProperty"]($$RSC_SERVER_CACHE_0, "name", { value: "foo", writable: false }); export const $$RSC_SERVER_ACTION_1 = async function bar() {}; +registerServerReference($$RSC_SERVER_ACTION_1, "0090b5db271335765a4b0eab01f044b381b5ebd5cd", null); export const obj = { - foo: registerServerReference($$RSC_SERVER_CACHE_0, "803128060c414d59f8552e4788b846c0d2b7f74743", null), - bar: registerServerReference($$RSC_SERVER_ACTION_1, "0090b5db271335765a4b0eab01f044b381b5ebd5cd", null) + foo: $$RSC_SERVER_CACHE_0, + bar: $$RSC_SERVER_ACTION_1 }; diff --git a/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/54/output.js b/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/54/output.js index 49fb9121840888..aa133634af1275 100644 --- a/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/54/output.js +++ b/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/54/output.js @@ -1,22 +1,23 @@ -/* __next_internal_action_entry_do_not_use__ {"401c36b06e398c97abe5d5d7ae8c672bfddf4e1b91":"$$RSC_SERVER_ACTION_2","c03128060c414d59f8552e4788b846c0d2b7f74743":"$$RSC_SERVER_CACHE_0"} */ import { registerServerReference } from "private-next-rsc-server-reference"; +/* __next_internal_action_entry_do_not_use__ {"4090b5db271335765a4b0eab01f044b381b5ebd5cd":"$$RSC_SERVER_ACTION_1","c03128060c414d59f8552e4788b846c0d2b7f74743":"$$RSC_SERVER_CACHE_0"} */ import { registerServerReference } from "private-next-rsc-server-reference"; import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption"; import { cache as $$cache__ } from "private-next-rsc-cache-wrapper"; export var $$RSC_SERVER_CACHE_0 = $$cache__("default", "c03128060c414d59f8552e4788b846c0d2b7f74743", 2, async function foo([$$ACTION_ARG_0, $$ACTION_ARG_1]) { return $$ACTION_ARG_0 * $$ACTION_ARG_1; }); +registerServerReference($$RSC_SERVER_CACHE_0, "c03128060c414d59f8552e4788b846c0d2b7f74743", null); Object["defineProperty"]($$RSC_SERVER_CACHE_0, "name", { value: "foo", writable: false }); -export const $$RSC_SERVER_ACTION_2 = async function bar($$ACTION_CLOSURE_BOUND) { - var [$$ACTION_ARG_0] = await decryptActionBoundArgs("401c36b06e398c97abe5d5d7ae8c672bfddf4e1b91", $$ACTION_CLOSURE_BOUND); +export const $$RSC_SERVER_ACTION_1 = async function bar($$ACTION_CLOSURE_BOUND) { + var [$$ACTION_ARG_0] = await decryptActionBoundArgs("4090b5db271335765a4b0eab01f044b381b5ebd5cd", $$ACTION_CLOSURE_BOUND); console.log($$ACTION_ARG_0); }; +registerServerReference($$RSC_SERVER_ACTION_1, "4090b5db271335765a4b0eab01f044b381b5ebd5cd", null); function createObj(n) { const m = n + 1; return { - foo: $$RSC_SERVER_REF_1.bind(null, encryptActionBoundArgs("c03128060c414d59f8552e4788b846c0d2b7f74743", n, m)), - bar: registerServerReference($$RSC_SERVER_ACTION_2, "401c36b06e398c97abe5d5d7ae8c672bfddf4e1b91", null).bind(null, encryptActionBoundArgs("401c36b06e398c97abe5d5d7ae8c672bfddf4e1b91", m)) + foo: $$RSC_SERVER_CACHE_0.bind(null, encryptActionBoundArgs("c03128060c414d59f8552e4788b846c0d2b7f74743", n, m)), + bar: $$RSC_SERVER_ACTION_1.bind(null, encryptActionBoundArgs("4090b5db271335765a4b0eab01f044b381b5ebd5cd", m)) }; } -var $$RSC_SERVER_REF_1 = registerServerReference($$RSC_SERVER_CACHE_0, "c03128060c414d59f8552e4788b846c0d2b7f74743", null); diff --git a/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/55/output.js b/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/55/output.js index b291dee8f8b4e7..107d3770ea1cea 100644 --- a/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/55/output.js +++ b/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/55/output.js @@ -4,12 +4,13 @@ import { cache as $$cache__ } from "private-next-rsc-cache-wrapper"; export var $$RSC_SERVER_CACHE_0 = $$cache__("default", "803128060c414d59f8552e4788b846c0d2b7f74743", 0, async function fetch1() { return fetch('https://example.com').then((res)=>res.json()); }); +registerServerReference($$RSC_SERVER_CACHE_0, "803128060c414d59f8552e4788b846c0d2b7f74743", null); Object["defineProperty"]($$RSC_SERVER_CACHE_0, "name", { value: "fetch", writable: false }); export const api = { product: { - fetch: registerServerReference($$RSC_SERVER_CACHE_0, "803128060c414d59f8552e4788b846c0d2b7f74743", null) + fetch: $$RSC_SERVER_CACHE_0 } }; diff --git a/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/57/output.js b/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/57/output.js index b017d5f8430375..b8e0d92c673a27 100644 --- a/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/57/output.js +++ b/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/57/output.js @@ -4,6 +4,7 @@ import { cache as $$cache__ } from "private-next-rsc-cache-wrapper"; export var $$RSC_SERVER_CACHE_0 = $$cache__("default", "803128060c414d59f8552e4788b846c0d2b7f74743", 0, async function foo() { return fetch('https://example.com').then((res)=>res.json()); }); +registerServerReference($$RSC_SERVER_CACHE_0, "803128060c414d59f8552e4788b846c0d2b7f74743", null); Object["defineProperty"]($$RSC_SERVER_CACHE_0, "name", { value: "foo", writable: false @@ -11,7 +12,8 @@ Object["defineProperty"]($$RSC_SERVER_CACHE_0, "name", { export const $$RSC_SERVER_ACTION_1 = async function bar() { console.log(42); }; +registerServerReference($$RSC_SERVER_ACTION_1, "0090b5db271335765a4b0eab01f044b381b5ebd5cd", null); export class MyClass { - static foo = registerServerReference($$RSC_SERVER_CACHE_0, "803128060c414d59f8552e4788b846c0d2b7f74743", null); - static bar = registerServerReference($$RSC_SERVER_ACTION_1, "0090b5db271335765a4b0eab01f044b381b5ebd5cd", null); + static foo = $$RSC_SERVER_CACHE_0; + static bar = $$RSC_SERVER_ACTION_1; } diff --git a/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/58/output.js b/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/58/output.js index d66f9a14ec03ce..972e6edc908a02 100644 --- a/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/58/output.js +++ b/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/58/output.js @@ -1,23 +1,24 @@ -/* __next_internal_action_entry_do_not_use__ {"401c36b06e398c97abe5d5d7ae8c672bfddf4e1b91":"$$RSC_SERVER_ACTION_2","c03128060c414d59f8552e4788b846c0d2b7f74743":"$$RSC_SERVER_CACHE_0"} */ import { registerServerReference } from "private-next-rsc-server-reference"; +/* __next_internal_action_entry_do_not_use__ {"4090b5db271335765a4b0eab01f044b381b5ebd5cd":"$$RSC_SERVER_ACTION_1","c03128060c414d59f8552e4788b846c0d2b7f74743":"$$RSC_SERVER_CACHE_0"} */ import { registerServerReference } from "private-next-rsc-server-reference"; import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption"; import { cache as $$cache__ } from "private-next-rsc-cache-wrapper"; export var $$RSC_SERVER_CACHE_0 = $$cache__("default", "c03128060c414d59f8552e4788b846c0d2b7f74743", 1, async function([$$ACTION_ARG_0]) { return $$ACTION_ARG_0(); }); +registerServerReference($$RSC_SERVER_CACHE_0, "c03128060c414d59f8552e4788b846c0d2b7f74743", null); function createCachedFn(start) { function fn() { return start + Math.random(); } - return $$RSC_SERVER_REF_1.bind(null, encryptActionBoundArgs("c03128060c414d59f8552e4788b846c0d2b7f74743", fn)); + return $$RSC_SERVER_CACHE_0.bind(null, encryptActionBoundArgs("c03128060c414d59f8552e4788b846c0d2b7f74743", fn)); } -var $$RSC_SERVER_REF_1 = registerServerReference($$RSC_SERVER_CACHE_0, "c03128060c414d59f8552e4788b846c0d2b7f74743", null); -export const $$RSC_SERVER_ACTION_2 = async function($$ACTION_CLOSURE_BOUND) { - var [$$ACTION_ARG_0] = await decryptActionBoundArgs("401c36b06e398c97abe5d5d7ae8c672bfddf4e1b91", $$ACTION_CLOSURE_BOUND); +export const $$RSC_SERVER_ACTION_1 = async function($$ACTION_CLOSURE_BOUND) { + var [$$ACTION_ARG_0] = await decryptActionBoundArgs("4090b5db271335765a4b0eab01f044b381b5ebd5cd", $$ACTION_CLOSURE_BOUND); console.log($$ACTION_ARG_0()); }; +registerServerReference($$RSC_SERVER_ACTION_1, "4090b5db271335765a4b0eab01f044b381b5ebd5cd", null); function createServerAction(start) { function fn() { return start + Math.random(); } - return registerServerReference($$RSC_SERVER_ACTION_2, "401c36b06e398c97abe5d5d7ae8c672bfddf4e1b91", null).bind(null, encryptActionBoundArgs("401c36b06e398c97abe5d5d7ae8c672bfddf4e1b91", fn)); + return $$RSC_SERVER_ACTION_1.bind(null, encryptActionBoundArgs("4090b5db271335765a4b0eab01f044b381b5ebd5cd", fn)); } diff --git a/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/6/output.js b/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/6/output.js index d3ce5c52feb852..d288b240ba654e 100644 --- a/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/6/output.js +++ b/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/6/output.js @@ -25,6 +25,7 @@ export const $$RSC_SERVER_ACTION_0 = async function action($$ACTION_CLOSURE_BOUN g19, // @ts-expect-error: deliberately undefined variable g20, globalThis); }; +registerServerReference($$RSC_SERVER_ACTION_0, "406a88810ecce4a4e8b59d53b8327d7e98bbf251d7", null); export function y(p, [p1, { p2 }], ...p3) { /** @type {any} */ const f2 = 1; const f11 = 1; @@ -32,6 +33,6 @@ export function y(p, [p1, { p2 }], ...p3) { if (true) { const f8 = 1; } - var action = registerServerReference($$RSC_SERVER_ACTION_0, "406a88810ecce4a4e8b59d53b8327d7e98bbf251d7", null).bind(null, encryptActionBoundArgs("406a88810ecce4a4e8b59d53b8327d7e98bbf251d7", f2, f11, p, p1, p2, p3)); + var action = $$RSC_SERVER_ACTION_0.bind(null, encryptActionBoundArgs("406a88810ecce4a4e8b59d53b8327d7e98bbf251d7", f2, f11, p, p1, p2, p3)); return ; } diff --git a/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/60/output.ts b/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/60/output.ts index eb23ba9b378d54..32cc70a4fc2fff 100644 --- a/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/60/output.ts +++ b/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/60/output.ts @@ -12,8 +12,9 @@ export enum E { export default interface D { } export var $$RSC_SERVER_CACHE_0 = $$cache__("default", "803128060c414d59f8552e4788b846c0d2b7f74743", 0, async function Page() {}); +registerServerReference($$RSC_SERVER_CACHE_0, "803128060c414d59f8552e4788b846c0d2b7f74743", null); Object["defineProperty"]($$RSC_SERVER_CACHE_0, "name", { value: "Page", writable: false }); -export var Page = registerServerReference($$RSC_SERVER_CACHE_0, "803128060c414d59f8552e4788b846c0d2b7f74743", null); +export var Page = $$RSC_SERVER_CACHE_0; diff --git a/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/61/output.js b/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/61/output.js index 10417e25b2c857..c5fc27a9b4e7e6 100644 --- a/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/61/output.js +++ b/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/61/output.js @@ -4,8 +4,9 @@ export const $$RSC_SERVER_ACTION_0 = async function action($$ACTION_CLOSURE_BOUN var [$$ACTION_ARG_0, $$ACTION_ARG_1] = await decryptActionBoundArgs("406a88810ecce4a4e8b59d53b8327d7e98bbf251d7", $$ACTION_CLOSURE_BOUND); console.log($$ACTION_ARG_0.find((x)=>x === $$ACTION_ARG_1)); }; +registerServerReference($$RSC_SERVER_ACTION_0, "406a88810ecce4a4e8b59d53b8327d7e98bbf251d7", null); export function ComponentA({ list, y }) { - return + return ; } @@ -15,8 +16,9 @@ export const $$RSC_SERVER_ACTION_1 = async function action($$ACTION_CLOSURE_BOUN return x === $$ACTION_ARG_1; })); }; +registerServerReference($$RSC_SERVER_ACTION_1, "4090b5db271335765a4b0eab01f044b381b5ebd5cd", null); export function ComponentB({ list, y }) { - return
+ return
; } diff --git a/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/7/output.js b/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/7/output.js index 280c61eb8ed353..6225342e615680 100644 --- a/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/7/output.js +++ b/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/7/output.js @@ -7,8 +7,9 @@ export const $$RSC_SERVER_ACTION_0 = async function deleteItem1($$ACTION_CLOSURE await deleteFromDb($$ACTION_ARG_0.id, $$ACTION_ARG_0?.foo, $$ACTION_ARG_0.bar.baz, $$ACTION_ARG_0[// @ts-expect-error: deliberate useless comma $$ACTION_ARG_1, $$ACTION_ARG_2]); }; +registerServerReference($$RSC_SERVER_ACTION_0, "406a88810ecce4a4e8b59d53b8327d7e98bbf251d7", null); export function Item1(product, foo, bar) { - const a = registerServerReference($$RSC_SERVER_ACTION_0, "406a88810ecce4a4e8b59d53b8327d7e98bbf251d7", null).bind(null, encryptActionBoundArgs("406a88810ecce4a4e8b59d53b8327d7e98bbf251d7", product, foo, bar)); + const a = $$RSC_SERVER_ACTION_0.bind(null, encryptActionBoundArgs("406a88810ecce4a4e8b59d53b8327d7e98bbf251d7", product, foo, bar)); return ; } export const $$RSC_SERVER_ACTION_1 = async function deleteItem2($$ACTION_CLOSURE_BOUND) { @@ -16,8 +17,9 @@ export const $$RSC_SERVER_ACTION_1 = async function deleteItem2($$ACTION_CLOSURE await deleteFromDb($$ACTION_ARG_0.id, $$ACTION_ARG_0?.foo, $$ACTION_ARG_0.bar.baz, $$ACTION_ARG_0[// @ts-expect-error: deliberate useless comma $$ACTION_ARG_1, $$ACTION_ARG_2]); }; +registerServerReference($$RSC_SERVER_ACTION_1, "4090b5db271335765a4b0eab01f044b381b5ebd5cd", null); export function Item2(product, foo, bar) { - var deleteItem2 = registerServerReference($$RSC_SERVER_ACTION_1, "4090b5db271335765a4b0eab01f044b381b5ebd5cd", null).bind(null, encryptActionBoundArgs("4090b5db271335765a4b0eab01f044b381b5ebd5cd", product, foo, bar)); + var deleteItem2 = $$RSC_SERVER_ACTION_1.bind(null, encryptActionBoundArgs("4090b5db271335765a4b0eab01f044b381b5ebd5cd", product, foo, bar)); return ; } export const $$RSC_SERVER_ACTION_2 = async function deleteItem3($$ACTION_CLOSURE_BOUND) { @@ -25,8 +27,9 @@ export const $$RSC_SERVER_ACTION_2 = async function deleteItem3($$ACTION_CLOSURE await deleteFromDb($$ACTION_ARG_0.id, $$ACTION_ARG_0?.foo, $$ACTION_ARG_0.bar.baz, $$ACTION_ARG_0[// @ts-expect-error: deliberate useless comma $$ACTION_ARG_1, $$ACTION_ARG_2]); }; +registerServerReference($$RSC_SERVER_ACTION_2, "401c36b06e398c97abe5d5d7ae8c672bfddf4e1b91", null); export function Item3(product, foo, bar) { - const deleteItem3 = registerServerReference($$RSC_SERVER_ACTION_2, "401c36b06e398c97abe5d5d7ae8c672bfddf4e1b91", null).bind(null, encryptActionBoundArgs("401c36b06e398c97abe5d5d7ae8c672bfddf4e1b91", product, foo, bar)); + const deleteItem3 = $$RSC_SERVER_ACTION_2.bind(null, encryptActionBoundArgs("401c36b06e398c97abe5d5d7ae8c672bfddf4e1b91", product, foo, bar)); return ; } export const $$RSC_SERVER_ACTION_3 = async function deleteItem4($$ACTION_CLOSURE_BOUND) { @@ -34,7 +37,8 @@ export const $$RSC_SERVER_ACTION_3 = async function deleteItem4($$ACTION_CLOSURE await deleteFromDb($$ACTION_ARG_0.id, $$ACTION_ARG_0?.foo, $$ACTION_ARG_0.bar.baz, $$ACTION_ARG_0[// @ts-expect-error: deliberate useless comma $$ACTION_ARG_1, $$ACTION_ARG_2]); }; +registerServerReference($$RSC_SERVER_ACTION_3, "409ed0cc47abc4e1c64320cf42b74ae60b58c40f00", null); export function Item4(product, foo, bar) { - const deleteItem4 = registerServerReference($$RSC_SERVER_ACTION_3, "409ed0cc47abc4e1c64320cf42b74ae60b58c40f00", null).bind(null, encryptActionBoundArgs("409ed0cc47abc4e1c64320cf42b74ae60b58c40f00", product, foo, bar)); + const deleteItem4 = $$RSC_SERVER_ACTION_3.bind(null, encryptActionBoundArgs("409ed0cc47abc4e1c64320cf42b74ae60b58c40f00", product, foo, bar)); return ; } diff --git a/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/8/output.js b/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/8/output.js index 08b4dfab2eee2e..e85774dcd15311 100644 --- a/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/8/output.js +++ b/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/8/output.js @@ -6,7 +6,8 @@ export const $$RSC_SERVER_ACTION_0 = async function myAction(a, b, c) { 'use strict'; console.log('a'); }; -var myAction = registerServerReference($$RSC_SERVER_ACTION_0, "706a88810ecce4a4e8b59d53b8327d7e98bbf251d7", null); +registerServerReference($$RSC_SERVER_ACTION_0, "706a88810ecce4a4e8b59d53b8327d7e98bbf251d7", null); +var myAction = $$RSC_SERVER_ACTION_0; export default function Page() { return ; } diff --git a/crates/next-custom-transforms/tests/fixture/source-maps/server-graph/use-cache/1/output.js b/crates/next-custom-transforms/tests/fixture/source-maps/server-graph/use-cache/1/output.js index de904a61178ac4..c12c9472a9d1dd 100644 --- a/crates/next-custom-transforms/tests/fixture/source-maps/server-graph/use-cache/1/output.js +++ b/crates/next-custom-transforms/tests/fixture/source-maps/server-graph/use-cache/1/output.js @@ -2,16 +2,18 @@ import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption"; import { cache as $$cache__ } from "private-next-rsc-cache-wrapper"; export var $$RSC_SERVER_CACHE_0 = $$cache__("default", "803128060c414d59f8552e4788b846c0d2b7f74743", 0, async function() {}); +registerServerReference($$RSC_SERVER_CACHE_0, "803128060c414d59f8552e4788b846c0d2b7f74743", null); Object["defineProperty"]($$RSC_SERVER_CACHE_0, "name", { value: "foo", writable: false }); -const foo = registerServerReference($$RSC_SERVER_CACHE_0, "803128060c414d59f8552e4788b846c0d2b7f74743", null); +const foo = $$RSC_SERVER_CACHE_0; export var $$RSC_SERVER_CACHE_1 = $$cache__("default", "80951c375b4a6a6e89d67b743ec5808127cfde405d", 0, async function bar() { return foo(); }); +registerServerReference($$RSC_SERVER_CACHE_1, "80951c375b4a6a6e89d67b743ec5808127cfde405d", null); Object["defineProperty"]($$RSC_SERVER_CACHE_1, "name", { value: "bar", writable: false }); -export var bar = registerServerReference($$RSC_SERVER_CACHE_1, "80951c375b4a6a6e89d67b743ec5808127cfde405d", null); +export var bar = $$RSC_SERVER_CACHE_1; diff --git a/crates/next-custom-transforms/tests/fixture/source-maps/server-graph/use-cache/1/output.map b/crates/next-custom-transforms/tests/fixture/source-maps/server-graph/use-cache/1/output.map index 5079c6ff2ecb0b..9c3bbcec03d873 100644 --- a/crates/next-custom-transforms/tests/fixture/source-maps/server-graph/use-cache/1/output.map +++ b/crates/next-custom-transforms/tests/fixture/source-maps/server-graph/use-cache/1/output.map @@ -1 +1 @@ -{"version":3,"sources":["input.js"],"sourcesContent":["'use cache'\n\nconst foo = async () => {\n 'use cache'\n}\n\nexport async function bar() {\n return foo()\n}\n"],"names":[],"mappings":";;;WAEY,+GAEZ;;;;;AAFA,MAAM,MAAM;WAIL,6FAAA,eAAe;IACpB,OAAO;AACT;;;;;AAFA,WAAsB,MAAf"} +{"version":3,"sources":["input.js"],"sourcesContent":["'use cache'\n\nconst foo = async () => {\n 'use cache'\n}\n\nexport async function bar() {\n return foo()\n}\n"],"names":[],"mappings":";;;WAEY,+GAEZ;AAFY;;;;;AAAZ,MAAM;WAIC,6FAAA,eAAe;IACpB,OAAO;AACT;;;;;;AAFA,WAAsB"} diff --git a/test/e2e/app-dir/use-cache-with-server-function-props/app/layout.tsx b/test/e2e/app-dir/use-cache-with-server-function-props/app/layout.tsx new file mode 100644 index 00000000000000..c684c430e068a8 --- /dev/null +++ b/test/e2e/app-dir/use-cache-with-server-function-props/app/layout.tsx @@ -0,0 +1,20 @@ +import Link from 'next/link' +import { ReactNode } from 'react' + +export default function Root({ children }: { children: ReactNode }) { + return ( + + + +
{children}
+ + + ) +} diff --git a/test/e2e/app-dir/use-cache-with-server-function-props/app/nested-cache/form.tsx b/test/e2e/app-dir/use-cache-with-server-function-props/app/nested-cache/form.tsx new file mode 100644 index 00000000000000..12ea4522925a3c --- /dev/null +++ b/test/e2e/app-dir/use-cache-with-server-function-props/app/nested-cache/form.tsx @@ -0,0 +1,29 @@ +'use client' + +import { useActionState } from 'react' + +export function Form({ + getDate, + getRandom, +}: { + getDate: () => Promise + getRandom: () => Promise +}) { + const [date, formAction, isDatePending] = useActionState(getDate, null) + + const [random, buttonAction, isRandomPending] = useActionState( + getRandom, + null + ) + + return ( +
+ {' '} + +

{isDatePending ? 'loading...' : date}

+

{isRandomPending ? 'loading...' : random}

+
+ ) +} diff --git a/test/e2e/app-dir/use-cache-with-server-function-props/app/nested-cache/page.tsx b/test/e2e/app-dir/use-cache-with-server-function-props/app/nested-cache/page.tsx new file mode 100644 index 00000000000000..5846cb99a21dcc --- /dev/null +++ b/test/e2e/app-dir/use-cache-with-server-function-props/app/nested-cache/page.tsx @@ -0,0 +1,36 @@ +import { connection } from 'next/server' +import { Suspense } from 'react' +import { Form } from './form' + +export default function Page() { + return ( +
+ Loading...}> + + + +
+ ) +} + +async function CachedForm() { + 'use cache' + + return ( +
{ + 'use cache' + return new Date().toISOString() + }} + getRandom={async function getRandom() { + 'use cache' + return Math.random() + }} + /> + ) +} + +const Dynamic = async () => { + await connection() + return

Dynamic

+} diff --git a/test/e2e/app-dir/use-cache-with-server-function-props/app/page.tsx b/test/e2e/app-dir/use-cache-with-server-function-props/app/page.tsx new file mode 100644 index 00000000000000..c17431379f962f --- /dev/null +++ b/test/e2e/app-dir/use-cache-with-server-function-props/app/page.tsx @@ -0,0 +1,3 @@ +export default function Page() { + return null +} diff --git a/test/e2e/app-dir/use-cache-with-server-function-props/app/server-action/form.tsx b/test/e2e/app-dir/use-cache-with-server-function-props/app/server-action/form.tsx new file mode 100644 index 00000000000000..ff270a9f83eca7 --- /dev/null +++ b/test/e2e/app-dir/use-cache-with-server-function-props/app/server-action/form.tsx @@ -0,0 +1,25 @@ +'use client' + +import { useActionState } from 'react' + +export function Form({ + sayHi, + sayHello, +}: { + sayHi: () => Promise + sayHello: () => Promise +}) { + const [hi, hiAction, isHiPending] = useActionState(sayHi, null) + const [hello, helloAction, isHelloPending] = useActionState(sayHello, null) + + return ( + + {' '} + +

{isHiPending ? 'loading...' : hi}

+

{isHelloPending ? 'loading...' : hello}

+ + ) +} diff --git a/test/e2e/app-dir/use-cache-with-server-function-props/app/server-action/page.tsx b/test/e2e/app-dir/use-cache-with-server-function-props/app/server-action/page.tsx new file mode 100644 index 00000000000000..5ab4d75a593973 --- /dev/null +++ b/test/e2e/app-dir/use-cache-with-server-function-props/app/server-action/page.tsx @@ -0,0 +1,36 @@ +import { connection } from 'next/server' +import { Suspense } from 'react' +import { Form } from './form' + +export default function Page() { + return ( +
+ Loading...}> + + + +
+ ) +} + +async function CachedForm({ subject }: { subject: string }) { + 'use cache' + + return ( +
{ + 'use server' + return `Hello, ${subject}!` + }} + /> + ) +} + +const Dynamic = async () => { + await connection() + return

Dynamic

+} diff --git a/test/e2e/app-dir/use-cache-with-server-function-props/next.config.js b/test/e2e/app-dir/use-cache-with-server-function-props/next.config.js new file mode 100644 index 00000000000000..bea0706290af6b --- /dev/null +++ b/test/e2e/app-dir/use-cache-with-server-function-props/next.config.js @@ -0,0 +1,11 @@ +/** + * @type {import('next').NextConfig} + */ +const nextConfig = { + experimental: { + ppr: true, + useCache: true, + }, +} + +module.exports = nextConfig diff --git a/test/e2e/app-dir/use-cache-with-server-function-props/use-cache-with-server-function-props.test.ts b/test/e2e/app-dir/use-cache-with-server-function-props/use-cache-with-server-function-props.test.ts new file mode 100644 index 00000000000000..b2c84924a828d4 --- /dev/null +++ b/test/e2e/app-dir/use-cache-with-server-function-props/use-cache-with-server-function-props.test.ts @@ -0,0 +1,39 @@ +import { nextTestSetup } from 'e2e-utils' +import { retry } from 'next-test-utils' + +const isoDateRegExp = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/ +const randomRegExp = /^\d+\.\d+$/ + +describe('use-cache-with-server-function-props', () => { + const { next } = nextTestSetup({ + files: __dirname, + }) + + it('should be able to use inline server actions as props', async () => { + const browser = await next.browser('/server-action') + + await browser.elementById('submit-button-hi').click() + await retry(async () => { + expect(await browser.elementById('hi').text()).toMatch('Hi, World!') + }) + + await browser.elementById('submit-button-hello').click() + await retry(async () => { + expect(await browser.elementById('hello').text()).toMatch('Hello, World!') + }) + }) + + it('should be able to use nested cache functions as props', async () => { + const browser = await next.browser('/nested-cache') + + await browser.elementById('submit-button-date').click() + await retry(async () => { + expect(await browser.elementById('date').text()).toMatch(isoDateRegExp) + }) + + await browser.elementById('submit-button-random').click() + await retry(async () => { + expect(await browser.elementById('random').text()).toMatch(randomRegExp) + }) + }) +}) diff --git a/test/ppr-tests-manifest.json b/test/ppr-tests-manifest.json index 32d34ee70e6089..2561d9ef55be0e 100644 --- a/test/ppr-tests-manifest.json +++ b/test/ppr-tests-manifest.json @@ -172,6 +172,7 @@ "test/e2e/app-dir/use-cache-hanging-inputs/**/*", "test/e2e/app-dir/use-cache-metadata-route-handler/**/*", "test/e2e/app-dir/use-cache-route-handler-only/**/*", + "test/e2e/app-dir/use-cache-with-server-function-props/use-cache-with-server-function-props.test.ts", "test/integration/app-dir-export/**/*", "test/production/app-dir/build-output-tree-view/build-output-tree-view.test.ts", "test/production/app-dir/global-default-cache-handler/global-default-cache-handler.test.ts"