From 0772aab4d925f260ff0ba4730b4eedb6423f71a5 Mon Sep 17 00:00:00 2001 From: Janka Uryga Date: Thu, 7 Nov 2024 15:03:50 +0100 Subject: [PATCH 1/7] wip: decrypt bound args before generating a cache key --- .../src/transforms/server_actions.rs | 47 +++++++------------ .../server-actions/server/33/output.js | 2 +- .../server-actions/server/34/output.js | 8 ++-- .../server-actions/server/35/output.js | 2 +- .../server-actions/server/36/output.js | 8 ++-- .../server-actions/server/37/output.js | 2 +- .../server-actions/server/38/output.js | 2 +- .../server-actions/server/39/output.js | 4 +- .../server-actions/server/40/output.js | 4 +- .../server-actions/server/41/output.js | 2 +- .../server-actions/server/42/output.js | 4 +- .../server-actions/server/43/output.js | 2 +- .../server-actions/server/45/output.js | 2 +- .../server-actions/server/46/output.js | 6 +-- .../server-actions/server/48/output.js | 2 +- .../server-actions/server/49/output.js | 2 +- .../server-actions/server/50/output.js | 2 +- .../src/server/use-cache/use-cache-wrapper.ts | 27 ++++++++++- 18 files changed, 69 insertions(+), 59 deletions(-) diff --git a/crates/next-custom-transforms/src/transforms/server_actions.rs b/crates/next-custom-transforms/src/transforms/server_actions.rs index 29d25fca83ca7..b938931a004cf 100644 --- a/crates/next-custom-transforms/src/transforms/server_actions.rs +++ b/crates/next-custom-transforms/src/transforms/server_actions.rs @@ -644,7 +644,7 @@ impl ServerActions { .into(), ))); } - let decryption_decl = VarDecl { + let args_decl = VarDecl { span: DUMMY_SP, kind: VarDeclKind::Var, declare: false, @@ -656,18 +656,9 @@ impl ServerActions { optional: false, type_ann: None, }), - init: Some(Box::new(Expr::Await(AwaitExpr { - span: DUMMY_SP, - arg: Box::new(Expr::Call(CallExpr { - span: DUMMY_SP, - callee: quote_ident!("decryptActionBoundArgs").as_callee(), - args: vec![ - reference_id.clone().as_arg(), - quote_ident!("$$ACTION_CLOSURE_BOUND").as_arg(), - ], - ..Default::default() - })), - }))), + init: Some(Box::new(Expr::Ident( + quote_ident!("$$ACTION_CLOSURE_BOUND").into(), + ))), definite: Default::default(), }], ..Default::default() @@ -675,13 +666,13 @@ impl ServerActions { match &mut new_body { BlockStmtOrExpr::BlockStmt(body) => { - body.stmts.insert(0, decryption_decl.into()); + body.stmts.insert(0, args_decl.into()); } BlockStmtOrExpr::Expr(body_expr) => { new_body = BlockStmtOrExpr::BlockStmt(BlockStmt { span: DUMMY_SP, stmts: vec![ - decryption_decl.into(), + args_decl.into(), Stmt::Return(ReturnStmt { span: DUMMY_SP, arg: Some(body_expr.take()), @@ -737,6 +728,7 @@ impl ServerActions { })), cache_type, &reference_id, + !ids_from_closure.is_empty(), )), definite: false, }], @@ -853,7 +845,7 @@ impl ServerActions { .into(), ))); } - let decryption_decl = VarDecl { + let args_decl = VarDecl { span: DUMMY_SP, kind: VarDeclKind::Var, decls: vec![VarDeclarator { @@ -864,29 +856,20 @@ impl ServerActions { optional: false, type_ann: None, }), - init: Some(Box::new(Expr::Await(AwaitExpr { - span: DUMMY_SP, - arg: Box::new(Expr::Call(CallExpr { - span: DUMMY_SP, - callee: quote_ident!("decryptActionBoundArgs").as_callee(), - args: vec![ - reference_id.clone().as_arg(), - quote_ident!("$$ACTION_CLOSURE_BOUND").as_arg(), - ], - ..Default::default() - })), - }))), + init: Some(Box::new(Expr::Ident( + quote_ident!("$$ACTION_CLOSURE_BOUND").into(), + ))), definite: Default::default(), }], ..Default::default() }; if let Some(body) = &mut new_body { - body.stmts.insert(0, decryption_decl.into()); + body.stmts.insert(0, args_decl.into()); } else { new_body = Some(BlockStmt { span: DUMMY_SP, - stmts: vec![decryption_decl.into()], + stmts: vec![args_decl.into()], ..Default::default() }); } @@ -917,6 +900,7 @@ impl ServerActions { })), cache_type, &reference_id, + !ids_from_closure.is_empty(), )), definite: false, }], @@ -2270,7 +2254,7 @@ fn retain_names_from_declared_idents( *child_names = retained_names; } -fn wrap_cache_expr(expr: Box, name: &str, id: &str) -> Box { +fn wrap_cache_expr(expr: Box, name: &str, id: &str, has_bound_args: bool) -> Box { // expr -> $$cache__("name", "id", expr) Box::new(Expr::Call(CallExpr { span: DUMMY_SP, @@ -2284,6 +2268,7 @@ fn wrap_cache_expr(expr: Box, name: &str, id: &str) -> Box { spread: None, expr: Box::new(id.into()), }, + Bool::from(has_bound_args).as_arg(), expr.as_arg(), ], ..Default::default() diff --git a/crates/next-custom-transforms/tests/fixture/server-actions/server/33/output.js b/crates/next-custom-transforms/tests/fixture/server-actions/server/33/output.js index 086e124ba08ae..93f0dbba0b695 100644 --- a/crates/next-custom-transforms/tests/fixture/server-actions/server/33/output.js +++ b/crates/next-custom-transforms/tests/fixture/server-actions/server/33/output.js @@ -2,7 +2,7 @@ import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption"; import { cache as $$cache__ } from "private-next-rsc-cache-wrapper"; const v = 'world'; -export var $$RSC_SERVER_CACHE_0 = $$cache__("default", "803128060c414d59f8552e4788b846c0d2b7f74743", async function fn() { +export var $$RSC_SERVER_CACHE_0 = $$cache__("default", "803128060c414d59f8552e4788b846c0d2b7f74743", false, async function fn() { return 'hello, ' + v; }); Object.defineProperty($$RSC_SERVER_CACHE_0, "name", { diff --git a/crates/next-custom-transforms/tests/fixture/server-actions/server/34/output.js b/crates/next-custom-transforms/tests/fixture/server-actions/server/34/output.js index e334026349c47..c7d502c1f0436 100644 --- a/crates/next-custom-transforms/tests/fixture/server-actions/server/34/output.js +++ b/crates/next-custom-transforms/tests/fixture/server-actions/server/34/output.js @@ -1,7 +1,7 @@ /* __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", async function() { +export var $$RSC_SERVER_CACHE_0 = $$cache__("default", "803128060c414d59f8552e4788b846c0d2b7f74743", false, async function() { return 'foo'; }); Object.defineProperty($$RSC_SERVER_CACHE_0, "name", { @@ -10,7 +10,7 @@ Object.defineProperty($$RSC_SERVER_CACHE_0, "name", { }); const foo = registerServerReference($$RSC_SERVER_CACHE_0, "803128060c414d59f8552e4788b846c0d2b7f74743", null); export { bar }; -export var $$RSC_SERVER_CACHE_1 = $$cache__("default", "80951c375b4a6a6e89d67b743ec5808127cfde405d", async function bar() { +export var $$RSC_SERVER_CACHE_1 = $$cache__("default", "80951c375b4a6a6e89d67b743ec5808127cfde405d", false, async function bar() { return 'bar'; }); Object.defineProperty($$RSC_SERVER_CACHE_1, "name", { @@ -22,7 +22,7 @@ var bar = registerServerReference($$RSC_SERVER_CACHE_1, "80951c375b4a6a6e89d67b7 const qux = async function qux() { return 'qux'; }; -export var $$RSC_SERVER_CACHE_2 = $$cache__("default", "8069348c79fce073bae2f70f139565a2fda1c74c74", async function baz() { +export var $$RSC_SERVER_CACHE_2 = $$cache__("default", "8069348c79fce073bae2f70f139565a2fda1c74c74", false, async function baz() { return qux() + 'baz'; }); Object.defineProperty($$RSC_SERVER_CACHE_2, "name", { @@ -30,7 +30,7 @@ Object.defineProperty($$RSC_SERVER_CACHE_2, "name", { "writable": false }); const baz = registerServerReference($$RSC_SERVER_CACHE_2, "8069348c79fce073bae2f70f139565a2fda1c74c74", null); -export var $$RSC_SERVER_CACHE_3 = $$cache__("default", "8012a8d21b6362b4cc8f5b15560525095bc48dba80", async function() { +export var $$RSC_SERVER_CACHE_3 = $$cache__("default", "8012a8d21b6362b4cc8f5b15560525095bc48dba80", false, async function() { return 'quux'; }); Object.defineProperty($$RSC_SERVER_CACHE_3, "name", { diff --git a/crates/next-custom-transforms/tests/fixture/server-actions/server/35/output.js b/crates/next-custom-transforms/tests/fixture/server-actions/server/35/output.js index 93a7191cab2e4..77ac341c71957 100644 --- a/crates/next-custom-transforms/tests/fixture/server-actions/server/35/output.js +++ b/crates/next-custom-transforms/tests/fixture/server-actions/server/35/output.js @@ -1,7 +1,7 @@ /* __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", async function() { +export var $$RSC_SERVER_CACHE_0 = $$cache__("default", "803128060c414d59f8552e4788b846c0d2b7f74743", false, async function() { return 'data'; }); Object.defineProperty($$RSC_SERVER_CACHE_0, "name", { diff --git a/crates/next-custom-transforms/tests/fixture/server-actions/server/36/output.js b/crates/next-custom-transforms/tests/fixture/server-actions/server/36/output.js index 1c60a0901a298..c495225c05237 100644 --- a/crates/next-custom-transforms/tests/fixture/server-actions/server/36/output.js +++ b/crates/next-custom-transforms/tests/fixture/server-actions/server/36/output.js @@ -1,7 +1,7 @@ /* __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", async function foo() { +export var $$RSC_SERVER_CACHE_0 = $$cache__("default", "803128060c414d59f8552e4788b846c0d2b7f74743", false, async function foo() { return 'data A'; }); Object.defineProperty($$RSC_SERVER_CACHE_0, "name", { @@ -9,7 +9,7 @@ Object.defineProperty($$RSC_SERVER_CACHE_0, "name", { "writable": false }); export var foo = registerServerReference($$RSC_SERVER_CACHE_0, "803128060c414d59f8552e4788b846c0d2b7f74743", null); -export var $$RSC_SERVER_CACHE_1 = $$cache__("default", "80951c375b4a6a6e89d67b743ec5808127cfde405d", async function bar() { +export var $$RSC_SERVER_CACHE_1 = $$cache__("default", "80951c375b4a6a6e89d67b743ec5808127cfde405d", false, async function bar() { return 'data B'; }); Object.defineProperty($$RSC_SERVER_CACHE_1, "name", { @@ -17,7 +17,7 @@ Object.defineProperty($$RSC_SERVER_CACHE_1, "name", { "writable": false }); export var bar = registerServerReference($$RSC_SERVER_CACHE_1, "80951c375b4a6a6e89d67b743ec5808127cfde405d", null); -export var $$RSC_SERVER_CACHE_2 = $$cache__("default", "c069348c79fce073bae2f70f139565a2fda1c74c74", async function Cached({ children }) { +export var $$RSC_SERVER_CACHE_2 = $$cache__("default", "c069348c79fce073bae2f70f139565a2fda1c74c74", false, async function Cached({ children }) { return children; }); Object.defineProperty($$RSC_SERVER_CACHE_2, "name", { @@ -25,7 +25,7 @@ Object.defineProperty($$RSC_SERVER_CACHE_2, "name", { "writable": false }); export default registerServerReference($$RSC_SERVER_CACHE_2, "c069348c79fce073bae2f70f139565a2fda1c74c74", null); -export var $$RSC_SERVER_CACHE_3 = $$cache__("default", "8012a8d21b6362b4cc8f5b15560525095bc48dba80", async function baz() { +export var $$RSC_SERVER_CACHE_3 = $$cache__("default", "8012a8d21b6362b4cc8f5b15560525095bc48dba80", false, async function baz() { return 'data C'; }); Object.defineProperty($$RSC_SERVER_CACHE_3, "name", { diff --git a/crates/next-custom-transforms/tests/fixture/server-actions/server/37/output.js b/crates/next-custom-transforms/tests/fixture/server-actions/server/37/output.js index 217f29d74b34d..806464e3b066e 100644 --- a/crates/next-custom-transforms/tests/fixture/server-actions/server/37/output.js +++ b/crates/next-custom-transforms/tests/fixture/server-actions/server/37/output.js @@ -1,7 +1,7 @@ /* __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", async function fn() { +export var $$RSC_SERVER_CACHE_0 = $$cache__("default", "803128060c414d59f8552e4788b846c0d2b7f74743", false, async function fn() { return 'foo'; }); Object.defineProperty($$RSC_SERVER_CACHE_0, "name", { diff --git a/crates/next-custom-transforms/tests/fixture/server-actions/server/38/output.js b/crates/next-custom-transforms/tests/fixture/server-actions/server/38/output.js index cac59ff51f644..f2e20aee3360d 100644 --- a/crates/next-custom-transforms/tests/fixture/server-actions/server/38/output.js +++ b/crates/next-custom-transforms/tests/fixture/server-actions/server/38/output.js @@ -1,7 +1,7 @@ /* __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", async function foo() { +export var $$RSC_SERVER_CACHE_0 = $$cache__("x", "803128060c414d59f8552e4788b846c0d2b7f74743", false, async function foo() { return 'data'; }); Object.defineProperty($$RSC_SERVER_CACHE_0, "name", { diff --git a/crates/next-custom-transforms/tests/fixture/server-actions/server/39/output.js b/crates/next-custom-transforms/tests/fixture/server-actions/server/39/output.js index e809fc3d8331d..aebb9079b4992 100644 --- a/crates/next-custom-transforms/tests/fixture/server-actions/server/39/output.js +++ b/crates/next-custom-transforms/tests/fixture/server-actions/server/39/output.js @@ -1,8 +1,8 @@ /* __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", async function fn($$ACTION_CLOSURE_BOUND) { - var [$$ACTION_ARG_0, $$ACTION_ARG_1] = await decryptActionBoundArgs("803128060c414d59f8552e4788b846c0d2b7f74743", $$ACTION_CLOSURE_BOUND); +export var $$RSC_SERVER_CACHE_0 = $$cache__("default", "803128060c414d59f8552e4788b846c0d2b7f74743", true, async function fn($$ACTION_CLOSURE_BOUND) { + var [$$ACTION_ARG_0, $$ACTION_ARG_1] = $$ACTION_CLOSURE_BOUND; console.log($$ACTION_ARG_0); return { foo: $$ACTION_ARG_1 diff --git a/crates/next-custom-transforms/tests/fixture/server-actions/server/40/output.js b/crates/next-custom-transforms/tests/fixture/server-actions/server/40/output.js index 2a1761af52fbc..15de953423993 100644 --- a/crates/next-custom-transforms/tests/fixture/server-actions/server/40/output.js +++ b/crates/next-custom-transforms/tests/fixture/server-actions/server/40/output.js @@ -1,8 +1,8 @@ /* __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"; 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", async function cache($$ACTION_CLOSURE_BOUND, e) { - var [$$ACTION_ARG_0, $$ACTION_ARG_1] = await decryptActionBoundArgs("c03128060c414d59f8552e4788b846c0d2b7f74743", $$ACTION_CLOSURE_BOUND); +export var $$RSC_SERVER_CACHE_0 = $$cache__("default", "c03128060c414d59f8552e4788b846c0d2b7f74743", true, async function cache($$ACTION_CLOSURE_BOUND, e) { + var [$$ACTION_ARG_0, $$ACTION_ARG_1] = $$ACTION_CLOSURE_BOUND; const f = $$ACTION_ARG_0 + e; return [ f, diff --git a/crates/next-custom-transforms/tests/fixture/server-actions/server/41/output.js b/crates/next-custom-transforms/tests/fixture/server-actions/server/41/output.js index 94bef357b693a..f5a07f3a446d0 100644 --- a/crates/next-custom-transforms/tests/fixture/server-actions/server/41/output.js +++ b/crates/next-custom-transforms/tests/fixture/server-actions/server/41/output.js @@ -8,7 +8,7 @@ export const $$RSC_SERVER_ACTION_0 = async function fn($$ACTION_CLOSURE_BOUND) { foo: $$ACTION_ARG_1 }; }; -export var $$RSC_SERVER_CACHE_1 = $$cache__("default", "c0951c375b4a6a6e89d67b743ec5808127cfde405d", async function Component({ foo }) { +export var $$RSC_SERVER_CACHE_1 = $$cache__("default", "c0951c375b4a6a6e89d67b743ec5808127cfde405d", false, async function Component({ foo }) { const a = 123; var fn = registerServerReference($$RSC_SERVER_ACTION_0, "006a88810ecce4a4e8b59d53b8327d7e98bbf251d7", null).bind(null, encryptActionBoundArgs("006a88810ecce4a4e8b59d53b8327d7e98bbf251d7", [ a, diff --git a/crates/next-custom-transforms/tests/fixture/server-actions/server/42/output.js b/crates/next-custom-transforms/tests/fixture/server-actions/server/42/output.js index 11ca54947cece..60ea035315d76 100644 --- a/crates/next-custom-transforms/tests/fixture/server-actions/server/42/output.js +++ b/crates/next-custom-transforms/tests/fixture/server-actions/server/42/output.js @@ -1,8 +1,8 @@ /* __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", async function($$ACTION_CLOSURE_BOUND) { - var [$$ACTION_ARG_0, $$ACTION_ARG_1] = await decryptActionBoundArgs("803128060c414d59f8552e4788b846c0d2b7f74743", $$ACTION_CLOSURE_BOUND); +export var $$RSC_SERVER_CACHE_0 = $$cache__("default", "803128060c414d59f8552e4788b846c0d2b7f74743", true, async function($$ACTION_CLOSURE_BOUND) { + var [$$ACTION_ARG_0, $$ACTION_ARG_1] = $$ACTION_CLOSURE_BOUND; console.log($$ACTION_ARG_0); return { foo: $$ACTION_ARG_1 diff --git a/crates/next-custom-transforms/tests/fixture/server-actions/server/43/output.js b/crates/next-custom-transforms/tests/fixture/server-actions/server/43/output.js index 2b8ed9d10e340..111f500613792 100644 --- a/crates/next-custom-transforms/tests/fixture/server-actions/server/43/output.js +++ b/crates/next-custom-transforms/tests/fixture/server-actions/server/43/output.js @@ -7,7 +7,7 @@ export const $$RSC_SERVER_ACTION_0 = async function action($$ACTION_CLOSURE_BOUN var [$$ACTION_ARG_0] = await decryptActionBoundArgs("006a88810ecce4a4e8b59d53b8327d7e98bbf251d7", $$ACTION_CLOSURE_BOUND); console.log(secret, $$ACTION_ARG_0); }; -export var $$RSC_SERVER_CACHE_1 = $$cache__("default", "e0951c375b4a6a6e89d67b743ec5808127cfde405d", async function getCachedRandom(x, children) { +export var $$RSC_SERVER_CACHE_1 = $$cache__("default", "e0951c375b4a6a6e89d67b743ec5808127cfde405d", false, async function getCachedRandom(x, children) { return { x, y: Math.random(), diff --git a/crates/next-custom-transforms/tests/fixture/server-actions/server/45/output.js b/crates/next-custom-transforms/tests/fixture/server-actions/server/45/output.js index 1c75a5c34554d..449f1d68c9f75 100644 --- a/crates/next-custom-transforms/tests/fixture/server-actions/server/45/output.js +++ b/crates/next-custom-transforms/tests/fixture/server-actions/server/45/output.js @@ -7,7 +7,7 @@ function Foo() { console.log(v); return v; } -export var $$RSC_SERVER_CACHE_0 = $$cache__("default", "803128060c414d59f8552e4788b846c0d2b7f74743", async function bar() { +export var $$RSC_SERVER_CACHE_0 = $$cache__("default", "803128060c414d59f8552e4788b846c0d2b7f74743", false, async function bar() { return ; }); Object.defineProperty($$RSC_SERVER_CACHE_0, "name", { diff --git a/crates/next-custom-transforms/tests/fixture/server-actions/server/46/output.js b/crates/next-custom-transforms/tests/fixture/server-actions/server/46/output.js index c2bde673e8829..0ff2eb717075d 100644 --- a/crates/next-custom-transforms/tests/fixture/server-actions/server/46/output.js +++ b/crates/next-custom-transforms/tests/fixture/server-actions/server/46/output.js @@ -3,7 +3,7 @@ /* __next_internal_action_entry_do_not_use__ {"6090b5db271335765a4b0eab01f044b381b5ebd5cd":"$$RSC_SERVER_ACTION_1","7c9ed0cc47abc4e1c64320cf42b74ae60b58c40f00":"$$RSC_SERVER_ACTION_3","7ea9b2939c1f39073a6bed227fd20233064c8b7869":"$$RSC_SERVER_ACTION_4","e03128060c414d59f8552e4788b846c0d2b7f74743":"$$RSC_SERVER_CACHE_0","ff471a5eb0be1c31686dd4ba938a80328b80b1615d":"$$RSC_SERVER_CACHE_5","ff69348c79fce073bae2f70f139565a2fda1c74c74":"$$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", "e03128060c414d59f8552e4788b846c0d2b7f74743", async function f1(a, b) { +export var $$RSC_SERVER_CACHE_0 = $$cache__("default", "e03128060c414d59f8552e4788b846c0d2b7f74743", false, async function f1(a, b) { return [ a, b @@ -22,7 +22,7 @@ $$RSC_SERVER_ACTION_1 = async function f2(a, b) { ]; }; var f2 = registerServerReference($$RSC_SERVER_ACTION_1, "6090b5db271335765a4b0eab01f044b381b5ebd5cd", null); -export var $$RSC_SERVER_CACHE_2 = $$cache__("default", "ff69348c79fce073bae2f70f139565a2fda1c74c74", // Should be 1 111111 1, which is "ff" in hex. +export var $$RSC_SERVER_CACHE_2 = $$cache__("default", "ff69348c79fce073bae2f70f139565a2fda1c74c74", false, // Should be 1 111111 1, which is "ff" in hex. async function f3(a, b, ...rest) { return [ a, @@ -58,7 +58,7 @@ $$RSC_SERVER_ACTION_4 = async function f4(a, b, c, d, e, f) { ]; }; var f4 = registerServerReference($$RSC_SERVER_ACTION_4, "7ea9b2939c1f39073a6bed227fd20233064c8b7869", null); -export var $$RSC_SERVER_CACHE_5 = $$cache__("default", "ff471a5eb0be1c31686dd4ba938a80328b80b1615d", // Should be 1 111111 1, which is "ff" in hex. +export var $$RSC_SERVER_CACHE_5 = $$cache__("default", "ff471a5eb0be1c31686dd4ba938a80328b80b1615d", false, // Should be 1 111111 1, which is "ff" in hex. async function f5(a, b, c, d, e, f, g) { return [ a, diff --git a/crates/next-custom-transforms/tests/fixture/server-actions/server/48/output.js b/crates/next-custom-transforms/tests/fixture/server-actions/server/48/output.js index fbb5634dfae0a..03e7baef7e5bf 100644 --- a/crates/next-custom-transforms/tests/fixture/server-actions/server/48/output.js +++ b/crates/next-custom-transforms/tests/fixture/server-actions/server/48/output.js @@ -24,7 +24,7 @@ export async function action3(a, b) { {b} ; } -export var $$RSC_SERVER_CACHE_0 = $$cache__("default", "e03128060c414d59f8552e4788b846c0d2b7f74743", async function cache(a, b) { +export var $$RSC_SERVER_CACHE_0 = $$cache__("default", "e03128060c414d59f8552e4788b846c0d2b7f74743", false, async function cache(a, b) { return
{a} {b} diff --git a/crates/next-custom-transforms/tests/fixture/server-actions/server/49/output.js b/crates/next-custom-transforms/tests/fixture/server-actions/server/49/output.js index 241d76da05d22..8182a0563e01f 100644 --- a/crates/next-custom-transforms/tests/fixture/server-actions/server/49/output.js +++ b/crates/next-custom-transforms/tests/fixture/server-actions/server/49/output.js @@ -1,7 +1,7 @@ /* __next_internal_action_entry_do_not_use__ {"f03128060c414d59f8552e4788b846c0d2b7f74743":"$$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", "f03128060c414d59f8552e4788b846c0d2b7f74743", async function(a, b, c) { +export var $$RSC_SERVER_CACHE_0 = $$cache__("default", "f03128060c414d59f8552e4788b846c0d2b7f74743", false, async function(a, b, c) { return
{a} {b} diff --git a/crates/next-custom-transforms/tests/fixture/server-actions/server/50/output.js b/crates/next-custom-transforms/tests/fixture/server-actions/server/50/output.js index 2f8a608608490..e1f71054ca1f4 100644 --- a/crates/next-custom-transforms/tests/fixture/server-actions/server/50/output.js +++ b/crates/next-custom-transforms/tests/fixture/server-actions/server/50/output.js @@ -1,7 +1,7 @@ /* __next_internal_action_entry_do_not_use__ {"f03128060c414d59f8552e4788b846c0d2b7f74743":"$$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", "f03128060c414d59f8552e4788b846c0d2b7f74743", async function(a, b, c) { +export var $$RSC_SERVER_CACHE_0 = $$cache__("default", "f03128060c414d59f8552e4788b846c0d2b7f74743", false, async function(a, b, c) { return
{a} {b} diff --git a/packages/next/src/server/use-cache/use-cache-wrapper.ts b/packages/next/src/server/use-cache/use-cache-wrapper.ts index ffd0c0c93d0c3..4235945df5717 100644 --- a/packages/next/src/server/use-cache/use-cache-wrapper.ts +++ b/packages/next/src/server/use-cache/use-cache-wrapper.ts @@ -36,6 +36,8 @@ import { import DefaultCacheHandler from '../lib/cache-handlers/default' import type { CacheHandler, CacheEntry } from '../lib/cache-handlers/types' import type { CacheSignal } from '../app-render/cache-signal' +import { decryptActionBoundArgs } from '../app-render/encryption' +import { InvariantError } from '../../shared/lib/invariant-error' const isEdgeRuntime = process.env.NEXT_RUNTIME === 'edge' @@ -433,7 +435,12 @@ function createTrackedReadableStream( }) } -export function cache(kind: string, id: string, fn: any) { +export function cache( + kind: string, + id: string, + hasBoundArgs: boolean, + fn: any +) { if (!process.env.__NEXT_DYNAMIC_IO) { throw new Error( '"use cache" is only available with the experimental.dynamicIO config.' @@ -495,6 +502,24 @@ export function cache(kind: string, id: string, fn: any) { } } + if (hasBoundArgs) { + if (args.length < 1) { + throw new InvariantError( + 'Expected server closure to receive at least one argument, got: ' + + args.length + ) + } + const [encryptedBound, ...rest] = args + const decryptedBound = await decryptActionBoundArgs(id, encryptedBound) + if (!Array.isArray(decryptedBound)) { + throw new InvariantError( + 'Expected bound closure args to deserialize into an array, got: ' + + typeof decryptedBound + ) + } + args = [decryptedBound, ...rest] + } + const temporaryReferences = createClientTemporaryReferenceSet() const encodedArguments: FormData | string = await encodeReply( [buildId, id, args], From 29ee695d99ab91d4e1bdb0b7b18e685126d31d77 Mon Sep 17 00:00:00 2001 From: Janka Uryga Date: Thu, 7 Nov 2024 16:02:31 +0100 Subject: [PATCH 2/7] test: passing cache closure to client --- .../app/passed-to-client-closure/page.tsx | 27 +++++++++++++++++++ test/e2e/app-dir/use-cache/use-cache.test.ts | 24 ++++++++++++++++- 2 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 test/e2e/app-dir/use-cache/app/passed-to-client-closure/page.tsx diff --git a/test/e2e/app-dir/use-cache/app/passed-to-client-closure/page.tsx b/test/e2e/app-dir/use-cache/app/passed-to-client-closure/page.tsx new file mode 100644 index 0000000000000..529547e8f8d01 --- /dev/null +++ b/test/e2e/app-dir/use-cache/app/passed-to-client-closure/page.tsx @@ -0,0 +1,27 @@ +import { Form } from '../form' + +function getRandomValue() { + const v = Math.random() + console.log(v) + return v +} + +export default function Page() { + const offset = 100 + return ( +
{ + 'use cache' + return offset + getRandomValue() + }} + /> + ) +} diff --git a/test/e2e/app-dir/use-cache/use-cache.test.ts b/test/e2e/app-dir/use-cache/use-cache.test.ts index 35e001ea895f5..d4360fc8817f6 100644 --- a/test/e2e/app-dir/use-cache/use-cache.test.ts +++ b/test/e2e/app-dir/use-cache/use-cache.test.ts @@ -162,7 +162,29 @@ describe('use-cache', () => { await retry(async () => { threeRandomValues = await browser.elementByCss('p').text() - expect(threeRandomValues).toMatch(/\d\.\d+ \d\.\d+/) + expect(threeRandomValues).toMatch(/\d\.\d+ \d\.\d+ \d\.\d+/) + }) + + await browser.elementById('reset-button').click() + expect(await browser.elementByCss('p').text()).toBe('0 0 0') + + await browser.elementById('submit-button').click() + + await retry(async () => { + expect(await browser.elementByCss('p').text()).toBe(threeRandomValues) + }) + }) + + it('should cache results for cached closures passed to client components', async () => { + const browser = await next.browser('/passed-to-client-closure') + expect(await browser.elementByCss('p').text()).toBe('0 0 0') + await browser.elementById('submit-button').click() + + let threeRandomValues: string + + await retry(async () => { + threeRandomValues = await browser.elementByCss('p').text() + expect(threeRandomValues).toMatch(/100\.\d+ 100\.\d+ 100\.\d+/) }) await browser.elementById('reset-button').click() From a6e2f67c40b9107ea1e8ce48babe5266cb41c60a Mon Sep 17 00:00:00 2001 From: Hendrik Liebau Date: Thu, 7 Nov 2024 16:58:03 +0100 Subject: [PATCH 3/7] Exclude crypto usage in `encodeActionBoundArg` from dynamicIO checks --- packages/next/src/server/app-render/encryption.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/next/src/server/app-render/encryption.ts b/packages/next/src/server/app-render/encryption.ts index 7649ef2dfe206..32b9259dbe850 100644 --- a/packages/next/src/server/app-render/encryption.ts +++ b/packages/next/src/server/app-render/encryption.ts @@ -16,6 +16,7 @@ import { getServerModuleMap, stringToUint8Array, } from './encryption-utils' +import { workUnitAsyncStorage } from './work-unit-async-storage.external' const isEdgeRuntime = process.env.NEXT_RUNTIME === 'edge' @@ -56,7 +57,7 @@ async function encodeActionBoundArg(actionId: string, arg: string) { // Get 16 random bytes as iv. const randomBytes = new Uint8Array(16) - crypto.getRandomValues(randomBytes) + workUnitAsyncStorage.exit(() => crypto.getRandomValues(randomBytes)) const ivValue = arrayBufferToString(randomBytes.buffer) const encrypted = await encrypt( From 08911064424ca5fc4e16f659692db2f0f9233d1f Mon Sep 17 00:00:00 2001 From: Hendrik Liebau Date: Thu, 7 Nov 2024 16:58:59 +0100 Subject: [PATCH 4/7] Unify `"use cache"` closure client component tests --- .../app/passed-to-client-closure/page.tsx | 27 ------------------- .../use-cache/app/passed-to-client/page.tsx | 7 ++--- test/e2e/app-dir/use-cache/use-cache.test.ts | 22 --------------- 3 files changed, 4 insertions(+), 52 deletions(-) delete mode 100644 test/e2e/app-dir/use-cache/app/passed-to-client-closure/page.tsx diff --git a/test/e2e/app-dir/use-cache/app/passed-to-client-closure/page.tsx b/test/e2e/app-dir/use-cache/app/passed-to-client-closure/page.tsx deleted file mode 100644 index 529547e8f8d01..0000000000000 --- a/test/e2e/app-dir/use-cache/app/passed-to-client-closure/page.tsx +++ /dev/null @@ -1,27 +0,0 @@ -import { Form } from '../form' - -function getRandomValue() { - const v = Math.random() - console.log(v) - return v -} - -export default function Page() { - const offset = 100 - return ( - { - 'use cache' - return offset + getRandomValue() - }} - /> - ) -} diff --git a/test/e2e/app-dir/use-cache/app/passed-to-client/page.tsx b/test/e2e/app-dir/use-cache/app/passed-to-client/page.tsx index 1c4bfe9b97cbc..529547e8f8d01 100644 --- a/test/e2e/app-dir/use-cache/app/passed-to-client/page.tsx +++ b/test/e2e/app-dir/use-cache/app/passed-to-client/page.tsx @@ -7,19 +7,20 @@ function getRandomValue() { } export default function Page() { + const offset = 100 return ( { 'use cache' - return getRandomValue() + return offset + getRandomValue() }} /> ) diff --git a/test/e2e/app-dir/use-cache/use-cache.test.ts b/test/e2e/app-dir/use-cache/use-cache.test.ts index d4360fc8817f6..bfada710f8187 100644 --- a/test/e2e/app-dir/use-cache/use-cache.test.ts +++ b/test/e2e/app-dir/use-cache/use-cache.test.ts @@ -160,28 +160,6 @@ describe('use-cache', () => { let threeRandomValues: string - await retry(async () => { - threeRandomValues = await browser.elementByCss('p').text() - expect(threeRandomValues).toMatch(/\d\.\d+ \d\.\d+ \d\.\d+/) - }) - - await browser.elementById('reset-button').click() - expect(await browser.elementByCss('p').text()).toBe('0 0 0') - - await browser.elementById('submit-button').click() - - await retry(async () => { - expect(await browser.elementByCss('p').text()).toBe(threeRandomValues) - }) - }) - - it('should cache results for cached closures passed to client components', async () => { - const browser = await next.browser('/passed-to-client-closure') - expect(await browser.elementByCss('p').text()).toBe('0 0 0') - await browser.elementById('submit-button').click() - - let threeRandomValues: string - await retry(async () => { threeRandomValues = await browser.elementByCss('p').text() expect(threeRandomValues).toMatch(/100\.\d+ 100\.\d+ 100\.\d+/) From f0af26d7259d7c0d832896e13593f19758cb230c Mon Sep 17 00:00:00 2001 From: Hendrik Liebau Date: Thu, 7 Nov 2024 19:32:45 +0100 Subject: [PATCH 5/7] Pass bound args already destructured into cache function --- .../src/transforms/server_actions.rs | 137 ++++-------------- .../server-actions/server/33/output.js | 2 +- .../server-actions/server/34/output.js | 8 +- .../server-actions/server/35/output.js | 2 +- .../server-actions/server/36/output.js | 8 +- .../server-actions/server/37/output.js | 2 +- .../server-actions/server/38/output.js | 2 +- .../server-actions/server/39/output.js | 3 +- .../server-actions/server/40/output.js | 3 +- .../server-actions/server/41/output.js | 2 +- .../server-actions/server/42/output.js | 3 +- .../server-actions/server/43/output.js | 2 +- .../server-actions/server/45/output.js | 2 +- .../server-actions/server/46/output.js | 6 +- .../server-actions/server/48/output.js | 2 +- .../server-actions/server/49/output.js | 2 +- .../server-actions/server/50/output.js | 2 +- .../src/server/use-cache/use-cache-wrapper.ts | 29 ++-- 18 files changed, 69 insertions(+), 148 deletions(-) diff --git a/crates/next-custom-transforms/src/transforms/server_actions.rs b/crates/next-custom-transforms/src/transforms/server_actions.rs index b938931a004cf..f2c274eb47770 100644 --- a/crates/next-custom-transforms/src/transforms/server_actions.rs +++ b/crates/next-custom-transforms/src/transforms/server_actions.rs @@ -618,69 +618,23 @@ impl ServerActions { }); } - // export const $ACTION_myAction = async () => {} let mut new_params: Vec = vec![]; - let mut new_body: BlockStmtOrExpr = *arrow.body.take(); + // Add the collected closure variables as the first parameters to the + // function. They are unencrypted and passed into this function by the + // cache wrapper. if !ids_from_closure.is_empty() { - // First argument is the encrypted closure variables - new_params.push(Param { - span: DUMMY_SP, - decorators: vec![], - pat: Pat::Ident(IdentName::new("$$ACTION_CLOSURE_BOUND".into(), DUMMY_SP).into()), - }); - - // Also prepend the decryption decl into the body. - // var [arg1, arg2, arg3] = await decryptActionBoundArgs(actionId, - // $$ACTION_CLOSURE_BOUND) - let mut pats = vec![]; for i in 0..ids_from_closure.len() { - pats.push(Some(Pat::Ident( - Ident::new( + new_params.push(Param { + span: DUMMY_SP, + decorators: vec![], + pat: Ident::new( format!("$$ACTION_ARG_{i}").into(), DUMMY_SP, self.private_ctxt, ) .into(), - ))); - } - let args_decl = VarDecl { - span: DUMMY_SP, - kind: VarDeclKind::Var, - declare: false, - decls: vec![VarDeclarator { - span: DUMMY_SP, - name: Pat::Array(ArrayPat { - span: DUMMY_SP, - elems: pats, - optional: false, - type_ann: None, - }), - init: Some(Box::new(Expr::Ident( - quote_ident!("$$ACTION_CLOSURE_BOUND").into(), - ))), - definite: Default::default(), - }], - ..Default::default() - }; - - match &mut new_body { - BlockStmtOrExpr::BlockStmt(body) => { - body.stmts.insert(0, args_decl.into()); - } - BlockStmtOrExpr::Expr(body_expr) => { - new_body = BlockStmtOrExpr::BlockStmt(BlockStmt { - span: DUMMY_SP, - stmts: vec![ - args_decl.into(), - Stmt::Return(ReturnStmt { - span: DUMMY_SP, - arg: Some(body_expr.take()), - }), - ], - ..Default::default() - }); - } + }); } } @@ -708,7 +662,7 @@ impl ServerActions { ident: None, function: Box::new(Function { params: new_params, - body: match new_body { + body: match *arrow.body.take() { BlockStmtOrExpr::BlockStmt(body) => Some(body), BlockStmtOrExpr::Expr(expr) => Some(BlockStmt { span: DUMMY_SP, @@ -728,7 +682,7 @@ impl ServerActions { })), cache_type, &reference_id, - !ids_from_closure.is_empty(), + ids_from_closure.len(), )), definite: false, }], @@ -817,60 +771,24 @@ impl ServerActions { private_ctxt: self.private_ctxt, }); - // export async function $ACTION_myAction () {} let mut new_params: Vec = vec![]; - let mut new_body: Option = function.body.clone(); - // add params from closure collected ids + // Add the collected closure variables as the first parameters to the + // function. They are unencrypted and passed into this function by the + // cache wrapper. if !ids_from_closure.is_empty() { - // First argument is the encrypted closure variables - new_params.push(Param { - span: DUMMY_SP, - decorators: vec![], - pat: Pat::Ident(IdentName::new("$$ACTION_CLOSURE_BOUND".into(), DUMMY_SP).into()), - }); - - // Also prepend the decryption decl into the body. - // var [arg1, arg2, arg3] = await decryptActionBoundArgs(actionId, - // $$ACTION_CLOSURE_BOUND) - let mut pats = vec![]; for i in 0..ids_from_closure.len() { - pats.push(Some(Pat::Ident( - Ident::new( - // $$ACTION_ARG_0 - format!("$$ACTION_ARG_{i}").into(), - DUMMY_SP, - self.private_ctxt, - ) - .into(), - ))); - } - let args_decl = VarDecl { - span: DUMMY_SP, - kind: VarDeclKind::Var, - decls: vec![VarDeclarator { + new_params.push(Param { span: DUMMY_SP, - name: Pat::Array(ArrayPat { - span: DUMMY_SP, - elems: pats, - optional: false, - type_ann: None, - }), - init: Some(Box::new(Expr::Ident( - quote_ident!("$$ACTION_CLOSURE_BOUND").into(), - ))), - definite: Default::default(), - }], - ..Default::default() - }; - - if let Some(body) = &mut new_body { - body.stmts.insert(0, args_decl.into()); - } else { - new_body = Some(BlockStmt { - span: DUMMY_SP, - stmts: vec![args_decl.into()], - ..Default::default() + decorators: vec![], + pat: Pat::Ident( + Ident::new( + format!("$$ACTION_ARG_{i}").into(), + DUMMY_SP, + self.private_ctxt, + ) + .into(), + ), }); } } @@ -894,13 +812,12 @@ impl ServerActions { ident: fn_name.clone(), function: Box::new(Function { params: new_params, - body: new_body, ..*function.take() }), })), cache_type, &reference_id, - !ids_from_closure.is_empty(), + ids_from_closure.len(), )), definite: false, }], @@ -2254,8 +2171,8 @@ fn retain_names_from_declared_idents( *child_names = retained_names; } -fn wrap_cache_expr(expr: Box, name: &str, id: &str, has_bound_args: bool) -> Box { - // expr -> $$cache__("name", "id", expr) +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, callee: quote_ident!("$$cache__").as_callee(), @@ -2268,7 +2185,7 @@ fn wrap_cache_expr(expr: Box, name: &str, id: &str, has_bound_args: bool) spread: None, expr: Box::new(id.into()), }, - Bool::from(has_bound_args).as_arg(), + Number::from(bound_args_len).as_arg(), expr.as_arg(), ], ..Default::default() diff --git a/crates/next-custom-transforms/tests/fixture/server-actions/server/33/output.js b/crates/next-custom-transforms/tests/fixture/server-actions/server/33/output.js index 93f0dbba0b695..f97b915e454ca 100644 --- a/crates/next-custom-transforms/tests/fixture/server-actions/server/33/output.js +++ b/crates/next-custom-transforms/tests/fixture/server-actions/server/33/output.js @@ -2,7 +2,7 @@ import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption"; import { cache as $$cache__ } from "private-next-rsc-cache-wrapper"; const v = 'world'; -export var $$RSC_SERVER_CACHE_0 = $$cache__("default", "803128060c414d59f8552e4788b846c0d2b7f74743", false, async function fn() { +export var $$RSC_SERVER_CACHE_0 = $$cache__("default", "803128060c414d59f8552e4788b846c0d2b7f74743", 0, async function fn() { return 'hello, ' + v; }); Object.defineProperty($$RSC_SERVER_CACHE_0, "name", { diff --git a/crates/next-custom-transforms/tests/fixture/server-actions/server/34/output.js b/crates/next-custom-transforms/tests/fixture/server-actions/server/34/output.js index c7d502c1f0436..a869a0a6ede46 100644 --- a/crates/next-custom-transforms/tests/fixture/server-actions/server/34/output.js +++ b/crates/next-custom-transforms/tests/fixture/server-actions/server/34/output.js @@ -1,7 +1,7 @@ /* __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", false, async function() { +export var $$RSC_SERVER_CACHE_0 = $$cache__("default", "803128060c414d59f8552e4788b846c0d2b7f74743", 0, async function() { return 'foo'; }); Object.defineProperty($$RSC_SERVER_CACHE_0, "name", { @@ -10,7 +10,7 @@ Object.defineProperty($$RSC_SERVER_CACHE_0, "name", { }); const foo = registerServerReference($$RSC_SERVER_CACHE_0, "803128060c414d59f8552e4788b846c0d2b7f74743", null); export { bar }; -export var $$RSC_SERVER_CACHE_1 = $$cache__("default", "80951c375b4a6a6e89d67b743ec5808127cfde405d", false, async function bar() { +export var $$RSC_SERVER_CACHE_1 = $$cache__("default", "80951c375b4a6a6e89d67b743ec5808127cfde405d", 0, async function bar() { return 'bar'; }); Object.defineProperty($$RSC_SERVER_CACHE_1, "name", { @@ -22,7 +22,7 @@ var bar = registerServerReference($$RSC_SERVER_CACHE_1, "80951c375b4a6a6e89d67b7 const qux = async function qux() { return 'qux'; }; -export var $$RSC_SERVER_CACHE_2 = $$cache__("default", "8069348c79fce073bae2f70f139565a2fda1c74c74", false, async function baz() { +export var $$RSC_SERVER_CACHE_2 = $$cache__("default", "8069348c79fce073bae2f70f139565a2fda1c74c74", 0, async function baz() { return qux() + 'baz'; }); Object.defineProperty($$RSC_SERVER_CACHE_2, "name", { @@ -30,7 +30,7 @@ Object.defineProperty($$RSC_SERVER_CACHE_2, "name", { "writable": false }); const baz = registerServerReference($$RSC_SERVER_CACHE_2, "8069348c79fce073bae2f70f139565a2fda1c74c74", null); -export var $$RSC_SERVER_CACHE_3 = $$cache__("default", "8012a8d21b6362b4cc8f5b15560525095bc48dba80", false, async function() { +export var $$RSC_SERVER_CACHE_3 = $$cache__("default", "8012a8d21b6362b4cc8f5b15560525095bc48dba80", 0, async function() { return 'quux'; }); Object.defineProperty($$RSC_SERVER_CACHE_3, "name", { diff --git a/crates/next-custom-transforms/tests/fixture/server-actions/server/35/output.js b/crates/next-custom-transforms/tests/fixture/server-actions/server/35/output.js index 77ac341c71957..41d10d499f974 100644 --- a/crates/next-custom-transforms/tests/fixture/server-actions/server/35/output.js +++ b/crates/next-custom-transforms/tests/fixture/server-actions/server/35/output.js @@ -1,7 +1,7 @@ /* __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", false, async function() { +export var $$RSC_SERVER_CACHE_0 = $$cache__("default", "803128060c414d59f8552e4788b846c0d2b7f74743", 0, async function() { return 'data'; }); Object.defineProperty($$RSC_SERVER_CACHE_0, "name", { diff --git a/crates/next-custom-transforms/tests/fixture/server-actions/server/36/output.js b/crates/next-custom-transforms/tests/fixture/server-actions/server/36/output.js index c495225c05237..3c03750190a0d 100644 --- a/crates/next-custom-transforms/tests/fixture/server-actions/server/36/output.js +++ b/crates/next-custom-transforms/tests/fixture/server-actions/server/36/output.js @@ -1,7 +1,7 @@ /* __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", false, async function foo() { +export var $$RSC_SERVER_CACHE_0 = $$cache__("default", "803128060c414d59f8552e4788b846c0d2b7f74743", 0, async function foo() { return 'data A'; }); Object.defineProperty($$RSC_SERVER_CACHE_0, "name", { @@ -9,7 +9,7 @@ Object.defineProperty($$RSC_SERVER_CACHE_0, "name", { "writable": false }); export var foo = registerServerReference($$RSC_SERVER_CACHE_0, "803128060c414d59f8552e4788b846c0d2b7f74743", null); -export var $$RSC_SERVER_CACHE_1 = $$cache__("default", "80951c375b4a6a6e89d67b743ec5808127cfde405d", false, async function bar() { +export var $$RSC_SERVER_CACHE_1 = $$cache__("default", "80951c375b4a6a6e89d67b743ec5808127cfde405d", 0, async function bar() { return 'data B'; }); Object.defineProperty($$RSC_SERVER_CACHE_1, "name", { @@ -17,7 +17,7 @@ Object.defineProperty($$RSC_SERVER_CACHE_1, "name", { "writable": false }); export var bar = registerServerReference($$RSC_SERVER_CACHE_1, "80951c375b4a6a6e89d67b743ec5808127cfde405d", null); -export var $$RSC_SERVER_CACHE_2 = $$cache__("default", "c069348c79fce073bae2f70f139565a2fda1c74c74", false, async function Cached({ children }) { +export var $$RSC_SERVER_CACHE_2 = $$cache__("default", "c069348c79fce073bae2f70f139565a2fda1c74c74", 0, async function Cached({ children }) { return children; }); Object.defineProperty($$RSC_SERVER_CACHE_2, "name", { @@ -25,7 +25,7 @@ Object.defineProperty($$RSC_SERVER_CACHE_2, "name", { "writable": false }); export default registerServerReference($$RSC_SERVER_CACHE_2, "c069348c79fce073bae2f70f139565a2fda1c74c74", null); -export var $$RSC_SERVER_CACHE_3 = $$cache__("default", "8012a8d21b6362b4cc8f5b15560525095bc48dba80", false, async function baz() { +export var $$RSC_SERVER_CACHE_3 = $$cache__("default", "8012a8d21b6362b4cc8f5b15560525095bc48dba80", 0, async function baz() { return 'data C'; }); Object.defineProperty($$RSC_SERVER_CACHE_3, "name", { diff --git a/crates/next-custom-transforms/tests/fixture/server-actions/server/37/output.js b/crates/next-custom-transforms/tests/fixture/server-actions/server/37/output.js index 806464e3b066e..0ba849ea94204 100644 --- a/crates/next-custom-transforms/tests/fixture/server-actions/server/37/output.js +++ b/crates/next-custom-transforms/tests/fixture/server-actions/server/37/output.js @@ -1,7 +1,7 @@ /* __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", false, async function fn() { +export var $$RSC_SERVER_CACHE_0 = $$cache__("default", "803128060c414d59f8552e4788b846c0d2b7f74743", 0, async function fn() { return 'foo'; }); Object.defineProperty($$RSC_SERVER_CACHE_0, "name", { diff --git a/crates/next-custom-transforms/tests/fixture/server-actions/server/38/output.js b/crates/next-custom-transforms/tests/fixture/server-actions/server/38/output.js index f2e20aee3360d..fd8981f7b00a2 100644 --- a/crates/next-custom-transforms/tests/fixture/server-actions/server/38/output.js +++ b/crates/next-custom-transforms/tests/fixture/server-actions/server/38/output.js @@ -1,7 +1,7 @@ /* __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", false, async function foo() { +export var $$RSC_SERVER_CACHE_0 = $$cache__("x", "803128060c414d59f8552e4788b846c0d2b7f74743", 0, async function foo() { return 'data'; }); Object.defineProperty($$RSC_SERVER_CACHE_0, "name", { diff --git a/crates/next-custom-transforms/tests/fixture/server-actions/server/39/output.js b/crates/next-custom-transforms/tests/fixture/server-actions/server/39/output.js index aebb9079b4992..9bef24e1b7110 100644 --- a/crates/next-custom-transforms/tests/fixture/server-actions/server/39/output.js +++ b/crates/next-custom-transforms/tests/fixture/server-actions/server/39/output.js @@ -1,8 +1,7 @@ /* __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", true, async function fn($$ACTION_CLOSURE_BOUND) { - var [$$ACTION_ARG_0, $$ACTION_ARG_1] = $$ACTION_CLOSURE_BOUND; +export var $$RSC_SERVER_CACHE_0 = $$cache__("default", "803128060c414d59f8552e4788b846c0d2b7f74743", 2, async function fn($$ACTION_ARG_0, $$ACTION_ARG_1) { console.log($$ACTION_ARG_0); return { foo: $$ACTION_ARG_1 diff --git a/crates/next-custom-transforms/tests/fixture/server-actions/server/40/output.js b/crates/next-custom-transforms/tests/fixture/server-actions/server/40/output.js index 15de953423993..ce12109d337b3 100644 --- a/crates/next-custom-transforms/tests/fixture/server-actions/server/40/output.js +++ b/crates/next-custom-transforms/tests/fixture/server-actions/server/40/output.js @@ -1,8 +1,7 @@ /* __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"; 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", true, async function cache($$ACTION_CLOSURE_BOUND, e) { - var [$$ACTION_ARG_0, $$ACTION_ARG_1] = $$ACTION_CLOSURE_BOUND; +export var $$RSC_SERVER_CACHE_0 = $$cache__("default", "c03128060c414d59f8552e4788b846c0d2b7f74743", 2, async function cache($$ACTION_ARG_0, $$ACTION_ARG_1, e) { const f = $$ACTION_ARG_0 + e; return [ f, diff --git a/crates/next-custom-transforms/tests/fixture/server-actions/server/41/output.js b/crates/next-custom-transforms/tests/fixture/server-actions/server/41/output.js index f5a07f3a446d0..5f35cab368675 100644 --- a/crates/next-custom-transforms/tests/fixture/server-actions/server/41/output.js +++ b/crates/next-custom-transforms/tests/fixture/server-actions/server/41/output.js @@ -8,7 +8,7 @@ export const $$RSC_SERVER_ACTION_0 = async function fn($$ACTION_CLOSURE_BOUND) { foo: $$ACTION_ARG_1 }; }; -export var $$RSC_SERVER_CACHE_1 = $$cache__("default", "c0951c375b4a6a6e89d67b743ec5808127cfde405d", false, async function Component({ foo }) { +export var $$RSC_SERVER_CACHE_1 = $$cache__("default", "c0951c375b4a6a6e89d67b743ec5808127cfde405d", 0, async function Component({ foo }) { const a = 123; var fn = registerServerReference($$RSC_SERVER_ACTION_0, "006a88810ecce4a4e8b59d53b8327d7e98bbf251d7", null).bind(null, encryptActionBoundArgs("006a88810ecce4a4e8b59d53b8327d7e98bbf251d7", [ a, diff --git a/crates/next-custom-transforms/tests/fixture/server-actions/server/42/output.js b/crates/next-custom-transforms/tests/fixture/server-actions/server/42/output.js index 60ea035315d76..4a0ce92a234f0 100644 --- a/crates/next-custom-transforms/tests/fixture/server-actions/server/42/output.js +++ b/crates/next-custom-transforms/tests/fixture/server-actions/server/42/output.js @@ -1,8 +1,7 @@ /* __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", true, async function($$ACTION_CLOSURE_BOUND) { - var [$$ACTION_ARG_0, $$ACTION_ARG_1] = $$ACTION_CLOSURE_BOUND; +export var $$RSC_SERVER_CACHE_0 = $$cache__("default", "803128060c414d59f8552e4788b846c0d2b7f74743", 2, async function($$ACTION_ARG_0, $$ACTION_ARG_1) { console.log($$ACTION_ARG_0); return { foo: $$ACTION_ARG_1 diff --git a/crates/next-custom-transforms/tests/fixture/server-actions/server/43/output.js b/crates/next-custom-transforms/tests/fixture/server-actions/server/43/output.js index 111f500613792..b795fdaedb51f 100644 --- a/crates/next-custom-transforms/tests/fixture/server-actions/server/43/output.js +++ b/crates/next-custom-transforms/tests/fixture/server-actions/server/43/output.js @@ -7,7 +7,7 @@ export const $$RSC_SERVER_ACTION_0 = async function action($$ACTION_CLOSURE_BOUN var [$$ACTION_ARG_0] = await decryptActionBoundArgs("006a88810ecce4a4e8b59d53b8327d7e98bbf251d7", $$ACTION_CLOSURE_BOUND); console.log(secret, $$ACTION_ARG_0); }; -export var $$RSC_SERVER_CACHE_1 = $$cache__("default", "e0951c375b4a6a6e89d67b743ec5808127cfde405d", false, async function getCachedRandom(x, children) { +export var $$RSC_SERVER_CACHE_1 = $$cache__("default", "e0951c375b4a6a6e89d67b743ec5808127cfde405d", 0, async function getCachedRandom(x, children) { return { x, y: Math.random(), diff --git a/crates/next-custom-transforms/tests/fixture/server-actions/server/45/output.js b/crates/next-custom-transforms/tests/fixture/server-actions/server/45/output.js index 449f1d68c9f75..2d81d32f8192c 100644 --- a/crates/next-custom-transforms/tests/fixture/server-actions/server/45/output.js +++ b/crates/next-custom-transforms/tests/fixture/server-actions/server/45/output.js @@ -7,7 +7,7 @@ function Foo() { console.log(v); return v; } -export var $$RSC_SERVER_CACHE_0 = $$cache__("default", "803128060c414d59f8552e4788b846c0d2b7f74743", false, async function bar() { +export var $$RSC_SERVER_CACHE_0 = $$cache__("default", "803128060c414d59f8552e4788b846c0d2b7f74743", 0, async function bar() { return ; }); Object.defineProperty($$RSC_SERVER_CACHE_0, "name", { diff --git a/crates/next-custom-transforms/tests/fixture/server-actions/server/46/output.js b/crates/next-custom-transforms/tests/fixture/server-actions/server/46/output.js index 0ff2eb717075d..785d6b735b670 100644 --- a/crates/next-custom-transforms/tests/fixture/server-actions/server/46/output.js +++ b/crates/next-custom-transforms/tests/fixture/server-actions/server/46/output.js @@ -3,7 +3,7 @@ /* __next_internal_action_entry_do_not_use__ {"6090b5db271335765a4b0eab01f044b381b5ebd5cd":"$$RSC_SERVER_ACTION_1","7c9ed0cc47abc4e1c64320cf42b74ae60b58c40f00":"$$RSC_SERVER_ACTION_3","7ea9b2939c1f39073a6bed227fd20233064c8b7869":"$$RSC_SERVER_ACTION_4","e03128060c414d59f8552e4788b846c0d2b7f74743":"$$RSC_SERVER_CACHE_0","ff471a5eb0be1c31686dd4ba938a80328b80b1615d":"$$RSC_SERVER_CACHE_5","ff69348c79fce073bae2f70f139565a2fda1c74c74":"$$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", "e03128060c414d59f8552e4788b846c0d2b7f74743", false, async function f1(a, b) { +export var $$RSC_SERVER_CACHE_0 = $$cache__("default", "e03128060c414d59f8552e4788b846c0d2b7f74743", 0, async function f1(a, b) { return [ a, b @@ -22,7 +22,7 @@ $$RSC_SERVER_ACTION_1 = async function f2(a, b) { ]; }; var f2 = registerServerReference($$RSC_SERVER_ACTION_1, "6090b5db271335765a4b0eab01f044b381b5ebd5cd", null); -export var $$RSC_SERVER_CACHE_2 = $$cache__("default", "ff69348c79fce073bae2f70f139565a2fda1c74c74", false, // Should be 1 111111 1, which is "ff" in hex. +export var $$RSC_SERVER_CACHE_2 = $$cache__("default", "ff69348c79fce073bae2f70f139565a2fda1c74c74", 0, // Should be 1 111111 1, which is "ff" in hex. async function f3(a, b, ...rest) { return [ a, @@ -58,7 +58,7 @@ $$RSC_SERVER_ACTION_4 = async function f4(a, b, c, d, e, f) { ]; }; var f4 = registerServerReference($$RSC_SERVER_ACTION_4, "7ea9b2939c1f39073a6bed227fd20233064c8b7869", null); -export var $$RSC_SERVER_CACHE_5 = $$cache__("default", "ff471a5eb0be1c31686dd4ba938a80328b80b1615d", false, // Should be 1 111111 1, which is "ff" in hex. +export var $$RSC_SERVER_CACHE_5 = $$cache__("default", "ff471a5eb0be1c31686dd4ba938a80328b80b1615d", 0, // Should be 1 111111 1, which is "ff" in hex. async function f5(a, b, c, d, e, f, g) { return [ a, diff --git a/crates/next-custom-transforms/tests/fixture/server-actions/server/48/output.js b/crates/next-custom-transforms/tests/fixture/server-actions/server/48/output.js index 03e7baef7e5bf..4005e28f0c9d8 100644 --- a/crates/next-custom-transforms/tests/fixture/server-actions/server/48/output.js +++ b/crates/next-custom-transforms/tests/fixture/server-actions/server/48/output.js @@ -24,7 +24,7 @@ export async function action3(a, b) { {b}
; } -export var $$RSC_SERVER_CACHE_0 = $$cache__("default", "e03128060c414d59f8552e4788b846c0d2b7f74743", false, async function cache(a, b) { +export var $$RSC_SERVER_CACHE_0 = $$cache__("default", "e03128060c414d59f8552e4788b846c0d2b7f74743", 0, async function cache(a, b) { return
{a} {b} diff --git a/crates/next-custom-transforms/tests/fixture/server-actions/server/49/output.js b/crates/next-custom-transforms/tests/fixture/server-actions/server/49/output.js index 8182a0563e01f..743c407acadde 100644 --- a/crates/next-custom-transforms/tests/fixture/server-actions/server/49/output.js +++ b/crates/next-custom-transforms/tests/fixture/server-actions/server/49/output.js @@ -1,7 +1,7 @@ /* __next_internal_action_entry_do_not_use__ {"f03128060c414d59f8552e4788b846c0d2b7f74743":"$$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", "f03128060c414d59f8552e4788b846c0d2b7f74743", false, async function(a, b, c) { +export var $$RSC_SERVER_CACHE_0 = $$cache__("default", "f03128060c414d59f8552e4788b846c0d2b7f74743", 0, async function(a, b, c) { return
{a} {b} diff --git a/crates/next-custom-transforms/tests/fixture/server-actions/server/50/output.js b/crates/next-custom-transforms/tests/fixture/server-actions/server/50/output.js index e1f71054ca1f4..55df457988e38 100644 --- a/crates/next-custom-transforms/tests/fixture/server-actions/server/50/output.js +++ b/crates/next-custom-transforms/tests/fixture/server-actions/server/50/output.js @@ -1,7 +1,7 @@ /* __next_internal_action_entry_do_not_use__ {"f03128060c414d59f8552e4788b846c0d2b7f74743":"$$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", "f03128060c414d59f8552e4788b846c0d2b7f74743", false, async function(a, b, c) { +export var $$RSC_SERVER_CACHE_0 = $$cache__("default", "f03128060c414d59f8552e4788b846c0d2b7f74743", 0, async function(a, b, c) { return
{a} {b} diff --git a/packages/next/src/server/use-cache/use-cache-wrapper.ts b/packages/next/src/server/use-cache/use-cache-wrapper.ts index 4235945df5717..dbc58ca0980c5 100644 --- a/packages/next/src/server/use-cache/use-cache-wrapper.ts +++ b/packages/next/src/server/use-cache/use-cache-wrapper.ts @@ -438,7 +438,7 @@ function createTrackedReadableStream( export function cache( kind: string, id: string, - hasBoundArgs: boolean, + boundArgsLength: number, fn: any ) { if (!process.env.__NEXT_DYNAMIC_IO) { @@ -502,22 +502,29 @@ export function cache( } } - if (hasBoundArgs) { - if (args.length < 1) { + if (boundArgsLength > 0) { + if (args.length === 0) { throw new InvariantError( - 'Expected server closure to receive at least one argument, got: ' + - args.length + `Expected the "use cache" function ${JSON.stringify(fn.name)} to receive its encrypted bound arguments as the first argument.` ) } - const [encryptedBound, ...rest] = args - const decryptedBound = await decryptActionBoundArgs(id, encryptedBound) - if (!Array.isArray(decryptedBound)) { + + const [encryptedBoundArgs, ...otherArgs] = args + const boundArgs = await decryptActionBoundArgs(id, encryptedBoundArgs) + + if (!Array.isArray(boundArgs)) { throw new InvariantError( - 'Expected bound closure args to deserialize into an array, got: ' + - typeof decryptedBound + `Expected the bound arguments of "use cache" function ${JSON.stringify(fn.name)} to deserialize into an array, got ${typeof boundArgs} instead.` ) } - args = [decryptedBound, ...rest] + + if (boundArgsLength !== boundArgs.length) { + throw new InvariantError( + `Expected the "use cache" function ${JSON.stringify(fn.name)} to receive ${boundArgsLength} bound arguments, got ${boundArgs.length} instead.` + ) + } + + args = [...boundArgs, ...otherArgs] } const temporaryReferences = createClientTemporaryReferenceSet() From a7aeb6b2e944d6c22281149e516979edd4def7e9 Mon Sep 17 00:00:00 2001 From: Hendrik Liebau Date: Thu, 7 Nov 2024 19:48:22 +0100 Subject: [PATCH 6/7] Update outdated fixture output --- .../fixture/next-font-with-directive/use-cache/output.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 e58688ce68b03..e9f8160480327 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 @@ -3,11 +3,11 @@ import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc import { cache as $$cache__ } from "private-next-rsc-cache-wrapper"; 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", async function Cached({ children }) { +export var $$RSC_SERVER_CACHE_0 = $$cache__("default", "c0dd5bb6fef67f5ab84327f5164ac2c3111a159337", 0, async function Cached({ children }) { return
{children}
; }); Object.defineProperty($$RSC_SERVER_CACHE_0, "name", { "value": "Cached", "writable": false }); -export var Cached = registerServerReference($$RSC_SERVER_CACHE_0, "c0dd5bb6fef67f5ab84327f5164ac2c3111a159337", null); \ No newline at end of file +export var Cached = registerServerReference($$RSC_SERVER_CACHE_0, "c0dd5bb6fef67f5ab84327f5164ac2c3111a159337", null); From d51acdd2253896dda9910ac6453554d8e3462a78 Mon Sep 17 00:00:00 2001 From: Hendrik Liebau Date: Fri, 8 Nov 2024 20:34:02 +0100 Subject: [PATCH 7/7] Mutate args instead of copying --- packages/next/src/server/use-cache/use-cache-wrapper.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/next/src/server/use-cache/use-cache-wrapper.ts b/packages/next/src/server/use-cache/use-cache-wrapper.ts index dbc58ca0980c5..9c49c421db4e0 100644 --- a/packages/next/src/server/use-cache/use-cache-wrapper.ts +++ b/packages/next/src/server/use-cache/use-cache-wrapper.ts @@ -509,7 +509,7 @@ export function cache( ) } - const [encryptedBoundArgs, ...otherArgs] = args + const encryptedBoundArgs = args.shift() const boundArgs = await decryptActionBoundArgs(id, encryptedBoundArgs) if (!Array.isArray(boundArgs)) { @@ -524,7 +524,7 @@ export function cache( ) } - args = [...boundArgs, ...otherArgs] + args.unshift(...boundArgs) } const temporaryReferences = createClientTemporaryReferenceSet()