Unverified Commit a181122a authored by Hendrik Liebau's avatar Hendrik Liebau Committed by GitHub

Dedupe cached data from `"use cache"` functions in RSC payload (#75786)

parent b5c64045
...@@ -2376,7 +2376,7 @@ fn bind_args_to_ref_expr(expr: Expr, bound: Vec<Option<ExprOrSpread>>, action_id ...@@ -2376,7 +2376,7 @@ fn bind_args_to_ref_expr(expr: Expr, bound: Vec<Option<ExprOrSpread>>, action_id
if bound.is_empty() { if bound.is_empty() {
expr expr
} else { } else {
// expr.bind(null, [encryptActionBoundArgs("id", [arg1, ...])]) // expr.bind(null, [encryptActionBoundArgs("id", arg1, arg2, ...)])
Expr::Call(CallExpr { Expr::Call(CallExpr {
span: DUMMY_SP, span: DUMMY_SP,
callee: Expr::Member(MemberExpr { callee: Expr::Member(MemberExpr {
...@@ -2395,19 +2395,12 @@ fn bind_args_to_ref_expr(expr: Expr, bound: Vec<Option<ExprOrSpread>>, action_id ...@@ -2395,19 +2395,12 @@ fn bind_args_to_ref_expr(expr: Expr, bound: Vec<Option<ExprOrSpread>>, action_id
expr: Box::new(Expr::Call(CallExpr { expr: Box::new(Expr::Call(CallExpr {
span: DUMMY_SP, span: DUMMY_SP,
callee: quote_ident!("encryptActionBoundArgs").as_callee(), callee: quote_ident!("encryptActionBoundArgs").as_callee(),
args: vec![ args: std::iter::once(ExprOrSpread {
ExprOrSpread { spread: None,
spread: None, expr: Box::new(action_id.into()),
expr: Box::new(action_id.into()), })
}, .chain(bound.into_iter().flatten())
ExprOrSpread { .collect(),
spread: None,
expr: Box::new(Expr::Array(ArrayLit {
span: DUMMY_SP,
elems: bound,
})),
},
],
..Default::default() ..Default::default()
})), })),
}, },
......
...@@ -7,10 +7,7 @@ export const /*#__TURBOPACK_DISABLE_EXPORT_MERGING__*/ $$RSC_SERVER_ACTION_0 = a ...@@ -7,10 +7,7 @@ export const /*#__TURBOPACK_DISABLE_EXPORT_MERGING__*/ $$RSC_SERVER_ACTION_0 = a
await deleteFromDb($$ACTION_ARG_1); await deleteFromDb($$ACTION_ARG_1);
}; };
export function Item({ id1, id2 }) { export function Item({ id1, id2 }) {
var deleteItem = registerServerReference($$RSC_SERVER_ACTION_0, "406a88810ecce4a4e8b59d53b8327d7e98bbf251d7", null).bind(null, encryptActionBoundArgs("406a88810ecce4a4e8b59d53b8327d7e98bbf251d7", [ var deleteItem = registerServerReference($$RSC_SERVER_ACTION_0, "406a88810ecce4a4e8b59d53b8327d7e98bbf251d7", null).bind(null, encryptActionBoundArgs("406a88810ecce4a4e8b59d53b8327d7e98bbf251d7", id1, id2));
id1,
id2
]));
return <Button action={deleteItem}>Delete</Button>; return <Button action={deleteItem}>Delete</Button>;
} }
export const /*#__TURBOPACK_DISABLE_EXPORT_MERGING__*/ $$RSC_SERVER_ACTION_1 = async function action($$ACTION_CLOSURE_BOUND) { export const /*#__TURBOPACK_DISABLE_EXPORT_MERGING__*/ $$RSC_SERVER_ACTION_1 = async function action($$ACTION_CLOSURE_BOUND) {
...@@ -23,9 +20,6 @@ export default function Home() { ...@@ -23,9 +20,6 @@ export default function Home() {
name: 'John', name: 'John',
test: 'test' test: 'test'
}; };
const action = registerServerReference($$RSC_SERVER_ACTION_1, "4090b5db271335765a4b0eab01f044b381b5ebd5cd", null).bind(null, encryptActionBoundArgs("4090b5db271335765a4b0eab01f044b381b5ebd5cd", [ const action = registerServerReference($$RSC_SERVER_ACTION_1, "4090b5db271335765a4b0eab01f044b381b5ebd5cd", null).bind(null, encryptActionBoundArgs("4090b5db271335765a4b0eab01f044b381b5ebd5cd", info.name, info.test));
info.name,
info.test
]));
return null; return null;
} }
...@@ -10,10 +10,7 @@ export const /*#__TURBOPACK_DISABLE_EXPORT_MERGING__*/ $$RSC_SERVER_ACTION_0 = a ...@@ -10,10 +10,7 @@ export const /*#__TURBOPACK_DISABLE_EXPORT_MERGING__*/ $$RSC_SERVER_ACTION_0 = a
}; };
export function Item({ id1, id2 }) { export function Item({ id1, id2 }) {
const v2 = id2; const v2 = id2;
const deleteItem = registerServerReference($$RSC_SERVER_ACTION_0, "406a88810ecce4a4e8b59d53b8327d7e98bbf251d7", null).bind(null, encryptActionBoundArgs("406a88810ecce4a4e8b59d53b8327d7e98bbf251d7", [ const deleteItem = registerServerReference($$RSC_SERVER_ACTION_0, "406a88810ecce4a4e8b59d53b8327d7e98bbf251d7", null).bind(null, encryptActionBoundArgs("406a88810ecce4a4e8b59d53b8327d7e98bbf251d7", id1, v2));
id1,
v2
]));
return <Button action={deleteItem}>Delete</Button>; return <Button action={deleteItem}>Delete</Button>;
} }
export const /*#__TURBOPACK_DISABLE_EXPORT_MERGING__*/ $$RSC_SERVER_ACTION_1 = async function g($$ACTION_CLOSURE_BOUND, y, ...z) { export const /*#__TURBOPACK_DISABLE_EXPORT_MERGING__*/ $$RSC_SERVER_ACTION_1 = async function g($$ACTION_CLOSURE_BOUND, y, ...z) {
...@@ -21,16 +18,12 @@ export const /*#__TURBOPACK_DISABLE_EXPORT_MERGING__*/ $$RSC_SERVER_ACTION_1 = a ...@@ -21,16 +18,12 @@ export const /*#__TURBOPACK_DISABLE_EXPORT_MERGING__*/ $$RSC_SERVER_ACTION_1 = a
return $$ACTION_ARG_0 + y + z[0]; return $$ACTION_ARG_0 + y + z[0];
}; };
const f = (x)=>{ const f = (x)=>{
var g = registerServerReference($$RSC_SERVER_ACTION_1, "7f90b5db271335765a4b0eab01f044b381b5ebd5cd", null).bind(null, encryptActionBoundArgs("7f90b5db271335765a4b0eab01f044b381b5ebd5cd", [ var g = registerServerReference($$RSC_SERVER_ACTION_1, "7f90b5db271335765a4b0eab01f044b381b5ebd5cd", null).bind(null, encryptActionBoundArgs("7f90b5db271335765a4b0eab01f044b381b5ebd5cd", x));
x
]));
}; };
export const /*#__TURBOPACK_DISABLE_EXPORT_MERGING__*/ $$RSC_SERVER_ACTION_2 = async function f($$ACTION_CLOSURE_BOUND, y, ...z) { export const /*#__TURBOPACK_DISABLE_EXPORT_MERGING__*/ $$RSC_SERVER_ACTION_2 = async function f($$ACTION_CLOSURE_BOUND, y, ...z) {
var [$$ACTION_ARG_0] = await decryptActionBoundArgs("7f1c36b06e398c97abe5d5d7ae8c672bfddf4e1b91", $$ACTION_CLOSURE_BOUND); var [$$ACTION_ARG_0] = await decryptActionBoundArgs("7f1c36b06e398c97abe5d5d7ae8c672bfddf4e1b91", $$ACTION_CLOSURE_BOUND);
return $$ACTION_ARG_0 + y + z[0]; return $$ACTION_ARG_0 + y + z[0];
}; };
const g = (x)=>{ const g = (x)=>{
f = registerServerReference($$RSC_SERVER_ACTION_2, "7f1c36b06e398c97abe5d5d7ae8c672bfddf4e1b91", null).bind(null, encryptActionBoundArgs("7f1c36b06e398c97abe5d5d7ae8c672bfddf4e1b91", [ f = registerServerReference($$RSC_SERVER_ACTION_2, "7f1c36b06e398c97abe5d5d7ae8c672bfddf4e1b91", null).bind(null, encryptActionBoundArgs("7f1c36b06e398c97abe5d5d7ae8c672bfddf4e1b91", x));
x
]));
}; };
...@@ -17,16 +17,10 @@ export const /*#__TURBOPACK_DISABLE_EXPORT_MERGING__*/ $$RSC_SERVER_ACTION_1 = a ...@@ -17,16 +17,10 @@ export const /*#__TURBOPACK_DISABLE_EXPORT_MERGING__*/ $$RSC_SERVER_ACTION_1 = a
export function Item({ id1, id2 }) { export function Item({ id1, id2 }) {
const v2 = id2; const v2 = id2;
return <> return <>
<Button action={registerServerReference($$RSC_SERVER_ACTION_0, "406a88810ecce4a4e8b59d53b8327d7e98bbf251d7", null).bind(null, encryptActionBoundArgs("406a88810ecce4a4e8b59d53b8327d7e98bbf251d7", [ <Button action={registerServerReference($$RSC_SERVER_ACTION_0, "406a88810ecce4a4e8b59d53b8327d7e98bbf251d7", null).bind(null, encryptActionBoundArgs("406a88810ecce4a4e8b59d53b8327d7e98bbf251d7", id1, v2))}>
id1,
v2
]))}>
Delete Delete
</Button> </Button>
<Button action={registerServerReference($$RSC_SERVER_ACTION_1, "4090b5db271335765a4b0eab01f044b381b5ebd5cd", null).bind(null, encryptActionBoundArgs("4090b5db271335765a4b0eab01f044b381b5ebd5cd", [ <Button action={registerServerReference($$RSC_SERVER_ACTION_1, "4090b5db271335765a4b0eab01f044b381b5ebd5cd", null).bind(null, encryptActionBoundArgs("4090b5db271335765a4b0eab01f044b381b5ebd5cd", id1, v2))}>
id1,
v2
]))}>
Delete Delete
</Button> </Button>
</>; </>;
......
...@@ -6,9 +6,7 @@ export const /*#__TURBOPACK_DISABLE_EXPORT_MERGING__*/ $$RSC_SERVER_ACTION_0 = a ...@@ -6,9 +6,7 @@ export const /*#__TURBOPACK_DISABLE_EXPORT_MERGING__*/ $$RSC_SERVER_ACTION_0 = a
}; };
export function Item({ value }) { export function Item({ value }) {
return <> return <>
<Button action={registerServerReference($$RSC_SERVER_ACTION_0, "606a88810ecce4a4e8b59d53b8327d7e98bbf251d7", null).bind(null, encryptActionBoundArgs("606a88810ecce4a4e8b59d53b8327d7e98bbf251d7", [ <Button action={registerServerReference($$RSC_SERVER_ACTION_0, "606a88810ecce4a4e8b59d53b8327d7e98bbf251d7", null).bind(null, encryptActionBoundArgs("606a88810ecce4a4e8b59d53b8327d7e98bbf251d7", value))}>
value
]))}>
Multiple Multiple
</Button> </Button>
</>; </>;
......
...@@ -9,9 +9,7 @@ export const /*#__TURBOPACK_DISABLE_EXPORT_MERGING__*/ $$RSC_SERVER_ACTION_0 = a ...@@ -9,9 +9,7 @@ export const /*#__TURBOPACK_DISABLE_EXPORT_MERGING__*/ $$RSC_SERVER_ACTION_0 = a
export default function Page() { export default function Page() {
const y = 1; const y = 1;
return <Foo // TODO: should use `action` as function name? return <Foo // TODO: should use `action` as function name?
action={validator(registerServerReference($$RSC_SERVER_ACTION_0, "606a88810ecce4a4e8b59d53b8327d7e98bbf251d7", null).bind(null, encryptActionBoundArgs("606a88810ecce4a4e8b59d53b8327d7e98bbf251d7", [ action={validator(registerServerReference($$RSC_SERVER_ACTION_0, "606a88810ecce4a4e8b59d53b8327d7e98bbf251d7", null).bind(null, encryptActionBoundArgs("606a88810ecce4a4e8b59d53b8327d7e98bbf251d7", y)))}/>;
y
])))}/>;
} }
export const /*#__TURBOPACK_DISABLE_EXPORT_MERGING__*/ $$RSC_SERVER_ACTION_1 = async function() {}; export const /*#__TURBOPACK_DISABLE_EXPORT_MERGING__*/ $$RSC_SERVER_ACTION_1 = async function() {};
validator(registerServerReference($$RSC_SERVER_ACTION_1, "0090b5db271335765a4b0eab01f044b381b5ebd5cd", null)); validator(registerServerReference($$RSC_SERVER_ACTION_1, "0090b5db271335765a4b0eab01f044b381b5ebd5cd", null));
......
...@@ -9,12 +9,8 @@ export const /*#__TURBOPACK_DISABLE_EXPORT_MERGING__*/ $$RSC_SERVER_ACTION_1 = a ...@@ -9,12 +9,8 @@ export const /*#__TURBOPACK_DISABLE_EXPORT_MERGING__*/ $$RSC_SERVER_ACTION_1 = a
console.log(a, b, $$ACTION_ARG_0, c, d); console.log(a, b, $$ACTION_ARG_0, c, d);
}; };
export default function Page({ foo, x, y }) { export default function Page({ foo, x, y }) {
var action = registerServerReference($$RSC_SERVER_ACTION_0, "7c6a88810ecce4a4e8b59d53b8327d7e98bbf251d7", null).bind(null, encryptActionBoundArgs("7c6a88810ecce4a4e8b59d53b8327d7e98bbf251d7", [ var action = registerServerReference($$RSC_SERVER_ACTION_0, "7c6a88810ecce4a4e8b59d53b8327d7e98bbf251d7", null).bind(null, encryptActionBoundArgs("7c6a88810ecce4a4e8b59d53b8327d7e98bbf251d7", x));
x
]));
action.bind(null, foo[0], foo[1], foo.x, foo[y]); action.bind(null, foo[0], foo[1], foo.x, foo[y]);
const action2 = registerServerReference($$RSC_SERVER_ACTION_1, "7c90b5db271335765a4b0eab01f044b381b5ebd5cd", null).bind(null, encryptActionBoundArgs("7c90b5db271335765a4b0eab01f044b381b5ebd5cd", [ const action2 = registerServerReference($$RSC_SERVER_ACTION_1, "7c90b5db271335765a4b0eab01f044b381b5ebd5cd", null).bind(null, encryptActionBoundArgs("7c90b5db271335765a4b0eab01f044b381b5ebd5cd", x));
x
]));
action2.bind(null, foo[0], foo[1], foo.x, foo[y]); action2.bind(null, foo[0], foo[1], foo.x, foo[y]);
} }
...@@ -5,7 +5,5 @@ export const /*#__TURBOPACK_DISABLE_EXPORT_MERGING__*/ $$RSC_SERVER_ACTION_0 = a ...@@ -5,7 +5,5 @@ export const /*#__TURBOPACK_DISABLE_EXPORT_MERGING__*/ $$RSC_SERVER_ACTION_0 = a
console.log(a, b, $$ACTION_ARG_0, d); console.log(a, b, $$ACTION_ARG_0, d);
}; };
export default function Page({ foo, x, y }) { export default function Page({ foo, x, y }) {
var action = registerServerReference($$RSC_SERVER_ACTION_0, "7c6a88810ecce4a4e8b59d53b8327d7e98bbf251d7", null).bind(null, encryptActionBoundArgs("7c6a88810ecce4a4e8b59d53b8327d7e98bbf251d7", [ var action = registerServerReference($$RSC_SERVER_ACTION_0, "7c6a88810ecce4a4e8b59d53b8327d7e98bbf251d7", null).bind(null, encryptActionBoundArgs("7c6a88810ecce4a4e8b59d53b8327d7e98bbf251d7", foo));
foo
]));
} }
...@@ -12,10 +12,7 @@ export function Item({ id1, id2 }) { ...@@ -12,10 +12,7 @@ export function Item({ id1, id2 }) {
id1++; id1++;
return <Button action={deleteItem}>Delete</Button>; return <Button action={deleteItem}>Delete</Button>;
})(); })();
var deleteItem = registerServerReference($$RSC_SERVER_ACTION_0, "406a88810ecce4a4e8b59d53b8327d7e98bbf251d7", null).bind(null, encryptActionBoundArgs("406a88810ecce4a4e8b59d53b8327d7e98bbf251d7", [ var deleteItem = registerServerReference($$RSC_SERVER_ACTION_0, "406a88810ecce4a4e8b59d53b8327d7e98bbf251d7", null).bind(null, encryptActionBoundArgs("406a88810ecce4a4e8b59d53b8327d7e98bbf251d7", id1, id2));
id1,
id2
]));
} }
export const /*#__TURBOPACK_DISABLE_EXPORT_MERGING__*/ $$RSC_SERVER_ACTION_1 = async function deleteItem($$ACTION_CLOSURE_BOUND) { export const /*#__TURBOPACK_DISABLE_EXPORT_MERGING__*/ $$RSC_SERVER_ACTION_1 = async function deleteItem($$ACTION_CLOSURE_BOUND) {
var [$$ACTION_ARG_0, $$ACTION_ARG_1] = await decryptActionBoundArgs("4090b5db271335765a4b0eab01f044b381b5ebd5cd", $$ACTION_CLOSURE_BOUND); var [$$ACTION_ARG_0, $$ACTION_ARG_1] = await decryptActionBoundArgs("4090b5db271335765a4b0eab01f044b381b5ebd5cd", $$ACTION_CLOSURE_BOUND);
...@@ -31,8 +28,5 @@ export function Item2({ id1, id2 }) { ...@@ -31,8 +28,5 @@ export function Item2({ id1, id2 }) {
id1++; id1++;
temp.push(<Button action={deleteItem}>Delete</Button>); temp.push(<Button action={deleteItem}>Delete</Button>);
return temp; return temp;
var deleteItem = registerServerReference($$RSC_SERVER_ACTION_1, "4090b5db271335765a4b0eab01f044b381b5ebd5cd", null).bind(null, encryptActionBoundArgs("4090b5db271335765a4b0eab01f044b381b5ebd5cd", [ var deleteItem = registerServerReference($$RSC_SERVER_ACTION_1, "4090b5db271335765a4b0eab01f044b381b5ebd5cd", null).bind(null, encryptActionBoundArgs("4090b5db271335765a4b0eab01f044b381b5ebd5cd", id1, id2));
id1,
id2
]));
} }
...@@ -17,25 +17,12 @@ export const /*#__TURBOPACK_DISABLE_EXPORT_MERGING__*/ $$RSC_SERVER_ACTION_2 = a ...@@ -17,25 +17,12 @@ export const /*#__TURBOPACK_DISABLE_EXPORT_MERGING__*/ $$RSC_SERVER_ACTION_2 = a
window window
}); });
console.log(a, $$ACTION_ARG_0, action2); console.log(a, $$ACTION_ARG_0, action2);
var action2 = registerServerReference($$RSC_SERVER_ACTION_0, "606a88810ecce4a4e8b59d53b8327d7e98bbf251d7", null).bind(null, encryptActionBoundArgs("606a88810ecce4a4e8b59d53b8327d7e98bbf251d7", [ var action2 = registerServerReference($$RSC_SERVER_ACTION_0, "606a88810ecce4a4e8b59d53b8327d7e98bbf251d7", null).bind(null, encryptActionBoundArgs("606a88810ecce4a4e8b59d53b8327d7e98bbf251d7", $$ACTION_ARG_1, d, f, $$ACTION_ARG_2));
$$ACTION_ARG_1,
d,
f,
$$ACTION_ARG_2
]));
return [ return [
action2, action2,
registerServerReference($$RSC_SERVER_ACTION_1, "6090b5db271335765a4b0eab01f044b381b5ebd5cd", null).bind(null, encryptActionBoundArgs("6090b5db271335765a4b0eab01f044b381b5ebd5cd", [ registerServerReference($$RSC_SERVER_ACTION_1, "6090b5db271335765a4b0eab01f044b381b5ebd5cd", null).bind(null, encryptActionBoundArgs("6090b5db271335765a4b0eab01f044b381b5ebd5cd", action2, $$ACTION_ARG_1, d))
action2,
$$ACTION_ARG_1,
d
]))
]; ];
}; };
function Comp(b, c, ...g) { function Comp(b, c, ...g) {
return registerServerReference($$RSC_SERVER_ACTION_2, "601c36b06e398c97abe5d5d7ae8c672bfddf4e1b91", null).bind(null, encryptActionBoundArgs("601c36b06e398c97abe5d5d7ae8c672bfddf4e1b91", [ return registerServerReference($$RSC_SERVER_ACTION_2, "601c36b06e398c97abe5d5d7ae8c672bfddf4e1b91", null).bind(null, encryptActionBoundArgs("601c36b06e398c97abe5d5d7ae8c672bfddf4e1b91", b, c, g));
b,
c,
g
]));
} }
...@@ -17,27 +17,14 @@ export const /*#__TURBOPACK_DISABLE_EXPORT_MERGING__*/ $$RSC_SERVER_ACTION_2 = a ...@@ -17,27 +17,14 @@ export const /*#__TURBOPACK_DISABLE_EXPORT_MERGING__*/ $$RSC_SERVER_ACTION_2 = a
window window
}); });
console.log(a, $$ACTION_ARG_0, action2); console.log(a, $$ACTION_ARG_0, action2);
var action2 = registerServerReference($$RSC_SERVER_ACTION_0, "606a88810ecce4a4e8b59d53b8327d7e98bbf251d7", null).bind(null, encryptActionBoundArgs("606a88810ecce4a4e8b59d53b8327d7e98bbf251d7", [ var action2 = registerServerReference($$RSC_SERVER_ACTION_0, "606a88810ecce4a4e8b59d53b8327d7e98bbf251d7", null).bind(null, encryptActionBoundArgs("606a88810ecce4a4e8b59d53b8327d7e98bbf251d7", $$ACTION_ARG_1, d, f, $$ACTION_ARG_2));
$$ACTION_ARG_1,
d,
f,
$$ACTION_ARG_2
]));
return [ return [
action2, action2,
registerServerReference($$RSC_SERVER_ACTION_1, "6090b5db271335765a4b0eab01f044b381b5ebd5cd", null).bind(null, encryptActionBoundArgs("6090b5db271335765a4b0eab01f044b381b5ebd5cd", [ registerServerReference($$RSC_SERVER_ACTION_1, "6090b5db271335765a4b0eab01f044b381b5ebd5cd", null).bind(null, encryptActionBoundArgs("6090b5db271335765a4b0eab01f044b381b5ebd5cd", action2, $$ACTION_ARG_1, d))
action2,
$$ACTION_ARG_1,
d
]))
]; ];
}; };
export async function /*#__TURBOPACK_DISABLE_EXPORT_MERGING__*/ action0(b, c, ...g) { export async function /*#__TURBOPACK_DISABLE_EXPORT_MERGING__*/ action0(b, c, ...g) {
return registerServerReference($$RSC_SERVER_ACTION_2, "601c36b06e398c97abe5d5d7ae8c672bfddf4e1b91", null).bind(null, encryptActionBoundArgs("601c36b06e398c97abe5d5d7ae8c672bfddf4e1b91", [ return registerServerReference($$RSC_SERVER_ACTION_2, "601c36b06e398c97abe5d5d7ae8c672bfddf4e1b91", null).bind(null, encryptActionBoundArgs("601c36b06e398c97abe5d5d7ae8c672bfddf4e1b91", b, c, g));
b,
c,
g
]));
} }
import { ensureServerEntryExports } from "private-next-rsc-action-validate"; import { ensureServerEntryExports } from "private-next-rsc-action-validate";
ensureServerEntryExports([ ensureServerEntryExports([
......
...@@ -21,10 +21,6 @@ export function Component() { ...@@ -21,10 +21,6 @@ export function Component() {
current: 1 current: 1
} }
}; };
var action = registerServerReference($$RSC_SERVER_ACTION_0, "406a88810ecce4a4e8b59d53b8327d7e98bbf251d7", null).bind(null, encryptActionBoundArgs("406a88810ecce4a4e8b59d53b8327d7e98bbf251d7", [ var action = registerServerReference($$RSC_SERVER_ACTION_0, "406a88810ecce4a4e8b59d53b8327d7e98bbf251d7", null).bind(null, encryptActionBoundArgs("406a88810ecce4a4e8b59d53b8327d7e98bbf251d7", data, baz.value, foo));
data,
baz.value,
foo
]));
return <form action={action}/>; return <form action={action}/>;
} }
...@@ -13,10 +13,7 @@ Object.defineProperty($$RSC_SERVER_CACHE_0, "name", { ...@@ -13,10 +13,7 @@ Object.defineProperty($$RSC_SERVER_CACHE_0, "name", {
}); });
async function Component({ foo }) { async function Component({ foo }) {
const a = 123; const a = 123;
var fn = $$RSC_SERVER_REF_1.bind(null, encryptActionBoundArgs("c03128060c414d59f8552e4788b846c0d2b7f74743", [ var fn = $$RSC_SERVER_REF_1.bind(null, encryptActionBoundArgs("c03128060c414d59f8552e4788b846c0d2b7f74743", a, foo));
a,
foo
]));
const data = await fn(); const data = await fn();
return <div>{data}</div>; return <div>{data}</div>;
} }
......
...@@ -17,18 +17,12 @@ Object.defineProperty($$RSC_SERVER_CACHE_0, "name", { ...@@ -17,18 +17,12 @@ Object.defineProperty($$RSC_SERVER_CACHE_0, "name", {
export const /*#__TURBOPACK_DISABLE_EXPORT_MERGING__*/ $$RSC_SERVER_ACTION_2 = async function action($$ACTION_CLOSURE_BOUND, c) { export const /*#__TURBOPACK_DISABLE_EXPORT_MERGING__*/ $$RSC_SERVER_ACTION_2 = async function action($$ACTION_CLOSURE_BOUND, c) {
var [$$ACTION_ARG_0, $$ACTION_ARG_1] = await decryptActionBoundArgs("601c36b06e398c97abe5d5d7ae8c672bfddf4e1b91", $$ACTION_CLOSURE_BOUND); var [$$ACTION_ARG_0, $$ACTION_ARG_1] = await decryptActionBoundArgs("601c36b06e398c97abe5d5d7ae8c672bfddf4e1b91", $$ACTION_CLOSURE_BOUND);
const d = $$ACTION_ARG_0 + $$ACTION_ARG_1 + c; const d = $$ACTION_ARG_0 + $$ACTION_ARG_1 + c;
var cache = $$RSC_SERVER_REF_1.bind(null, encryptActionBoundArgs("e03128060c414d59f8552e4788b846c0d2b7f74743", [ var cache = $$RSC_SERVER_REF_1.bind(null, encryptActionBoundArgs("e03128060c414d59f8552e4788b846c0d2b7f74743", d, $$ACTION_ARG_0));
d,
$$ACTION_ARG_0
]));
return cache(d); return cache(d);
}; };
async function Component({ a }) { async function Component({ a }) {
const b = 1; const b = 1;
var action = registerServerReference($$RSC_SERVER_ACTION_2, "601c36b06e398c97abe5d5d7ae8c672bfddf4e1b91", null).bind(null, encryptActionBoundArgs("601c36b06e398c97abe5d5d7ae8c672bfddf4e1b91", [ var action = registerServerReference($$RSC_SERVER_ACTION_2, "601c36b06e398c97abe5d5d7ae8c672bfddf4e1b91", null).bind(null, encryptActionBoundArgs("601c36b06e398c97abe5d5d7ae8c672bfddf4e1b91", a, b));
a,
b
]));
return <form action={action}> return <form action={action}>
<button>Submit</button> <button>Submit</button>
</form>; </form>;
......
...@@ -10,10 +10,7 @@ export const /*#__TURBOPACK_DISABLE_EXPORT_MERGING__*/ $$RSC_SERVER_ACTION_0 = a ...@@ -10,10 +10,7 @@ export const /*#__TURBOPACK_DISABLE_EXPORT_MERGING__*/ $$RSC_SERVER_ACTION_0 = a
}; };
export var /*#__TURBOPACK_DISABLE_EXPORT_MERGING__*/ $$RSC_SERVER_CACHE_1 = $$cache__("default", "c0951c375b4a6a6e89d67b743ec5808127cfde405d", 0, async function Component({ foo }) { export var /*#__TURBOPACK_DISABLE_EXPORT_MERGING__*/ $$RSC_SERVER_CACHE_1 = $$cache__("default", "c0951c375b4a6a6e89d67b743ec5808127cfde405d", 0, async function Component({ foo }) {
const a = 123; const a = 123;
var fn = registerServerReference($$RSC_SERVER_ACTION_0, "406a88810ecce4a4e8b59d53b8327d7e98bbf251d7", null).bind(null, encryptActionBoundArgs("406a88810ecce4a4e8b59d53b8327d7e98bbf251d7", [ var fn = registerServerReference($$RSC_SERVER_ACTION_0, "406a88810ecce4a4e8b59d53b8327d7e98bbf251d7", null).bind(null, encryptActionBoundArgs("406a88810ecce4a4e8b59d53b8327d7e98bbf251d7", a, foo));
a,
foo
]));
const data = await fn(); const data = await fn();
return <div>{data}</div>; return <div>{data}</div>;
}); });
......
...@@ -13,10 +13,7 @@ Object.defineProperty($$RSC_SERVER_CACHE_0, "name", { ...@@ -13,10 +13,7 @@ Object.defineProperty($$RSC_SERVER_CACHE_0, "name", {
}); });
async function Component({ foo }) { async function Component({ foo }) {
const a = 123; const a = 123;
const fn = $$RSC_SERVER_REF_1.bind(null, encryptActionBoundArgs("c03128060c414d59f8552e4788b846c0d2b7f74743", [ const fn = $$RSC_SERVER_REF_1.bind(null, encryptActionBoundArgs("c03128060c414d59f8552e4788b846c0d2b7f74743", a, foo));
a,
foo
]));
const data = await fn(); const data = await fn();
return <div>{data}</div>; return <div>{data}</div>;
} }
......
...@@ -11,9 +11,7 @@ export var /*#__TURBOPACK_DISABLE_EXPORT_MERGING__*/ $$RSC_SERVER_CACHE_1 = $$ca ...@@ -11,9 +11,7 @@ export var /*#__TURBOPACK_DISABLE_EXPORT_MERGING__*/ $$RSC_SERVER_CACHE_1 = $$ca
return { return {
x, x,
y: Math.random(), y: Math.random(),
z: <Foo action={registerServerReference($$RSC_SERVER_ACTION_0, "406a88810ecce4a4e8b59d53b8327d7e98bbf251d7", null).bind(null, encryptActionBoundArgs("406a88810ecce4a4e8b59d53b8327d7e98bbf251d7", [ z: <Foo action={registerServerReference($$RSC_SERVER_ACTION_0, "406a88810ecce4a4e8b59d53b8327d7e98bbf251d7", null).bind(null, encryptActionBoundArgs("406a88810ecce4a4e8b59d53b8327d7e98bbf251d7", x))}/>,
x
]))}/>,
r: children r: children
}; };
}); });
......
...@@ -14,11 +14,6 @@ export const /*#__TURBOPACK_DISABLE_EXPORT_MERGING__*/ $$RSC_SERVER_ACTION_0 = a ...@@ -14,11 +14,6 @@ export const /*#__TURBOPACK_DISABLE_EXPORT_MERGING__*/ $$RSC_SERVER_ACTION_0 = a
}; };
export function Item({ id1, id2, id3, id4 }) { export function Item({ id1, id2, id3, id4 }) {
const v2 = id2; const v2 = id2;
var deleteItem = registerServerReference($$RSC_SERVER_ACTION_0, "406a88810ecce4a4e8b59d53b8327d7e98bbf251d7", null).bind(null, encryptActionBoundArgs("406a88810ecce4a4e8b59d53b8327d7e98bbf251d7", [ var deleteItem = registerServerReference($$RSC_SERVER_ACTION_0, "406a88810ecce4a4e8b59d53b8327d7e98bbf251d7", null).bind(null, encryptActionBoundArgs("406a88810ecce4a4e8b59d53b8327d7e98bbf251d7", id1, v2, id3, id4.x));
id1,
v2,
id3,
id4.x
]));
return <Button action={deleteItem}>Delete</Button>; return <Button action={deleteItem}>Delete</Button>;
} }
...@@ -33,19 +33,7 @@ export async function Component(a) { ...@@ -33,19 +33,7 @@ export async function Component(a) {
const b = 1; const b = 1;
return <Client // Should be 1 110000 0, which is "e0" in hex (counts as two params, return <Client // Should be 1 110000 0, which is "e0" in hex (counts as two params,
// because of the encrypted bound args param) // because of the encrypted bound args param)
fn1={$$RSC_SERVER_REF_1.bind(null, encryptActionBoundArgs("e03128060c414d59f8552e4788b846c0d2b7f74743", [ fn1={$$RSC_SERVER_REF_1.bind(null, encryptActionBoundArgs("e03128060c414d59f8552e4788b846c0d2b7f74743", a, b))} fn2={$$RSC_SERVER_REF_3.bind(null, encryptActionBoundArgs("c069348c79fce073bae2f70f139565a2fda1c74c74", a, b))} fn3={registerServerReference($$RSC_SERVER_ACTION_4, "60a9b2939c1f39073a6bed227fd20233064c8b7869", null).bind(null, encryptActionBoundArgs("60a9b2939c1f39073a6bed227fd20233064c8b7869", a, b))} fn4={registerServerReference($$RSC_SERVER_ACTION_5, "409651a98a9dccd7ffbe72ff5cf0f38546ca1252ab", null).bind(null, encryptActionBoundArgs("409651a98a9dccd7ffbe72ff5cf0f38546ca1252ab", a, b))}/>;
a,
b
]))} fn2={$$RSC_SERVER_REF_3.bind(null, encryptActionBoundArgs("c069348c79fce073bae2f70f139565a2fda1c74c74", [
a,
b
]))} fn3={registerServerReference($$RSC_SERVER_ACTION_4, "60a9b2939c1f39073a6bed227fd20233064c8b7869", null).bind(null, encryptActionBoundArgs("60a9b2939c1f39073a6bed227fd20233064c8b7869", [
a,
b
]))} fn4={registerServerReference($$RSC_SERVER_ACTION_5, "409651a98a9dccd7ffbe72ff5cf0f38546ca1252ab", null).bind(null, encryptActionBoundArgs("409651a98a9dccd7ffbe72ff5cf0f38546ca1252ab", [
a,
b
]))}/>;
} }
var $$RSC_SERVER_REF_1 = registerServerReference($$RSC_SERVER_CACHE_0, "e03128060c414d59f8552e4788b846c0d2b7f74743", null); var $$RSC_SERVER_REF_1 = registerServerReference($$RSC_SERVER_CACHE_0, "e03128060c414d59f8552e4788b846c0d2b7f74743", null);
var $$RSC_SERVER_REF_3 = registerServerReference($$RSC_SERVER_CACHE_2, "c069348c79fce073bae2f70f139565a2fda1c74c74", null); var $$RSC_SERVER_REF_3 = registerServerReference($$RSC_SERVER_CACHE_2, "c069348c79fce073bae2f70f139565a2fda1c74c74", null);
...@@ -15,13 +15,8 @@ export const /*#__TURBOPACK_DISABLE_EXPORT_MERGING__*/ $$RSC_SERVER_ACTION_2 = a ...@@ -15,13 +15,8 @@ export const /*#__TURBOPACK_DISABLE_EXPORT_MERGING__*/ $$RSC_SERVER_ACTION_2 = a
function createObj(n) { function createObj(n) {
const m = n + 1; const m = n + 1;
return { return {
foo: $$RSC_SERVER_REF_1.bind(null, encryptActionBoundArgs("c03128060c414d59f8552e4788b846c0d2b7f74743", [ foo: $$RSC_SERVER_REF_1.bind(null, encryptActionBoundArgs("c03128060c414d59f8552e4788b846c0d2b7f74743", n, m)),
n, bar: registerServerReference($$RSC_SERVER_ACTION_2, "401c36b06e398c97abe5d5d7ae8c672bfddf4e1b91", null).bind(null, encryptActionBoundArgs("401c36b06e398c97abe5d5d7ae8c672bfddf4e1b91", m))
m
])),
bar: registerServerReference($$RSC_SERVER_ACTION_2, "401c36b06e398c97abe5d5d7ae8c672bfddf4e1b91", null).bind(null, encryptActionBoundArgs("401c36b06e398c97abe5d5d7ae8c672bfddf4e1b91", [
m
]))
}; };
} }
var $$RSC_SERVER_REF_1 = registerServerReference($$RSC_SERVER_CACHE_0, "c03128060c414d59f8552e4788b846c0d2b7f74743", null); var $$RSC_SERVER_REF_1 = registerServerReference($$RSC_SERVER_CACHE_0, "c03128060c414d59f8552e4788b846c0d2b7f74743", null);
...@@ -8,9 +8,7 @@ function createCachedFn(start) { ...@@ -8,9 +8,7 @@ function createCachedFn(start) {
function fn() { function fn() {
return start + Math.random(); return start + Math.random();
} }
return $$RSC_SERVER_REF_1.bind(null, encryptActionBoundArgs("c03128060c414d59f8552e4788b846c0d2b7f74743", [ return $$RSC_SERVER_REF_1.bind(null, encryptActionBoundArgs("c03128060c414d59f8552e4788b846c0d2b7f74743", fn));
fn
]));
} }
var $$RSC_SERVER_REF_1 = registerServerReference($$RSC_SERVER_CACHE_0, "c03128060c414d59f8552e4788b846c0d2b7f74743", null); var $$RSC_SERVER_REF_1 = registerServerReference($$RSC_SERVER_CACHE_0, "c03128060c414d59f8552e4788b846c0d2b7f74743", null);
export const /*#__TURBOPACK_DISABLE_EXPORT_MERGING__*/ $$RSC_SERVER_ACTION_2 = async function($$ACTION_CLOSURE_BOUND) { export const /*#__TURBOPACK_DISABLE_EXPORT_MERGING__*/ $$RSC_SERVER_ACTION_2 = async function($$ACTION_CLOSURE_BOUND) {
...@@ -21,7 +19,5 @@ function createServerAction(start) { ...@@ -21,7 +19,5 @@ function createServerAction(start) {
function fn() { function fn() {
return start + Math.random(); return start + Math.random();
} }
return registerServerReference($$RSC_SERVER_ACTION_2, "401c36b06e398c97abe5d5d7ae8c672bfddf4e1b91", null).bind(null, encryptActionBoundArgs("401c36b06e398c97abe5d5d7ae8c672bfddf4e1b91", [ return registerServerReference($$RSC_SERVER_ACTION_2, "401c36b06e398c97abe5d5d7ae8c672bfddf4e1b91", null).bind(null, encryptActionBoundArgs("401c36b06e398c97abe5d5d7ae8c672bfddf4e1b91", fn));
fn
]));
} }
...@@ -28,13 +28,6 @@ export function y(p, [p1, { p2 }], ...p3) { ...@@ -28,13 +28,6 @@ export function y(p, [p1, { p2 }], ...p3) {
if (true) { if (true) {
const f8 = 1; const f8 = 1;
} }
var action = registerServerReference($$RSC_SERVER_ACTION_0, "406a88810ecce4a4e8b59d53b8327d7e98bbf251d7", null).bind(null, encryptActionBoundArgs("406a88810ecce4a4e8b59d53b8327d7e98bbf251d7", [ var action = registerServerReference($$RSC_SERVER_ACTION_0, "406a88810ecce4a4e8b59d53b8327d7e98bbf251d7", null).bind(null, encryptActionBoundArgs("406a88810ecce4a4e8b59d53b8327d7e98bbf251d7", f2, f11, p, p1, p2, p3));
f2,
f11,
p,
p1,
p2,
p3
]));
return <Button action={action}>Delete</Button>; return <Button action={action}>Delete</Button>;
} }
...@@ -6,11 +6,7 @@ export const /*#__TURBOPACK_DISABLE_EXPORT_MERGING__*/ $$RSC_SERVER_ACTION_0 = a ...@@ -6,11 +6,7 @@ export const /*#__TURBOPACK_DISABLE_EXPORT_MERGING__*/ $$RSC_SERVER_ACTION_0 = a
await deleteFromDb($$ACTION_ARG_0.id, $$ACTION_ARG_0?.foo, $$ACTION_ARG_0.bar.baz, $$ACTION_ARG_0[$$ACTION_ARG_1, $$ACTION_ARG_2]); await deleteFromDb($$ACTION_ARG_0.id, $$ACTION_ARG_0?.foo, $$ACTION_ARG_0.bar.baz, $$ACTION_ARG_0[$$ACTION_ARG_1, $$ACTION_ARG_2]);
}; };
export function Item1(product, foo, bar) { export function Item1(product, foo, bar) {
const a = registerServerReference($$RSC_SERVER_ACTION_0, "406a88810ecce4a4e8b59d53b8327d7e98bbf251d7", null).bind(null, encryptActionBoundArgs("406a88810ecce4a4e8b59d53b8327d7e98bbf251d7", [ const a = registerServerReference($$RSC_SERVER_ACTION_0, "406a88810ecce4a4e8b59d53b8327d7e98bbf251d7", null).bind(null, encryptActionBoundArgs("406a88810ecce4a4e8b59d53b8327d7e98bbf251d7", product, foo, bar));
product,
foo,
bar
]));
return <Button action={a}>Delete</Button>; return <Button action={a}>Delete</Button>;
} }
export const /*#__TURBOPACK_DISABLE_EXPORT_MERGING__*/ $$RSC_SERVER_ACTION_1 = async function deleteItem2($$ACTION_CLOSURE_BOUND) { export const /*#__TURBOPACK_DISABLE_EXPORT_MERGING__*/ $$RSC_SERVER_ACTION_1 = async function deleteItem2($$ACTION_CLOSURE_BOUND) {
...@@ -18,11 +14,7 @@ export const /*#__TURBOPACK_DISABLE_EXPORT_MERGING__*/ $$RSC_SERVER_ACTION_1 = a ...@@ -18,11 +14,7 @@ export const /*#__TURBOPACK_DISABLE_EXPORT_MERGING__*/ $$RSC_SERVER_ACTION_1 = a
await deleteFromDb($$ACTION_ARG_0.id, $$ACTION_ARG_0?.foo, $$ACTION_ARG_0.bar.baz, $$ACTION_ARG_0[$$ACTION_ARG_1, $$ACTION_ARG_2]); await deleteFromDb($$ACTION_ARG_0.id, $$ACTION_ARG_0?.foo, $$ACTION_ARG_0.bar.baz, $$ACTION_ARG_0[$$ACTION_ARG_1, $$ACTION_ARG_2]);
}; };
export function Item2(product, foo, bar) { export function Item2(product, foo, bar) {
var deleteItem2 = registerServerReference($$RSC_SERVER_ACTION_1, "4090b5db271335765a4b0eab01f044b381b5ebd5cd", null).bind(null, encryptActionBoundArgs("4090b5db271335765a4b0eab01f044b381b5ebd5cd", [ var deleteItem2 = registerServerReference($$RSC_SERVER_ACTION_1, "4090b5db271335765a4b0eab01f044b381b5ebd5cd", null).bind(null, encryptActionBoundArgs("4090b5db271335765a4b0eab01f044b381b5ebd5cd", product, foo, bar));
product,
foo,
bar
]));
return <Button action={deleteItem2}>Delete</Button>; return <Button action={deleteItem2}>Delete</Button>;
} }
export const /*#__TURBOPACK_DISABLE_EXPORT_MERGING__*/ $$RSC_SERVER_ACTION_2 = async function deleteItem3($$ACTION_CLOSURE_BOUND) { export const /*#__TURBOPACK_DISABLE_EXPORT_MERGING__*/ $$RSC_SERVER_ACTION_2 = async function deleteItem3($$ACTION_CLOSURE_BOUND) {
...@@ -30,11 +22,7 @@ export const /*#__TURBOPACK_DISABLE_EXPORT_MERGING__*/ $$RSC_SERVER_ACTION_2 = a ...@@ -30,11 +22,7 @@ export const /*#__TURBOPACK_DISABLE_EXPORT_MERGING__*/ $$RSC_SERVER_ACTION_2 = a
await deleteFromDb($$ACTION_ARG_0.id, $$ACTION_ARG_0?.foo, $$ACTION_ARG_0.bar.baz, $$ACTION_ARG_0[$$ACTION_ARG_1, $$ACTION_ARG_2]); await deleteFromDb($$ACTION_ARG_0.id, $$ACTION_ARG_0?.foo, $$ACTION_ARG_0.bar.baz, $$ACTION_ARG_0[$$ACTION_ARG_1, $$ACTION_ARG_2]);
}; };
export function Item3(product, foo, bar) { export function Item3(product, foo, bar) {
const deleteItem3 = registerServerReference($$RSC_SERVER_ACTION_2, "401c36b06e398c97abe5d5d7ae8c672bfddf4e1b91", null).bind(null, encryptActionBoundArgs("401c36b06e398c97abe5d5d7ae8c672bfddf4e1b91", [ const deleteItem3 = registerServerReference($$RSC_SERVER_ACTION_2, "401c36b06e398c97abe5d5d7ae8c672bfddf4e1b91", null).bind(null, encryptActionBoundArgs("401c36b06e398c97abe5d5d7ae8c672bfddf4e1b91", product, foo, bar));
product,
foo,
bar
]));
return <Button action={deleteItem3}>Delete</Button>; return <Button action={deleteItem3}>Delete</Button>;
} }
export const /*#__TURBOPACK_DISABLE_EXPORT_MERGING__*/ $$RSC_SERVER_ACTION_3 = async function deleteItem4($$ACTION_CLOSURE_BOUND) { export const /*#__TURBOPACK_DISABLE_EXPORT_MERGING__*/ $$RSC_SERVER_ACTION_3 = async function deleteItem4($$ACTION_CLOSURE_BOUND) {
...@@ -42,10 +30,6 @@ export const /*#__TURBOPACK_DISABLE_EXPORT_MERGING__*/ $$RSC_SERVER_ACTION_3 = a ...@@ -42,10 +30,6 @@ export const /*#__TURBOPACK_DISABLE_EXPORT_MERGING__*/ $$RSC_SERVER_ACTION_3 = a
await deleteFromDb($$ACTION_ARG_0.id, $$ACTION_ARG_0?.foo, $$ACTION_ARG_0.bar.baz, $$ACTION_ARG_0[$$ACTION_ARG_1, $$ACTION_ARG_2]); await deleteFromDb($$ACTION_ARG_0.id, $$ACTION_ARG_0?.foo, $$ACTION_ARG_0.bar.baz, $$ACTION_ARG_0[$$ACTION_ARG_1, $$ACTION_ARG_2]);
}; };
export function Item4(product, foo, bar) { export function Item4(product, foo, bar) {
const deleteItem4 = registerServerReference($$RSC_SERVER_ACTION_3, "409ed0cc47abc4e1c64320cf42b74ae60b58c40f00", null).bind(null, encryptActionBoundArgs("409ed0cc47abc4e1c64320cf42b74ae60b58c40f00", [ const deleteItem4 = registerServerReference($$RSC_SERVER_ACTION_3, "409ed0cc47abc4e1c64320cf42b74ae60b58c40f00", null).bind(null, encryptActionBoundArgs("409ed0cc47abc4e1c64320cf42b74ae60b58c40f00", product, foo, bar));
product,
foo,
bar
]));
return <Button action={deleteItem4}>Delete</Button>; return <Button action={deleteItem4}>Delete</Button>;
} }
...@@ -22,6 +22,7 @@ import { ...@@ -22,6 +22,7 @@ import {
workUnitAsyncStorage, workUnitAsyncStorage,
} from './work-unit-async-storage.external' } from './work-unit-async-storage.external'
import { createHangingInputAbortSignal } from './dynamic-rendering' import { createHangingInputAbortSignal } from './dynamic-rendering'
import React from 'react'
const isEdgeRuntime = process.env.NEXT_RUNTIME === 'edge' const isEdgeRuntime = process.env.NEXT_RUNTIME === 'edge'
...@@ -81,90 +82,95 @@ async function encodeActionBoundArg(actionId: string, arg: string) { ...@@ -81,90 +82,95 @@ async function encodeActionBoundArg(actionId: string, arg: string) {
return btoa(ivValue + arrayBufferToString(encrypted)) return btoa(ivValue + arrayBufferToString(encrypted))
} }
// Encrypts the action's bound args into a string. // Encrypts the action's bound args into a string. For the same combination of
export async function encryptActionBoundArgs(actionId: string, args: any[]) { // actionId and args the same cached promise is returned. This ensures reference
const { clientModules } = getClientReferenceManifestForRsc() // equality for returned objects from "use cache" functions when they're invoked
// multiple times within one render pass using the same bound args.
export const encryptActionBoundArgs = React.cache(
async function encryptActionBoundArgs(actionId: string, ...args: any[]) {
const { clientModules } = getClientReferenceManifestForRsc()
// Create an error before any asynchronous calls, to capture the original
// call stack in case we need it when the serialization errors.
const error = new Error()
Error.captureStackTrace(error, encryptActionBoundArgs)
let didCatchError = false
const workUnitStore = workUnitAsyncStorage.getStore()
const hangingInputAbortSignal =
workUnitStore?.type === 'prerender'
? createHangingInputAbortSignal(workUnitStore)
: undefined
// Using Flight to serialize the args into a string.
const serialized = await streamToString(
renderToReadableStream(args, clientModules, {
signal: hangingInputAbortSignal,
onError(err) {
if (hangingInputAbortSignal?.aborted) {
return
}
// Create an error before any asynchronous calls, to capture the original // We're only reporting one error at a time, starting with the first.
// call stack in case we need it when the serialization errors. if (didCatchError) {
const error = new Error() return
Error.captureStackTrace(error, encryptActionBoundArgs) }
let didCatchError = false didCatchError = true
// Use the original error message together with the previously created
// stack, because err.stack is a useless Flight Server call stack.
error.message = err instanceof Error ? err.message : String(err)
},
}),
// We pass the abort signal to `streamToString` so that no chunks are
// included that are emitted after the signal was already aborted. This
// ensures that we can encode hanging promises.
hangingInputAbortSignal
)
const workUnitStore = workUnitAsyncStorage.getStore() if (didCatchError) {
if (process.env.NODE_ENV === 'development') {
// Logging the error is needed for server functions that are passed to the
// client where the decryption is not done during rendering. Console
// replaying allows us to still show the error dev overlay in this case.
console.error(error)
}
const hangingInputAbortSignal = throw error
workUnitStore?.type === 'prerender' }
? createHangingInputAbortSignal(workUnitStore)
: undefined
// Using Flight to serialize the args into a string.
const serialized = await streamToString(
renderToReadableStream(args, clientModules, {
signal: hangingInputAbortSignal,
onError(err) {
if (hangingInputAbortSignal?.aborted) {
return
}
// We're only reporting one error at a time, starting with the first. if (!workUnitStore) {
if (didCatchError) { return encodeActionBoundArg(actionId, serialized)
return }
}
didCatchError = true const prerenderResumeDataCache = getPrerenderResumeDataCache(workUnitStore)
const renderResumeDataCache = getRenderResumeDataCache(workUnitStore)
const cacheKey = actionId + serialized
// Use the original error message together with the previously created const cachedEncrypted =
// stack, because err.stack is a useless Flight Server call stack. prerenderResumeDataCache?.encryptedBoundArgs.get(cacheKey) ??
error.message = err instanceof Error ? err.message : String(err) renderResumeDataCache?.encryptedBoundArgs.get(cacheKey)
},
}),
// We pass the abort signal to `streamToString` so that no chunks are
// included that are emitted after the signal was already aborted. This
// ensures that we can encode hanging promises.
hangingInputAbortSignal
)
if (didCatchError) { if (cachedEncrypted) {
if (process.env.NODE_ENV === 'development') { return cachedEncrypted
// Logging the error is needed for server functions that are passed to the
// client where the decryption is not done during rendering. Console
// replaying allows us to still show the error dev overlay in this case.
console.error(error)
} }
throw error const cacheSignal =
} workUnitStore.type === 'prerender' ? workUnitStore.cacheSignal : undefined
if (!workUnitStore) { cacheSignal?.beginRead()
return encodeActionBoundArg(actionId, serialized)
}
const prerenderResumeDataCache = getPrerenderResumeDataCache(workUnitStore) const encrypted = await encodeActionBoundArg(actionId, serialized)
const renderResumeDataCache = getRenderResumeDataCache(workUnitStore)
const cacheKey = actionId + serialized
const cachedEncrypted = cacheSignal?.endRead()
prerenderResumeDataCache?.encryptedBoundArgs.get(cacheKey) ?? prerenderResumeDataCache?.encryptedBoundArgs.set(cacheKey, encrypted)
renderResumeDataCache?.encryptedBoundArgs.get(cacheKey)
if (cachedEncrypted) { return encrypted
return cachedEncrypted
} }
)
const cacheSignal =
workUnitStore.type === 'prerender' ? workUnitStore.cacheSignal : undefined
cacheSignal?.beginRead()
const encrypted = await encodeActionBoundArg(actionId, serialized)
cacheSignal?.endRead()
prerenderResumeDataCache?.encryptedBoundArgs.set(cacheKey, encrypted)
return encrypted
}
// Decrypts the action's bound args from the encrypted string. // Decrypts the action's bound args from the encrypted string.
export async function decryptActionBoundArgs( export async function decryptActionBoundArgs(
......
...@@ -48,6 +48,7 @@ import { ...@@ -48,6 +48,7 @@ import {
type SearchParams, type SearchParams,
} from '../request/search-params' } from '../request/search-params'
import type { Params } from '../request/params' import type { Params } from '../request/params'
import React from 'react'
type CacheKeyParts = [ type CacheKeyParts = [
buildId: string, buildId: string,
...@@ -861,7 +862,8 @@ export function cache( ...@@ -861,7 +862,8 @@ export function cache(
}) })
}, },
}[name] }[name]
return cachedFn
return React.cache(cachedFn)
} }
/** /**
......
/* eslint-disable no-self-compare */
async function getObject(arg: unknown) {
'use cache'
return { arg }
}
async function getObjectWithBoundArgs(arg: unknown) {
async function getCachedObject() {
'use cache'
return { arg }
}
return getCachedObject()
}
export default async function Page() {
return (
<>
<h2>With normal args</h2>
<p>
Two <span style={{ whiteSpace: 'pre' }}>"use cache"</span> invocations
with the same arg return the same result:{' '}
<strong id="same-arg">
{String((await getObject(1)) === (await getObject(1)))}
</strong>
</p>
<p>
Two <span style={{ whiteSpace: 'pre' }}>"use cache"</span> invocations
with different args return different results:{' '}
<strong id="different-args">
{String((await getObject(1)) !== (await getObject(2)))}
</strong>
</p>
<h2>With bound args</h2>
<p>
Two <span style={{ whiteSpace: 'pre' }}>"use cache"</span> invocations
with the same bound arg return the same result:{' '}
<strong id="same-bound-arg">
{String(
(await getObjectWithBoundArgs(1)) ===
(await getObjectWithBoundArgs(1))
)}
</strong>
</p>
<p>
Two <span style={{ whiteSpace: 'pre' }}>"use cache"</span> invocations
with different bound args return different results:{' '}
<strong id="different-bound-args">
{String(
(await getObjectWithBoundArgs(1)) !==
(await getObjectWithBoundArgs(2))
)}
</strong>
</p>
</>
)
}
'use client'
export function ClientComponent({ children, data }) {
console.log(data)
return children
}
import { ClientComponent } from './client'
async function getLargeObject() {
'use cache'
return { hello: 'world' }
}
export default async function Page() {
return (
<>
<ClientComponent data={await getLargeObject()}>
<p>foo</p>
</ClientComponent>
<ClientComponent data={await getLargeObject()}>
<p>bar</p>
</ClientComponent>
</>
)
}
...@@ -99,6 +99,29 @@ describe('use-cache', () => { ...@@ -99,6 +99,29 @@ describe('use-cache', () => {
expect(a).toBe(b) expect(a).toBe(b)
}) })
it('should return the same object reference for multiple invocations', async () => {
const browser = await next.browser('/referential-equality')
expect(await browser.elementById('same-arg').text()).toBe('true')
expect(await browser.elementById('different-args').text()).toBe('true')
expect(await browser.elementById('same-bound-arg').text()).toBe('true')
expect(await browser.elementById('different-bound-args').text()).toBe(
'true'
)
})
it('should dedupe cached data in the RSC payload', async () => {
const text = await next
.fetch('/rsc-payload')
.then((response) => response.text())
// The cached data is passed to two client components, but should appear
// only once in the RSC payload that's included in the HTML document.
expect(text).toIncludeRepeated(
'{\\\\"data\\\\":{\\\\"hello\\\\":\\\\"world\\\\"}',
1
)
})
it('should error when cookies/headers/draftMode is used inside "use cache"', async () => { it('should error when cookies/headers/draftMode is used inside "use cache"', async () => {
const browser = await next.browser('/errors') const browser = await next.browser('/errors')
...@@ -311,6 +334,8 @@ describe('use-cache', () => { ...@@ -311,6 +334,8 @@ describe('use-cache', () => {
'/not-found', '/not-found',
'/passed-to-client', '/passed-to-client',
'/react-cache', '/react-cache',
'/referential-equality',
'/rsc-payload',
'/static-class-method', '/static-class-method',
'/use-action-state', '/use-action-state',
'/with-server-action', '/with-server-action',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment