diff --git a/crates/next-custom-transforms/src/transforms/server_actions.rs b/crates/next-custom-transforms/src/transforms/server_actions.rs index 620ddf7303882..3da2d65b2c531 100644 --- a/crates/next-custom-transforms/src/transforms/server_actions.rs +++ b/crates/next-custom-transforms/src/transforms/server_actions.rs @@ -545,9 +545,6 @@ impl ServerActions { ..Default::default() }), }, - decorators: vec![], - span: DUMMY_SP, - is_generator: false, is_async: true, ..Default::default() }), @@ -752,44 +749,49 @@ impl ServerActions { }); } - // Create the action export decl from the arrow function - // export var cache_ident = async function() {} + let inner_fn_body = match *arrow.body.take() { + BlockStmtOrExpr::BlockStmt(body) => Some(body), + BlockStmtOrExpr::Expr(expr) => Some(BlockStmt { + stmts: vec![Stmt::Return(ReturnStmt { + span: DUMMY_SP, + arg: Some(expr), + })], + ..Default::default() + }), + }; + + let inner_fn = Box::new(Expr::Fn(FnExpr { + ident: None, + function: Box::new(Function { + params: new_params.clone(), + body: inner_fn_body, + span: arrow.span, + is_generator: false, + is_async: true, + ..Default::default() + }), + })); + + // Wrap with $$reactCache__(function foo() { return $$cache__(...) }) + let wrapper_fn = wrap_cache_expr( + cache_kind.as_str(), + reference_id.as_str(), + ids_from_closure.len(), + inner_fn, + self.arrow_or_fn_expr_ident.clone(), + arrow.span, + ); + + // Create the export: export var $$RSC_SERVER_CACHE_0 = ... self.hoisted_extra_items .push(ModuleItem::ModuleDecl(ModuleDecl::ExportDecl(ExportDecl { span: DUMMY_SP, decl: VarDecl { - span: DUMMY_SP, kind: VarDeclKind::Var, decls: vec![VarDeclarator { span: arrow.span, name: Pat::Ident(cache_ident.clone().into()), - init: Some(wrap_cache_expr( - Box::new(Expr::Fn(FnExpr { - ident: None, - function: Box::new(Function { - params: new_params, - body: match *arrow.body.take() { - BlockStmtOrExpr::BlockStmt(body) => Some(body), - BlockStmtOrExpr::Expr(expr) => Some(BlockStmt { - span: DUMMY_SP, - stmts: vec![Stmt::Return(ReturnStmt { - span: DUMMY_SP, - arg: Some(expr), - })], - ..Default::default() - }), - }, - decorators: vec![], - span: DUMMY_SP, - is_generator: false, - is_async: true, - ..Default::default() - }), - })), - &cache_kind, - &reference_id, - ids_from_closure.len(), - )), + init: Some(wrapper_fn), definite: false, }], ..Default::default() @@ -866,28 +868,40 @@ impl ServerActions { private_ctxt: self.private_ctxt, }); - // export var cache_ident = async function() {} + let function_body = function.body.take(); + let function_span = function.span; + + let inner_fn = Box::new(Expr::Fn(FnExpr { + ident: fn_name.clone(), + function: Box::new(Function { + params: new_params.clone(), + body: function_body, + span: function_span, + is_async: true, + ..function.take() + }), + })); + + // Wrap with $$reactCache__(function foo() { return $$cache__(...) }) + let wrapper_fn = wrap_cache_expr( + cache_kind.as_str(), + reference_id.as_str(), + ids_from_closure.len(), + inner_fn, + fn_name.clone(), + function_span, + ); + + // Create the export: export var $$RSC_SERVER_CACHE_0 = ... self.hoisted_extra_items .push(ModuleItem::ModuleDecl(ModuleDecl::ExportDecl(ExportDecl { span: DUMMY_SP, decl: VarDecl { - span: DUMMY_SP, kind: VarDeclKind::Var, decls: vec![VarDeclarator { - span: function.span, + span: function_span, name: Pat::Ident(cache_ident.clone().into()), - init: Some(wrap_cache_expr( - Box::new(Expr::Fn(FnExpr { - ident: fn_name.clone(), - function: Box::new(Function { - params: new_params, - ..function.take() - }), - })), - &cache_kind, - &reference_id, - ids_from_closure.len(), - )), + init: Some(wrapper_fn), definite: false, }], ..Default::default() @@ -901,7 +915,7 @@ impl ServerActions { expr: Box::new(annotate_ident_as_server_reference( cache_ident.clone(), reference_id.clone(), - function.span, + function_span, )), }))); @@ -2049,6 +2063,7 @@ impl VisitMut for ServerActions { } // import { cache as $$cache__ } from "private-next-rsc-cache-wrapper"; + // import { cache as $$reactCache__ } from "react"; if self.has_cache && self.config.is_react_server_layer { new.push(ModuleItem::ModuleDecl(ModuleDecl::Import(ImportDecl { span: DUMMY_SP, @@ -2068,8 +2083,26 @@ impl VisitMut for ServerActions { phase: Default::default(), }))); - // Make it the first item - new.rotate_right(1); + new.push(ModuleItem::ModuleDecl(ModuleDecl::Import(ImportDecl { + span: DUMMY_SP, + specifiers: vec![ImportSpecifier::Named(ImportNamedSpecifier { + span: DUMMY_SP, + local: quote_ident!("$$reactCache__").into(), + imported: Some(quote_ident!("cache").into()), + is_type_only: false, + })], + src: Box::new(Str { + span: DUMMY_SP, + value: atom!("react"), + raw: None, + }), + type_only: false, + with: None, + phase: Default::default(), + }))); + + // Make them the first items + new.rotate_right(2); } if (self.has_action || self.has_cache) && self.config.is_react_server_layer { @@ -2379,24 +2412,64 @@ fn retain_names_from_declared_idents( *child_names = retained_names; } -fn wrap_cache_expr(expr: Box, name: &str, id: &str, bound_args_len: usize) -> Box { - // expr -> $$cache__("name", "id", 0, expr) - Box::new(Expr::Call(CallExpr { - span: DUMMY_SP, +fn wrap_cache_expr( + cache_kind: &str, + reference_id: &str, + bound_args_length: usize, + inner_fn: Box, + fn_ident: Option, + original_span: Span, +) -> Box { + let cache_call = CallExpr { + span: original_span, callee: quote_ident!("$$cache__").as_callee(), args: vec![ ExprOrSpread { spread: None, - expr: Box::new(name.into()), + expr: Box::new(cache_kind.into()), + }, + ExprOrSpread { + spread: None, + expr: Box::new(reference_id.into()), + }, + ExprOrSpread { + spread: None, + expr: Box::new(Expr::Lit(Lit::Num(Number { + span: DUMMY_SP, + value: bound_args_length as f64, + raw: None, + }))), }, + inner_fn.as_arg(), ExprOrSpread { spread: None, - expr: Box::new(id.into()), + expr: Box::new(Expr::Ident(private_ident!(DUMMY_SP, "arguments"))), }, - Number::from(bound_args_len).as_arg(), - expr.as_arg(), ], ..Default::default() + }; + + // This wrapper function ensures that we have a user-space call stack frame. + let wrapper_fn = Box::new(Expr::Fn(FnExpr { + ident: fn_ident, + function: Box::new(Function { + body: Some(BlockStmt { + span: DUMMY_SP, + stmts: vec![Stmt::Return(ReturnStmt { + span: DUMMY_SP, + arg: Some(Box::new(Expr::Call(cache_call))), + })], + ..Default::default() + }), + span: original_span, + ..Default::default() + }), + })); + + Box::new(Expr::Call(CallExpr { + callee: quote_ident!("$$reactCache__").as_callee(), + args: vec![wrapper_fn.as_arg()], + ..Default::default() })) } 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 6fd4ffd10ac18..fbc7d67790a2f 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 @@ -1,10 +1,13 @@ /* __next_internal_action_entry_do_not_use__ {"c0dd5bb6fef67f5ab84327f5164ac2c3111a159337":"$$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 { cache as $$reactCache__ } from "react"; import React from 'react'; import inter from '@next/font/google/target.css?{"path":"app/test.tsx","import":"Inter","arguments":[],"variableName":"inter"}'; -export var $$RSC_SERVER_CACHE_0 = $$cache__("default", "c0dd5bb6fef67f5ab84327f5164ac2c3111a159337", 0, async function Cached({ children }) { - return
{children}
; +export var $$RSC_SERVER_CACHE_0 = $$reactCache__(function Cached() { + return $$cache__("default", "c0dd5bb6fef67f5ab84327f5164ac2c3111a159337", 0, async function Cached({ children }) { + return
{children}
; + }, arguments); }); registerServerReference($$RSC_SERVER_CACHE_0, "c0dd5bb6fef67f5ab84327f5164ac2c3111a159337", null); Object["defineProperty"]($$RSC_SERVER_CACHE_0, "name", { diff --git a/crates/next-custom-transforms/tests/fixture/server-actions/next.d.ts b/crates/next-custom-transforms/tests/fixture/server-actions/next.d.ts index befe558c27831..2e19662d526a8 100644 --- a/crates/next-custom-transforms/tests/fixture/server-actions/next.d.ts +++ b/crates/next-custom-transforms/tests/fixture/server-actions/next.d.ts @@ -44,6 +44,7 @@ declare module 'private-next-rsc-cache-wrapper' { kind: string, id: string, boundArgsLength: number, - fn: TFn - ): TFn + fn: TFn, + argsObj: IArguments + ): Promise } 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 3c6c43a7775b7..034ece8e19a61 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 @@ -1,9 +1,12 @@ /* __next_internal_action_entry_do_not_use__ {"803128060c414d59f8552e4788b846c0d2b7f74743":"$$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 { cache as $$reactCache__ } from "react"; const v = 'world'; -export var $$RSC_SERVER_CACHE_0 = $$cache__("default", "803128060c414d59f8552e4788b846c0d2b7f74743", 0, async function fn() { - return 'hello, ' + v; +export var $$RSC_SERVER_CACHE_0 = $$reactCache__(function fn() { + return $$cache__("default", "803128060c414d59f8552e4788b846c0d2b7f74743", 0, async function fn() { + return 'hello, ' + v; + }, arguments); }); registerServerReference($$RSC_SERVER_CACHE_0, "803128060c414d59f8552e4788b846c0d2b7f74743", null); Object["defineProperty"]($$RSC_SERVER_CACHE_0, "name", { 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 7d387cf83de75..2769b42858ad9 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 @@ -1,8 +1,11 @@ /* __next_internal_action_entry_do_not_use__ {"8012a8d21b6362b4cc8f5b15560525095bc48dba80":"$$RSC_SERVER_CACHE_3","803128060c414d59f8552e4788b846c0d2b7f74743":"$$RSC_SERVER_CACHE_0","8069348c79fce073bae2f70f139565a2fda1c74c74":"$$RSC_SERVER_CACHE_2","80951c375b4a6a6e89d67b743ec5808127cfde405d":"$$RSC_SERVER_CACHE_1"} */ 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", "803128060c414d59f8552e4788b846c0d2b7f74743", 0, async function() { - return 'foo'; +import { cache as $$reactCache__ } from "react"; +export var $$RSC_SERVER_CACHE_0 = $$reactCache__(function foo() { + return $$cache__("default", "803128060c414d59f8552e4788b846c0d2b7f74743", 0, async function() { + return 'foo'; + }, arguments); }); registerServerReference($$RSC_SERVER_CACHE_0, "803128060c414d59f8552e4788b846c0d2b7f74743", null); Object["defineProperty"]($$RSC_SERVER_CACHE_0, "name", { @@ -11,8 +14,10 @@ Object["defineProperty"]($$RSC_SERVER_CACHE_0, "name", { }); const foo = $$RSC_SERVER_CACHE_0; export { bar }; -export var $$RSC_SERVER_CACHE_1 = $$cache__("default", "80951c375b4a6a6e89d67b743ec5808127cfde405d", 0, async function bar() { - return 'bar'; +export var $$RSC_SERVER_CACHE_1 = $$reactCache__(function bar() { + return $$cache__("default", "80951c375b4a6a6e89d67b743ec5808127cfde405d", 0, async function bar() { + return 'bar'; + }, arguments); }); registerServerReference($$RSC_SERVER_CACHE_1, "80951c375b4a6a6e89d67b743ec5808127cfde405d", null); Object["defineProperty"]($$RSC_SERVER_CACHE_1, "name", { @@ -24,8 +29,10 @@ var bar = $$RSC_SERVER_CACHE_1; const qux = async function qux() { return 'qux'; }; -export var $$RSC_SERVER_CACHE_2 = $$cache__("default", "8069348c79fce073bae2f70f139565a2fda1c74c74", 0, async function baz() { - return qux() + 'baz'; +export var $$RSC_SERVER_CACHE_2 = $$reactCache__(function baz() { + return $$cache__("default", "8069348c79fce073bae2f70f139565a2fda1c74c74", 0, async function baz() { + return qux() + 'baz'; + }, arguments); }); registerServerReference($$RSC_SERVER_CACHE_2, "8069348c79fce073bae2f70f139565a2fda1c74c74", null); Object["defineProperty"]($$RSC_SERVER_CACHE_2, "name", { @@ -33,8 +40,10 @@ Object["defineProperty"]($$RSC_SERVER_CACHE_2, "name", { writable: false }); const baz = $$RSC_SERVER_CACHE_2; -export var $$RSC_SERVER_CACHE_3 = $$cache__("default", "8012a8d21b6362b4cc8f5b15560525095bc48dba80", 0, async function() { - return 'quux'; +export var $$RSC_SERVER_CACHE_3 = $$reactCache__(function quux() { + return $$cache__("default", "8012a8d21b6362b4cc8f5b15560525095bc48dba80", 0, async function() { + return 'quux'; + }, arguments); }); registerServerReference($$RSC_SERVER_CACHE_3, "8012a8d21b6362b4cc8f5b15560525095bc48dba80", null); Object["defineProperty"]($$RSC_SERVER_CACHE_3, "name", { 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 23c08a193de83..7e482e8c37937 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 @@ -1,8 +1,11 @@ /* __next_internal_action_entry_do_not_use__ {"803128060c414d59f8552e4788b846c0d2b7f74743":"$$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", "803128060c414d59f8552e4788b846c0d2b7f74743", 0, async function() { - return 'data'; +import { cache as $$reactCache__ } from "react"; +export var $$RSC_SERVER_CACHE_0 = $$reactCache__(function my_fn() { + return $$cache__("default", "803128060c414d59f8552e4788b846c0d2b7f74743", 0, async function() { + return 'data'; + }, arguments); }); registerServerReference($$RSC_SERVER_CACHE_0, "803128060c414d59f8552e4788b846c0d2b7f74743", null); Object["defineProperty"]($$RSC_SERVER_CACHE_0, "name", { 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 0640df39823e7..5c30e24ef6d67 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 @@ -1,8 +1,11 @@ /* __next_internal_action_entry_do_not_use__ {"8012a8d21b6362b4cc8f5b15560525095bc48dba80":"$$RSC_SERVER_CACHE_3","803128060c414d59f8552e4788b846c0d2b7f74743":"$$RSC_SERVER_CACHE_0","80951c375b4a6a6e89d67b743ec5808127cfde405d":"$$RSC_SERVER_CACHE_1","c069348c79fce073bae2f70f139565a2fda1c74c74":"$$RSC_SERVER_CACHE_2"} */ 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", "803128060c414d59f8552e4788b846c0d2b7f74743", 0, async function foo() { - return 'data A'; +import { cache as $$reactCache__ } from "react"; +export var $$RSC_SERVER_CACHE_0 = $$reactCache__(function foo() { + return $$cache__("default", "803128060c414d59f8552e4788b846c0d2b7f74743", 0, async function foo() { + return 'data A'; + }, arguments); }); registerServerReference($$RSC_SERVER_CACHE_0, "803128060c414d59f8552e4788b846c0d2b7f74743", null); Object["defineProperty"]($$RSC_SERVER_CACHE_0, "name", { @@ -10,8 +13,10 @@ Object["defineProperty"]($$RSC_SERVER_CACHE_0, "name", { writable: false }); export var foo = $$RSC_SERVER_CACHE_0; -export var $$RSC_SERVER_CACHE_1 = $$cache__("default", "80951c375b4a6a6e89d67b743ec5808127cfde405d", 0, async function bar() { - return 'data B'; +export var $$RSC_SERVER_CACHE_1 = $$reactCache__(function bar() { + return $$cache__("default", "80951c375b4a6a6e89d67b743ec5808127cfde405d", 0, async function bar() { + return 'data B'; + }, arguments); }); registerServerReference($$RSC_SERVER_CACHE_1, "80951c375b4a6a6e89d67b743ec5808127cfde405d", null); Object["defineProperty"]($$RSC_SERVER_CACHE_1, "name", { @@ -19,8 +24,10 @@ Object["defineProperty"]($$RSC_SERVER_CACHE_1, "name", { writable: false }); export var bar = $$RSC_SERVER_CACHE_1; -export var $$RSC_SERVER_CACHE_2 = $$cache__("default", "c069348c79fce073bae2f70f139565a2fda1c74c74", 0, async function Cached({ children }) { - return children; +export var $$RSC_SERVER_CACHE_2 = $$reactCache__(function Cached() { + return $$cache__("default", "c069348c79fce073bae2f70f139565a2fda1c74c74", 0, async function Cached({ children }) { + return children; + }, arguments); }); registerServerReference($$RSC_SERVER_CACHE_2, "c069348c79fce073bae2f70f139565a2fda1c74c74", null); Object["defineProperty"]($$RSC_SERVER_CACHE_2, "name", { @@ -28,8 +35,10 @@ Object["defineProperty"]($$RSC_SERVER_CACHE_2, "name", { writable: false }); export default $$RSC_SERVER_CACHE_2; -export var $$RSC_SERVER_CACHE_3 = $$cache__("default", "8012a8d21b6362b4cc8f5b15560525095bc48dba80", 0, async function baz() { - return 'data C'; +export var $$RSC_SERVER_CACHE_3 = $$reactCache__(function baz() { + return $$cache__("default", "8012a8d21b6362b4cc8f5b15560525095bc48dba80", 0, async function baz() { + return 'data C'; + }, arguments); }); registerServerReference($$RSC_SERVER_CACHE_3, "8012a8d21b6362b4cc8f5b15560525095bc48dba80", null); Object["defineProperty"]($$RSC_SERVER_CACHE_3, "name", { 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 30e6223c88ba2..6eb0199d1e85a 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 @@ -1,8 +1,11 @@ /* __next_internal_action_entry_do_not_use__ {"803128060c414d59f8552e4788b846c0d2b7f74743":"$$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", "803128060c414d59f8552e4788b846c0d2b7f74743", 0, async function fn() { - return 'foo'; +import { cache as $$reactCache__ } from "react"; +export var $$RSC_SERVER_CACHE_0 = $$reactCache__(function fn() { + return $$cache__("default", "803128060c414d59f8552e4788b846c0d2b7f74743", 0, async function fn() { + return 'foo'; + }, arguments); }); registerServerReference($$RSC_SERVER_CACHE_0, "803128060c414d59f8552e4788b846c0d2b7f74743", null); Object["defineProperty"]($$RSC_SERVER_CACHE_0, "name", { 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 e0de6fb1bda5a..4e7e15e2dc3c6 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 @@ -1,8 +1,11 @@ /* __next_internal_action_entry_do_not_use__ {"803128060c414d59f8552e4788b846c0d2b7f74743":"$$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__("x", "803128060c414d59f8552e4788b846c0d2b7f74743", 0, async function foo() { - return 'data'; +import { cache as $$reactCache__ } from "react"; +export var $$RSC_SERVER_CACHE_0 = $$reactCache__(function foo() { + return $$cache__("x", "803128060c414d59f8552e4788b846c0d2b7f74743", 0, async function foo() { + return 'data'; + }, arguments); }); registerServerReference($$RSC_SERVER_CACHE_0, "803128060c414d59f8552e4788b846c0d2b7f74743", null); Object["defineProperty"]($$RSC_SERVER_CACHE_0, "name", { diff --git a/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/39/input.js b/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/39/input.js index f3d9f13465bfa..9d1bf1061be00 100644 --- a/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/39/input.js +++ b/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/39/input.js @@ -10,6 +10,6 @@ async function Component({ foo }) { } const data = await fn() - // @ts-expect-error: data is not a valid react child + // @ts-ignore: data is not a valid react child return
{data}
} 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 3eb7a29401101..b57a82ca6e457 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 @@ -1,11 +1,14 @@ /* __next_internal_action_entry_do_not_use__ {"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 fn([$$ACTION_ARG_0, $$ACTION_ARG_1]) { - console.log($$ACTION_ARG_0); - return { - foo: $$ACTION_ARG_1 - }; +import { cache as $$reactCache__ } from "react"; +export var $$RSC_SERVER_CACHE_0 = $$reactCache__(function fn() { + return $$cache__("default", "c03128060c414d59f8552e4788b846c0d2b7f74743", 2, async function fn([$$ACTION_ARG_0, $$ACTION_ARG_1]) { + console.log($$ACTION_ARG_0); + return { + foo: $$ACTION_ARG_1 + }; + }, arguments); }); registerServerReference($$RSC_SERVER_CACHE_0, "c03128060c414d59f8552e4788b846c0d2b7f74743", null); Object["defineProperty"]($$RSC_SERVER_CACHE_0, "name", { @@ -16,6 +19,6 @@ async function Component({ foo }) { const a = 123; 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 + // @ts-ignore: data is not a valid react child return
{data}
; } 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 8f6dc9e32f95f..abce8c606bc8b 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,15 +1,18 @@ /* __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 { cache as $$reactCache__ } from "react"; import { Form } from 'components'; -export var $$RSC_SERVER_CACHE_0 = $$cache__("default", "e03128060c414d59f8552e4788b846c0d2b7f74743", 2, async function cache([$$ACTION_ARG_0, $$ACTION_ARG_1], e) { - const f = $$ACTION_ARG_0 + e; - return [ - f, - { - a: $$ACTION_ARG_1 - } - ]; +export var $$RSC_SERVER_CACHE_0 = $$reactCache__(function cache() { + return $$cache__("default", "e03128060c414d59f8552e4788b846c0d2b7f74743", 2, async function cache([$$ACTION_ARG_0, $$ACTION_ARG_1], e) { + const f = $$ACTION_ARG_0 + e; + return [ + f, + { + a: $$ACTION_ARG_1 + } + ]; + }, arguments); }); registerServerReference($$RSC_SERVER_CACHE_0, "e03128060c414d59f8552e4788b846c0d2b7f74743", null); Object["defineProperty"]($$RSC_SERVER_CACHE_0, "name", { 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 e52be8748e992..f321824c6d8c8 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 @@ -1,6 +1,7 @@ /* __next_internal_action_entry_do_not_use__ {"406a88810ecce4a4e8b59d53b8327d7e98bbf251d7":"$$RSC_SERVER_ACTION_0","c0951c375b4a6a6e89d67b743ec5808127cfde405d":"$$RSC_SERVER_CACHE_1"} */ 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 { cache as $$reactCache__ } from "react"; export const $$RSC_SERVER_ACTION_0 = async function fn($$ACTION_CLOSURE_BOUND) { var [$$ACTION_ARG_0, $$ACTION_ARG_1] = await decryptActionBoundArgs("406a88810ecce4a4e8b59d53b8327d7e98bbf251d7", $$ACTION_CLOSURE_BOUND); console.log($$ACTION_ARG_0); @@ -9,12 +10,14 @@ export const $$RSC_SERVER_ACTION_0 = async function fn($$ACTION_CLOSURE_BOUND) { }; }; 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 = $$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}
; +export var $$RSC_SERVER_CACHE_1 = $$reactCache__(function Component() { + return $$cache__("default", "c0951c375b4a6a6e89d67b743ec5808127cfde405d", 0, async function Component({ foo }) { + const a = 123; + 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}
; + }, arguments); }); registerServerReference($$RSC_SERVER_CACHE_1, "c0951c375b4a6a6e89d67b743ec5808127cfde405d", null); Object["defineProperty"]($$RSC_SERVER_CACHE_1, "name", { diff --git a/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/42/input.js b/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/42/input.js index a5d450374855f..6cd45bb82972e 100644 --- a/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/42/input.js +++ b/crates/next-custom-transforms/tests/fixture/server-actions/server-graph/42/input.js @@ -10,6 +10,6 @@ async function Component({ foo }) { } const data = await fn() - // @ts-expect-error: data is not a valid react child + // @ts-ignore: data is not a valid react child return
{data}
} 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 b22cae0e87eac..58b929d549c26 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 @@ -1,11 +1,14 @@ /* __next_internal_action_entry_do_not_use__ {"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([$$ACTION_ARG_0, $$ACTION_ARG_1]) { - console.log($$ACTION_ARG_0); - return { - foo: $$ACTION_ARG_1 - }; +import { cache as $$reactCache__ } from "react"; +export var $$RSC_SERVER_CACHE_0 = $$reactCache__(function fn() { + return $$cache__("default", "c03128060c414d59f8552e4788b846c0d2b7f74743", 2, async function([$$ACTION_ARG_0, $$ACTION_ARG_1]) { + console.log($$ACTION_ARG_0); + return { + foo: $$ACTION_ARG_1 + }; + }, arguments); }); registerServerReference($$RSC_SERVER_CACHE_0, "c03128060c414d59f8552e4788b846c0d2b7f74743", null); Object["defineProperty"]($$RSC_SERVER_CACHE_0, "name", { @@ -16,6 +19,6 @@ async function Component({ foo }) { const a = 123; 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 + // @ts-ignore: data is not a valid react child return
{data}
; } 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 44e8130c1e01a..9edbf417ade20 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 @@ -1,6 +1,7 @@ /* __next_internal_action_entry_do_not_use__ {"406a88810ecce4a4e8b59d53b8327d7e98bbf251d7":"$$RSC_SERVER_ACTION_0","e0951c375b4a6a6e89d67b743ec5808127cfde405d":"$$RSC_SERVER_CACHE_1"} */ 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 { cache as $$reactCache__ } from "react"; import { Button } from 'components'; const secret = 'my password is qwerty123'; export const $$RSC_SERVER_ACTION_0 = async function action($$ACTION_CLOSURE_BOUND) { @@ -8,13 +9,15 @@ export const $$RSC_SERVER_ACTION_0 = async function action($$ACTION_CLOSURE_BOUN 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: