Commit 822dcc7d authored by Hendrik Liebau's avatar Hendrik Liebau Committed by Jiachi Liu

Hoist inner `'use cache'` functions to reduce function allocations (#85904)

This PR fixes a slight performance regression introduced in #85519 where
inline async function expressions were created for each unique set of
arguments passed to a `'use cache'` function.

For a function like this:

```js
export async function getCachedData(id) {
  'use cache';
  return fetch(`/api/data/${id}`);
}
```

we were previously generating (simplified):

```js
export var $$RSC_SERVER_CACHE_0 = cache("default", "0815", 0, async function(id) {
  return fetch(`/api/data/${id}`);
});
```

In #85519, we restructured this to ensure proper stack frames in error
messages (simplified):

```js
export var $$RSC_SERVER_CACHE_0 = React.cache(function getCachedData() {
  return cache("default", "0815", 0, async function(id) {
    return fetch(`/api/data/${id}`);
  }, arguments);
});
```

However, this introduced a small performance issue: the inner async
function expression was passed inline to the cache wrapper. While
`React.cache` memoizes the outer function, each unique set of arguments
would cause a new inner function object to be allocated.

Now we're generating (simplified):

```js
const $$RSC_SERVER_CACHE_0_INNER = async function getCachedData(id) {
  return fetch(`/api/data/${id}`);
};

export var $$RSC_SERVER_CACHE_0 = React.cache(function getCachedData() {
  return cache("default", "0815", 0, $$RSC_SERVER_CACHE_0_INNER, arguments);
});
```

The cache implementation is now hoisted to module scope with an `_INNER`
suffix as a const declaration with a named function expression. The
function name is preserved to ensure proper stack traces in dev. This
eliminates the repeated function allocations while preserving the
improvements from #85519.
parent 499f5e19
......@@ -3,8 +3,7 @@ import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc
export default $$RSC_SERVER_ACTION_0 = ()=>{};
var $$RSC_SERVER_ACTION_0;
Object["defineProperty"]($$RSC_SERVER_ACTION_0, "name", {
value: "default",
writable: false
value: "default"
});
import { ensureServerEntryExports } from "private-next-rsc-action-validate";
ensureServerEntryExports([
......
......@@ -4,14 +4,14 @@ import { cache as $$cache__ } from "private-next-rsc-cache-wrapper";
import { cache as $$reactCache__ } from "react";
import React from 'react';
import inter from '@next/font/google/target.css?{"path":"app/test.tsx","import":"Inter","arguments":[],"variableName":"inter"}';
const $$RSC_SERVER_CACHE_0_INNER = async function Cached({ children }) {
return <div className={inter.className}>{children}</div>;
};
export var $$RSC_SERVER_CACHE_0 = $$reactCache__(function Cached() {
return $$cache__("default", "c0dd5bb6fef67f5ab84327f5164ac2c3111a159337", 0, async function Cached({ children }) {
return <div className={inter.className}>{children}</div>;
}, arguments);
return $$cache__("default", "c0dd5bb6fef67f5ab84327f5164ac2c3111a159337", 0, $$RSC_SERVER_CACHE_0_INNER, arguments);
});
registerServerReference($$RSC_SERVER_CACHE_0, "c0dd5bb6fef67f5ab84327f5164ac2c3111a159337", null);
Object["defineProperty"]($$RSC_SERVER_CACHE_0, "name", {
value: "Cached",
writable: false
value: "Cached"
});
export var Cached = $$RSC_SERVER_CACHE_0;
......@@ -2,8 +2,7 @@
import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption";
export default async function $$RSC_SERVER_ACTION_0() {}
Object["defineProperty"]($$RSC_SERVER_ACTION_0, "name", {
value: "default",
writable: false
value: "default"
});
import { ensureServerEntryExports } from "private-next-rsc-action-validate";
ensureServerEntryExports([
......
......@@ -5,8 +5,7 @@ export default $$RSC_SERVER_ACTION_0 = async (a, b)=>{
};
var $$RSC_SERVER_ACTION_0;
Object["defineProperty"]($$RSC_SERVER_ACTION_0, "name", {
value: "default",
writable: false
value: "default"
});
import { ensureServerEntryExports } from "private-next-rsc-action-validate";
ensureServerEntryExports([
......
......@@ -5,8 +5,7 @@ export const action = validator(async ()=>{});
export default $$RSC_SERVER_ACTION_0 = validator(async ()=>{});
var $$RSC_SERVER_ACTION_0;
Object["defineProperty"]($$RSC_SERVER_ACTION_0, "name", {
value: "default",
writable: false
value: "default"
});
import { ensureServerEntryExports } from "private-next-rsc-action-validate";
ensureServerEntryExports([
......
......@@ -3,15 +3,15 @@ import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc
import { cache as $$cache__ } from "private-next-rsc-cache-wrapper";
import { cache as $$reactCache__ } from "react";
const v = 'world';
const $$RSC_SERVER_CACHE_0_INNER = async function fn() {
return 'hello, ' + v;
};
export var $$RSC_SERVER_CACHE_0 = $$reactCache__(function fn() {
return $$cache__("default", "803128060c414d59f8552e4788b846c0d2b7f74743", 0, async function fn() {
return 'hello, ' + v;
}, arguments);
return $$cache__("default", "803128060c414d59f8552e4788b846c0d2b7f74743", 0, $$RSC_SERVER_CACHE_0_INNER, arguments);
});
registerServerReference($$RSC_SERVER_CACHE_0, "803128060c414d59f8552e4788b846c0d2b7f74743", null);
Object["defineProperty"]($$RSC_SERVER_CACHE_0, "name", {
value: "fn",
writable: false
value: "fn"
});
var fn = $$RSC_SERVER_CACHE_0;
export async function Component() {
......
......@@ -2,53 +2,53 @@
import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption";
import { cache as $$cache__ } from "private-next-rsc-cache-wrapper";
import { cache as $$reactCache__ } from "react";
const $$RSC_SERVER_CACHE_0_INNER = async function foo() {
return 'foo';
};
export var $$RSC_SERVER_CACHE_0 = $$reactCache__(function foo() {
return $$cache__("default", "803128060c414d59f8552e4788b846c0d2b7f74743", 0, async function() {
return 'foo';
}, arguments);
return $$cache__("default", "803128060c414d59f8552e4788b846c0d2b7f74743", 0, $$RSC_SERVER_CACHE_0_INNER, arguments);
});
registerServerReference($$RSC_SERVER_CACHE_0, "803128060c414d59f8552e4788b846c0d2b7f74743", null);
Object["defineProperty"]($$RSC_SERVER_CACHE_0, "name", {
value: "foo",
writable: false
value: "foo"
});
const foo = $$RSC_SERVER_CACHE_0;
export { bar };
const $$RSC_SERVER_CACHE_1_INNER = async function bar() {
return 'bar';
};
export var $$RSC_SERVER_CACHE_1 = $$reactCache__(function bar() {
return $$cache__("default", "80951c375b4a6a6e89d67b743ec5808127cfde405d", 0, async function bar() {
return 'bar';
}, arguments);
return $$cache__("default", "80951c375b4a6a6e89d67b743ec5808127cfde405d", 0, $$RSC_SERVER_CACHE_1_INNER, arguments);
});
registerServerReference($$RSC_SERVER_CACHE_1, "80951c375b4a6a6e89d67b743ec5808127cfde405d", null);
Object["defineProperty"]($$RSC_SERVER_CACHE_1, "name", {
value: "bar",
writable: false
value: "bar"
});
var bar = $$RSC_SERVER_CACHE_1;
// Should not be wrapped in $$cache__.
const qux = async function qux() {
return 'qux';
};
const $$RSC_SERVER_CACHE_2_INNER = async function baz() {
return qux() + 'baz';
};
export var $$RSC_SERVER_CACHE_2 = $$reactCache__(function baz() {
return $$cache__("default", "8069348c79fce073bae2f70f139565a2fda1c74c74", 0, async function baz() {
return qux() + 'baz';
}, arguments);
return $$cache__("default", "8069348c79fce073bae2f70f139565a2fda1c74c74", 0, $$RSC_SERVER_CACHE_2_INNER, arguments);
});
registerServerReference($$RSC_SERVER_CACHE_2, "8069348c79fce073bae2f70f139565a2fda1c74c74", null);
Object["defineProperty"]($$RSC_SERVER_CACHE_2, "name", {
value: "baz",
writable: false
value: "baz"
});
const baz = $$RSC_SERVER_CACHE_2;
const $$RSC_SERVER_CACHE_3_INNER = async function quux() {
return 'quux';
};
export var $$RSC_SERVER_CACHE_3 = $$reactCache__(function quux() {
return $$cache__("default", "8012a8d21b6362b4cc8f5b15560525095bc48dba80", 0, async function() {
return 'quux';
}, arguments);
return $$cache__("default", "8012a8d21b6362b4cc8f5b15560525095bc48dba80", 0, $$RSC_SERVER_CACHE_3_INNER, arguments);
});
registerServerReference($$RSC_SERVER_CACHE_3, "8012a8d21b6362b4cc8f5b15560525095bc48dba80", null);
Object["defineProperty"]($$RSC_SERVER_CACHE_3, "name", {
value: "quux",
writable: false
value: "quux"
});
const quux = $$RSC_SERVER_CACHE_3;
export { foo, baz };
......
......@@ -2,14 +2,14 @@
import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption";
import { cache as $$cache__ } from "private-next-rsc-cache-wrapper";
import { cache as $$reactCache__ } from "react";
const $$RSC_SERVER_CACHE_0_INNER = async function my_fn() {
return 'data';
};
export var $$RSC_SERVER_CACHE_0 = $$reactCache__(function my_fn() {
return $$cache__("default", "803128060c414d59f8552e4788b846c0d2b7f74743", 0, async function() {
return 'data';
}, arguments);
return $$cache__("default", "803128060c414d59f8552e4788b846c0d2b7f74743", 0, $$RSC_SERVER_CACHE_0_INNER, arguments);
});
registerServerReference($$RSC_SERVER_CACHE_0, "803128060c414d59f8552e4788b846c0d2b7f74743", null);
Object["defineProperty"]($$RSC_SERVER_CACHE_0, "name", {
value: "my_fn",
writable: false
value: "my_fn"
});
export const my_fn = $$RSC_SERVER_CACHE_0;
......@@ -2,47 +2,47 @@
import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption";
import { cache as $$cache__ } from "private-next-rsc-cache-wrapper";
import { cache as $$reactCache__ } from "react";
const $$RSC_SERVER_CACHE_0_INNER = async function foo() {
return 'data A';
};
export var $$RSC_SERVER_CACHE_0 = $$reactCache__(function foo() {
return $$cache__("default", "803128060c414d59f8552e4788b846c0d2b7f74743", 0, async function foo() {
return 'data A';
}, arguments);
return $$cache__("default", "803128060c414d59f8552e4788b846c0d2b7f74743", 0, $$RSC_SERVER_CACHE_0_INNER, arguments);
});
registerServerReference($$RSC_SERVER_CACHE_0, "803128060c414d59f8552e4788b846c0d2b7f74743", null);
Object["defineProperty"]($$RSC_SERVER_CACHE_0, "name", {
value: "foo",
writable: false
value: "foo"
});
export var foo = $$RSC_SERVER_CACHE_0;
const $$RSC_SERVER_CACHE_1_INNER = async function bar() {
return 'data B';
};
export var $$RSC_SERVER_CACHE_1 = $$reactCache__(function bar() {
return $$cache__("default", "80951c375b4a6a6e89d67b743ec5808127cfde405d", 0, async function bar() {
return 'data B';
}, arguments);
return $$cache__("default", "80951c375b4a6a6e89d67b743ec5808127cfde405d", 0, $$RSC_SERVER_CACHE_1_INNER, arguments);
});
registerServerReference($$RSC_SERVER_CACHE_1, "80951c375b4a6a6e89d67b743ec5808127cfde405d", null);
Object["defineProperty"]($$RSC_SERVER_CACHE_1, "name", {
value: "bar",
writable: false
value: "bar"
});
export var bar = $$RSC_SERVER_CACHE_1;
const $$RSC_SERVER_CACHE_2_INNER = async function Cached({ children }) {
return children;
};
export var $$RSC_SERVER_CACHE_2 = $$reactCache__(function Cached() {
return $$cache__("default", "c069348c79fce073bae2f70f139565a2fda1c74c74", 0, async function Cached({ children }) {
return children;
}, arguments);
return $$cache__("default", "c069348c79fce073bae2f70f139565a2fda1c74c74", 0, $$RSC_SERVER_CACHE_2_INNER, arguments);
});
registerServerReference($$RSC_SERVER_CACHE_2, "c069348c79fce073bae2f70f139565a2fda1c74c74", null);
Object["defineProperty"]($$RSC_SERVER_CACHE_2, "name", {
value: "Cached",
writable: false
value: "Cached"
});
export default $$RSC_SERVER_CACHE_2;
const $$RSC_SERVER_CACHE_3_INNER = async function baz() {
return 'data C';
};
export var $$RSC_SERVER_CACHE_3 = $$reactCache__(function baz() {
return $$cache__("default", "8012a8d21b6362b4cc8f5b15560525095bc48dba80", 0, async function baz() {
return 'data C';
}, arguments);
return $$cache__("default", "8012a8d21b6362b4cc8f5b15560525095bc48dba80", 0, $$RSC_SERVER_CACHE_3_INNER, arguments);
});
registerServerReference($$RSC_SERVER_CACHE_3, "8012a8d21b6362b4cc8f5b15560525095bc48dba80", null);
Object["defineProperty"]($$RSC_SERVER_CACHE_3, "name", {
value: "baz",
writable: false
value: "baz"
});
export const baz = $$RSC_SERVER_CACHE_3;
......@@ -2,15 +2,15 @@
import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption";
import { cache as $$cache__ } from "private-next-rsc-cache-wrapper";
import { cache as $$reactCache__ } from "react";
const $$RSC_SERVER_CACHE_0_INNER = async function fn() {
return 'foo';
};
export var $$RSC_SERVER_CACHE_0 = $$reactCache__(function fn() {
return $$cache__("default", "803128060c414d59f8552e4788b846c0d2b7f74743", 0, async function fn() {
return 'foo';
}, arguments);
return $$cache__("default", "803128060c414d59f8552e4788b846c0d2b7f74743", 0, $$RSC_SERVER_CACHE_0_INNER, arguments);
});
registerServerReference($$RSC_SERVER_CACHE_0, "803128060c414d59f8552e4788b846c0d2b7f74743", null);
Object["defineProperty"]($$RSC_SERVER_CACHE_0, "name", {
value: "fn",
writable: false
value: "fn"
});
var fn = $$RSC_SERVER_CACHE_0;
async function Component() {
......
......@@ -2,14 +2,14 @@
import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption";
import { cache as $$cache__ } from "private-next-rsc-cache-wrapper";
import { cache as $$reactCache__ } from "react";
const $$RSC_SERVER_CACHE_0_INNER = async function foo() {
return 'data';
};
export var $$RSC_SERVER_CACHE_0 = $$reactCache__(function foo() {
return $$cache__("x", "803128060c414d59f8552e4788b846c0d2b7f74743", 0, async function foo() {
return 'data';
}, arguments);
return $$cache__("x", "803128060c414d59f8552e4788b846c0d2b7f74743", 0, $$RSC_SERVER_CACHE_0_INNER, arguments);
});
registerServerReference($$RSC_SERVER_CACHE_0, "803128060c414d59f8552e4788b846c0d2b7f74743", null);
Object["defineProperty"]($$RSC_SERVER_CACHE_0, "name", {
value: "foo",
writable: false
value: "foo"
});
export var foo = $$RSC_SERVER_CACHE_0;
......@@ -2,18 +2,18 @@
import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption";
import { cache as $$cache__ } from "private-next-rsc-cache-wrapper";
import { cache as $$reactCache__ } from "react";
const $$RSC_SERVER_CACHE_0_INNER = async function fn([$$ACTION_ARG_0, $$ACTION_ARG_1]) {
console.log($$ACTION_ARG_0);
return {
foo: $$ACTION_ARG_1
};
};
export var $$RSC_SERVER_CACHE_0 = $$reactCache__(function fn() {
return $$cache__("default", "c03128060c414d59f8552e4788b846c0d2b7f74743", 2, async function fn([$$ACTION_ARG_0, $$ACTION_ARG_1]) {
console.log($$ACTION_ARG_0);
return {
foo: $$ACTION_ARG_1
};
}, arguments);
return $$cache__("default", "c03128060c414d59f8552e4788b846c0d2b7f74743", 2, $$RSC_SERVER_CACHE_0_INNER, arguments);
});
registerServerReference($$RSC_SERVER_CACHE_0, "c03128060c414d59f8552e4788b846c0d2b7f74743", null);
Object["defineProperty"]($$RSC_SERVER_CACHE_0, "name", {
value: "fn",
writable: false
value: "fn"
});
async function Component({ foo }) {
const a = 123;
......
......@@ -3,21 +3,21 @@ import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc
import { cache as $$cache__ } from "private-next-rsc-cache-wrapper";
import { cache as $$reactCache__ } from "react";
import { Form } from 'components';
const $$RSC_SERVER_CACHE_0_INNER = async function cache([$$ACTION_ARG_0, $$ACTION_ARG_1], e) {
const f = $$ACTION_ARG_0 + e;
return [
f,
{
a: $$ACTION_ARG_1
}
];
};
export var $$RSC_SERVER_CACHE_0 = $$reactCache__(function cache() {
return $$cache__("default", "e03128060c414d59f8552e4788b846c0d2b7f74743", 2, async function cache([$$ACTION_ARG_0, $$ACTION_ARG_1], e) {
const f = $$ACTION_ARG_0 + e;
return [
f,
{
a: $$ACTION_ARG_1
}
];
}, arguments);
return $$cache__("default", "e03128060c414d59f8552e4788b846c0d2b7f74743", 2, $$RSC_SERVER_CACHE_0_INNER, arguments);
});
registerServerReference($$RSC_SERVER_CACHE_0, "e03128060c414d59f8552e4788b846c0d2b7f74743", null);
Object["defineProperty"]($$RSC_SERVER_CACHE_0, "name", {
value: "cache",
writable: false
value: "cache"
});
export const $$RSC_SERVER_ACTION_1 = async function action($$ACTION_CLOSURE_BOUND, c) {
var [$$ACTION_ARG_0, $$ACTION_ARG_1] = await decryptActionBoundArgs("6090b5db271335765a4b0eab01f044b381b5ebd5cd", $$ACTION_CLOSURE_BOUND);
......
......@@ -10,18 +10,18 @@ export const $$RSC_SERVER_ACTION_0 = async function fn($$ACTION_CLOSURE_BOUND) {
};
};
registerServerReference($$RSC_SERVER_ACTION_0, "406a88810ecce4a4e8b59d53b8327d7e98bbf251d7", null);
const $$RSC_SERVER_CACHE_1_INNER = async function Component({ foo }) {
const a = 123;
var fn = $$RSC_SERVER_ACTION_0.bind(null, encryptActionBoundArgs("406a88810ecce4a4e8b59d53b8327d7e98bbf251d7", a, foo));
const data = await fn();
// @ts-expect-error: data is not a valid react child
return <div>{data}</div>;
};
export var $$RSC_SERVER_CACHE_1 = $$reactCache__(function Component() {
return $$cache__("default", "c0951c375b4a6a6e89d67b743ec5808127cfde405d", 0, async function Component({ foo }) {
const a = 123;
var fn = $$RSC_SERVER_ACTION_0.bind(null, encryptActionBoundArgs("406a88810ecce4a4e8b59d53b8327d7e98bbf251d7", a, foo));
const data = await fn();
// @ts-expect-error: data is not a valid react child
return <div>{data}</div>;
}, arguments);
return $$cache__("default", "c0951c375b4a6a6e89d67b743ec5808127cfde405d", 0, $$RSC_SERVER_CACHE_1_INNER, arguments);
});
registerServerReference($$RSC_SERVER_CACHE_1, "c0951c375b4a6a6e89d67b743ec5808127cfde405d", null);
Object["defineProperty"]($$RSC_SERVER_CACHE_1, "name", {
value: "Component",
writable: false
value: "Component"
});
export var Component = $$RSC_SERVER_CACHE_1;
......@@ -2,18 +2,18 @@
import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption";
import { cache as $$cache__ } from "private-next-rsc-cache-wrapper";
import { cache as $$reactCache__ } from "react";
const $$RSC_SERVER_CACHE_0_INNER = async function fn([$$ACTION_ARG_0, $$ACTION_ARG_1]) {
console.log($$ACTION_ARG_0);
return {
foo: $$ACTION_ARG_1
};
};
export var $$RSC_SERVER_CACHE_0 = $$reactCache__(function fn() {
return $$cache__("default", "c03128060c414d59f8552e4788b846c0d2b7f74743", 2, async function([$$ACTION_ARG_0, $$ACTION_ARG_1]) {
console.log($$ACTION_ARG_0);
return {
foo: $$ACTION_ARG_1
};
}, arguments);
return $$cache__("default", "c03128060c414d59f8552e4788b846c0d2b7f74743", 2, $$RSC_SERVER_CACHE_0_INNER, arguments);
});
registerServerReference($$RSC_SERVER_CACHE_0, "c03128060c414d59f8552e4788b846c0d2b7f74743", null);
Object["defineProperty"]($$RSC_SERVER_CACHE_0, "name", {
value: "fn",
writable: false
value: "fn"
});
async function Component({ foo }) {
const a = 123;
......
......@@ -9,19 +9,19 @@ export const $$RSC_SERVER_ACTION_0 = async function action($$ACTION_CLOSURE_BOUN
console.log(secret, $$ACTION_ARG_0);
};
registerServerReference($$RSC_SERVER_ACTION_0, "406a88810ecce4a4e8b59d53b8327d7e98bbf251d7", null);
const $$RSC_SERVER_CACHE_1_INNER = async function getCachedRandom(x, children) {
return {
x,
y: Math.random(),
z: <Button action={$$RSC_SERVER_ACTION_0.bind(null, encryptActionBoundArgs("406a88810ecce4a4e8b59d53b8327d7e98bbf251d7", x))}/>,
r: children
};
};
export var $$RSC_SERVER_CACHE_1 = $$reactCache__(function getCachedRandom() {
return $$cache__("default", "e0951c375b4a6a6e89d67b743ec5808127cfde405d", 0, async function getCachedRandom(x, children) {
return {
x,
y: Math.random(),
z: <Button action={$$RSC_SERVER_ACTION_0.bind(null, encryptActionBoundArgs("406a88810ecce4a4e8b59d53b8327d7e98bbf251d7", x))}/>,
r: children
};
}, arguments);
return $$cache__("default", "e0951c375b4a6a6e89d67b743ec5808127cfde405d", 0, $$RSC_SERVER_CACHE_1_INNER, arguments);
});
registerServerReference($$RSC_SERVER_CACHE_1, "e0951c375b4a6a6e89d67b743ec5808127cfde405d", null);
Object["defineProperty"]($$RSC_SERVER_CACHE_1, "name", {
value: "getCachedRandom",
writable: false
value: "getCachedRandom"
});
var getCachedRandom = $$RSC_SERVER_CACHE_1;
......@@ -8,14 +8,14 @@ function Foo() {
console.log(v);
return v;
}
const $$RSC_SERVER_CACHE_0_INNER = async function bar() {
return <Foo/>;
};
export var $$RSC_SERVER_CACHE_0 = $$reactCache__(function bar() {
return $$cache__("default", "803128060c414d59f8552e4788b846c0d2b7f74743", 0, async function bar() {
return <Foo/>;
}, arguments);
return $$cache__("default", "803128060c414d59f8552e4788b846c0d2b7f74743", 0, $$RSC_SERVER_CACHE_0_INNER, arguments);
});
registerServerReference($$RSC_SERVER_CACHE_0, "803128060c414d59f8552e4788b846c0d2b7f74743", null);
Object["defineProperty"]($$RSC_SERVER_CACHE_0, "name", {
value: "bar",
writable: false
value: "bar"
});
export var bar = $$RSC_SERVER_CACHE_0;
......@@ -4,18 +4,18 @@
import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption";
import { cache as $$cache__ } from "private-next-rsc-cache-wrapper";
import { cache as $$reactCache__ } from "react";
const $$RSC_SERVER_CACHE_0_INNER = async function f1(a, b) {
return [
a,
b
];
};
export var $$RSC_SERVER_CACHE_0 = $$reactCache__(function f1() {
return $$cache__("default", "e03128060c414d59f8552e4788b846c0d2b7f74743", 0, async function f1(a, b) {
return [
a,
b
];
}, arguments);
return $$cache__("default", "e03128060c414d59f8552e4788b846c0d2b7f74743", 0, $$RSC_SERVER_CACHE_0_INNER, arguments);
});
registerServerReference($$RSC_SERVER_CACHE_0, "e03128060c414d59f8552e4788b846c0d2b7f74743", null);
Object["defineProperty"]($$RSC_SERVER_CACHE_0, "name", {
value: "f1",
writable: false
value: "f1"
});
var f1 = $$RSC_SERVER_CACHE_0;
export const // Should be 0 110000 0, which is "60" in hex.
......@@ -27,20 +27,20 @@ $$RSC_SERVER_ACTION_1 = async function f2(a, b) {
};
registerServerReference($$RSC_SERVER_ACTION_1, "6090b5db271335765a4b0eab01f044b381b5ebd5cd", null);
var f2 = $$RSC_SERVER_ACTION_1;
export var // Should be 1 111111 1, which is "ff" in hex.
$$RSC_SERVER_CACHE_2 = $$reactCache__(function f3() {
return $$cache__("default", "ff69348c79fce073bae2f70f139565a2fda1c74c74", 0, async function f3(a, b, ...rest) {
return [
a,
b,
rest
];
}, arguments);
// Should be 1 111111 1, which is "ff" in hex.
const $$RSC_SERVER_CACHE_2_INNER = async function f3(a, b, ...rest) {
return [
a,
b,
rest
];
};
export var $$RSC_SERVER_CACHE_2 = $$reactCache__(function f3() {
return $$cache__("default", "ff69348c79fce073bae2f70f139565a2fda1c74c74", 0, $$RSC_SERVER_CACHE_2_INNER, arguments);
});
registerServerReference($$RSC_SERVER_CACHE_2, "ff69348c79fce073bae2f70f139565a2fda1c74c74", null);
Object["defineProperty"]($$RSC_SERVER_CACHE_2, "name", {
value: "f3",
writable: false
value: "f3"
});
var f3 = $$RSC_SERVER_CACHE_2;
export const // Should be 0 111110 0, which is "7c" in hex.
......@@ -68,23 +68,23 @@ $$RSC_SERVER_ACTION_4 = async function f5(a, b, c, d, e, f) {
};
registerServerReference($$RSC_SERVER_ACTION_4, "7ea9b2939c1f39073a6bed227fd20233064c8b7869", null);
var f5 = $$RSC_SERVER_ACTION_4;
export var // Should be 1 111111 1, which is "ff" in hex.
$$RSC_SERVER_CACHE_5 = $$reactCache__(function f6() {
return $$cache__("default", "ff471a5eb0be1c31686dd4ba938a80328b80b1615d", 0, async function f6(a, b, c, d, e, f, g) {
return [
a,
b,
c,
d,
e,
f,
g
];
}, arguments);
// Should be 1 111111 1, which is "ff" in hex.
const $$RSC_SERVER_CACHE_5_INNER = async function f6(a, b, c, d, e, f, g) {
return [
a,
b,
c,
d,
e,
f,
g
];
};
export var $$RSC_SERVER_CACHE_5 = $$reactCache__(function f6() {
return $$cache__("default", "ff471a5eb0be1c31686dd4ba938a80328b80b1615d", 0, $$RSC_SERVER_CACHE_5_INNER, arguments);
});
registerServerReference($$RSC_SERVER_CACHE_5, "ff471a5eb0be1c31686dd4ba938a80328b80b1615d", null);
Object["defineProperty"]($$RSC_SERVER_CACHE_5, "name", {
value: "f6",
writable: false
value: "f6"
});
var f6 = $$RSC_SERVER_CACHE_5;
......@@ -25,18 +25,18 @@ export async function action3(a, b) {
{b}
</div>;
}
export var $$RSC_SERVER_CACHE_0 = $$reactCache__(function cache() {
return $$cache__("default", "e03128060c414d59f8552e4788b846c0d2b7f74743", 0, async function cache(a, b) {
return <div>
const $$RSC_SERVER_CACHE_0_INNER = async function cache(a, b) {
return <div>
{a}
{b}
</div>;
}, arguments);
};
export var $$RSC_SERVER_CACHE_0 = $$reactCache__(function cache() {
return $$cache__("default", "e03128060c414d59f8552e4788b846c0d2b7f74743", 0, $$RSC_SERVER_CACHE_0_INNER, arguments);
});
registerServerReference($$RSC_SERVER_CACHE_0, "e03128060c414d59f8552e4788b846c0d2b7f74743", null);
Object["defineProperty"]($$RSC_SERVER_CACHE_0, "name", {
value: "cache",
writable: false
value: "cache"
});
// Should be 1 110000 0, which is "e0" in hex.
export var cache = $$RSC_SERVER_CACHE_0;
......
......@@ -2,14 +2,18 @@
import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption";
import { cache as $$cache__ } from "private-next-rsc-cache-wrapper";
import { cache as $$reactCache__ } from "react";
export var $$RSC_SERVER_CACHE_0 = $$reactCache__(function() {
return $$cache__("default", "f03128060c414d59f8552e4788b846c0d2b7f74743", 0, async function(a, b, c) {
return <div>
const $$RSC_SERVER_CACHE_0_INNER = async function(a, b, c) {
return <div>
{a}
{b}
{c}
</div>;
}, arguments);
};
Object["defineProperty"]($$RSC_SERVER_CACHE_0_INNER, "name", {
value: ""
});
export var $$RSC_SERVER_CACHE_0 = $$reactCache__(function() {
return $$cache__("default", "f03128060c414d59f8552e4788b846c0d2b7f74743", 0, $$RSC_SERVER_CACHE_0_INNER, arguments);
});
registerServerReference($$RSC_SERVER_CACHE_0, "f03128060c414d59f8552e4788b846c0d2b7f74743", null);
export default $$RSC_SERVER_CACHE_0;
......@@ -2,18 +2,21 @@
import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption";
import { cache as $$cache__ } from "private-next-rsc-cache-wrapper";
import { cache as $$reactCache__ } from "react";
export var $$RSC_SERVER_CACHE_0 = $$reactCache__(function() {
return $$cache__("default", "f03128060c414d59f8552e4788b846c0d2b7f74743", 0, async function(a, b, c) {
return <div>
const $$RSC_SERVER_CACHE_0_INNER = async function(a, b, c) {
return <div>
{a}
{b}
{c}
</div>;
}, arguments);
};
Object["defineProperty"]($$RSC_SERVER_CACHE_0_INNER, "name", {
value: ""
});
export var $$RSC_SERVER_CACHE_0 = $$reactCache__(function() {
return $$cache__("default", "f03128060c414d59f8552e4788b846c0d2b7f74743", 0, $$RSC_SERVER_CACHE_0_INNER, arguments);
});
registerServerReference($$RSC_SERVER_CACHE_0, "f03128060c414d59f8552e4788b846c0d2b7f74743", null);
Object["defineProperty"]($$RSC_SERVER_CACHE_0, "name", {
value: "default",
writable: false
value: "default"
});
export default $$RSC_SERVER_CACHE_0;
......@@ -10,8 +10,7 @@ export const $$RSC_SERVER_ACTION_1 = async function $$RSC_SERVER_ACTION_0(a, b,
registerServerReference($$RSC_SERVER_ACTION_1, "7090b5db271335765a4b0eab01f044b381b5ebd5cd", null);
export default $$RSC_SERVER_ACTION_1;
Object["defineProperty"]($$RSC_SERVER_ACTION_0, "name", {
value: "default",
writable: false
value: "default"
});
export const $$RSC_SERVER_ACTION_2 = async function foo(a, b) {
return <div>
......
......@@ -3,29 +3,29 @@ import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc
import { cache as $$cache__ } from "private-next-rsc-cache-wrapper";
import { cache as $$reactCache__ } from "react";
import { Client } from 'components';
export var $$RSC_SERVER_CACHE_0 = $$reactCache__(function // Should be 1 110000 0, which is "e0" in hex (counts as two params,
const $$RSC_SERVER_CACHE_0_INNER = async function // Should be 1 110000 0, which is "e0" in hex (counts as two params,
// because of the encrypted bound args param)
fn1() {
return $$cache__("default", "e03128060c414d59f8552e4788b846c0d2b7f74743", 2, async function([$$ACTION_ARG_0, $$ACTION_ARG_1], c) {
return $$ACTION_ARG_0 + $$ACTION_ARG_1 + c;
}, arguments);
fn1([$$ACTION_ARG_0, $$ACTION_ARG_1], c) {
return $$ACTION_ARG_0 + $$ACTION_ARG_1 + c;
};
export var $$RSC_SERVER_CACHE_0 = $$reactCache__(function fn1() {
return $$cache__("default", "e03128060c414d59f8552e4788b846c0d2b7f74743", 2, $$RSC_SERVER_CACHE_0_INNER, arguments);
});
registerServerReference($$RSC_SERVER_CACHE_0, "e03128060c414d59f8552e4788b846c0d2b7f74743", null);
Object["defineProperty"]($$RSC_SERVER_CACHE_0, "name", {
value: "fn1",
writable: false
value: "fn1"
});
export var $$RSC_SERVER_CACHE_1 = $$reactCache__(function // Should be 1 100000 0, which is "c0" in hex (counts as one param,
const $$RSC_SERVER_CACHE_1_INNER = async function // Should be 1 100000 0, which is "c0" in hex (counts as one param,
// because of the encrypted bound args param)
fn2() {
return $$cache__("default", "c0951c375b4a6a6e89d67b743ec5808127cfde405d", 2, async function fn2([$$ACTION_ARG_0, $$ACTION_ARG_1]) {
return $$ACTION_ARG_0 + $$ACTION_ARG_1;
}, arguments);
fn2([$$ACTION_ARG_0, $$ACTION_ARG_1]) {
return $$ACTION_ARG_0 + $$ACTION_ARG_1;
};
export var $$RSC_SERVER_CACHE_1 = $$reactCache__(function fn2() {
return $$cache__("default", "c0951c375b4a6a6e89d67b743ec5808127cfde405d", 2, $$RSC_SERVER_CACHE_1_INNER, arguments);
});
registerServerReference($$RSC_SERVER_CACHE_1, "c0951c375b4a6a6e89d67b743ec5808127cfde405d", null);
Object["defineProperty"]($$RSC_SERVER_CACHE_1, "name", {
value: "fn2",
writable: false
value: "fn2"
});
export const $$RSC_SERVER_ACTION_2 = async function // Should be 0 110000 0, which is "60" in hex (counts as two params,
// because of the encrypted bound args param)
......
......@@ -2,13 +2,13 @@
import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption";
import { cache as $$cache__ } from "private-next-rsc-cache-wrapper";
import { cache as $$reactCache__ } from "react";
const $$RSC_SERVER_CACHE_0_INNER = async function foo() {};
export var $$RSC_SERVER_CACHE_0 = $$reactCache__(function foo() {
return $$cache__("default", "803128060c414d59f8552e4788b846c0d2b7f74743", 0, async function foo() {}, arguments);
return $$cache__("default", "803128060c414d59f8552e4788b846c0d2b7f74743", 0, $$RSC_SERVER_CACHE_0_INNER, arguments);
});
registerServerReference($$RSC_SERVER_CACHE_0, "803128060c414d59f8552e4788b846c0d2b7f74743", null);
Object["defineProperty"]($$RSC_SERVER_CACHE_0, "name", {
value: "foo",
writable: false
value: "foo"
});
export const $$RSC_SERVER_ACTION_1 = async function bar() {};
registerServerReference($$RSC_SERVER_ACTION_1, "0090b5db271335765a4b0eab01f044b381b5ebd5cd", null);
......
......@@ -2,15 +2,15 @@
import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption";
import { cache as $$cache__ } from "private-next-rsc-cache-wrapper";
import { cache as $$reactCache__ } from "react";
const $$RSC_SERVER_CACHE_0_INNER = async function foo([$$ACTION_ARG_0, $$ACTION_ARG_1]) {
return $$ACTION_ARG_0 * $$ACTION_ARG_1;
};
export var $$RSC_SERVER_CACHE_0 = $$reactCache__(function foo() {
return $$cache__("default", "c03128060c414d59f8552e4788b846c0d2b7f74743", 2, async function foo([$$ACTION_ARG_0, $$ACTION_ARG_1]) {
return $$ACTION_ARG_0 * $$ACTION_ARG_1;
}, arguments);
return $$cache__("default", "c03128060c414d59f8552e4788b846c0d2b7f74743", 2, $$RSC_SERVER_CACHE_0_INNER, arguments);
});
registerServerReference($$RSC_SERVER_CACHE_0, "c03128060c414d59f8552e4788b846c0d2b7f74743", null);
Object["defineProperty"]($$RSC_SERVER_CACHE_0, "name", {
value: "foo",
writable: false
value: "foo"
});
export const $$RSC_SERVER_ACTION_1 = async function bar($$ACTION_CLOSURE_BOUND) {
var [$$ACTION_ARG_0] = await decryptActionBoundArgs("4090b5db271335765a4b0eab01f044b381b5ebd5cd", $$ACTION_CLOSURE_BOUND);
......
......@@ -2,15 +2,15 @@
import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption";
import { cache as $$cache__ } from "private-next-rsc-cache-wrapper";
import { cache as $$reactCache__ } from "react";
const $$RSC_SERVER_CACHE_0_INNER = async function fetch1() {
return fetch('https://example.com').then((res)=>res.json());
};
export var $$RSC_SERVER_CACHE_0 = $$reactCache__(function fetch1() {
return $$cache__("default", "803128060c414d59f8552e4788b846c0d2b7f74743", 0, async function fetch1() {
return fetch('https://example.com').then((res)=>res.json());
}, arguments);
return $$cache__("default", "803128060c414d59f8552e4788b846c0d2b7f74743", 0, $$RSC_SERVER_CACHE_0_INNER, arguments);
});
registerServerReference($$RSC_SERVER_CACHE_0, "803128060c414d59f8552e4788b846c0d2b7f74743", null);
Object["defineProperty"]($$RSC_SERVER_CACHE_0, "name", {
value: "fetch",
writable: false
value: "fetch"
});
export const api = {
product: {
......
......@@ -2,15 +2,15 @@
import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption";
import { cache as $$cache__ } from "private-next-rsc-cache-wrapper";
import { cache as $$reactCache__ } from "react";
const $$RSC_SERVER_CACHE_0_INNER = async function foo() {
return fetch('https://example.com').then((res)=>res.json());
};
export var $$RSC_SERVER_CACHE_0 = $$reactCache__(function foo() {
return $$cache__("default", "803128060c414d59f8552e4788b846c0d2b7f74743", 0, async function foo() {
return fetch('https://example.com').then((res)=>res.json());
}, arguments);
return $$cache__("default", "803128060c414d59f8552e4788b846c0d2b7f74743", 0, $$RSC_SERVER_CACHE_0_INNER, arguments);
});
registerServerReference($$RSC_SERVER_CACHE_0, "803128060c414d59f8552e4788b846c0d2b7f74743", null);
Object["defineProperty"]($$RSC_SERVER_CACHE_0, "name", {
value: "foo",
writable: false
value: "foo"
});
export const $$RSC_SERVER_ACTION_1 = async function bar() {
console.log(42);
......
......@@ -2,10 +2,14 @@
import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption";
import { cache as $$cache__ } from "private-next-rsc-cache-wrapper";
import { cache as $$reactCache__ } from "react";
const $$RSC_SERVER_CACHE_0_INNER = async function([$$ACTION_ARG_0]) {
return $$ACTION_ARG_0();
};
Object["defineProperty"]($$RSC_SERVER_CACHE_0_INNER, "name", {
value: ""
});
export var $$RSC_SERVER_CACHE_0 = $$reactCache__(function() {
return $$cache__("default", "c03128060c414d59f8552e4788b846c0d2b7f74743", 1, async function([$$ACTION_ARG_0]) {
return $$ACTION_ARG_0();
}, arguments);
return $$cache__("default", "c03128060c414d59f8552e4788b846c0d2b7f74743", 1, $$RSC_SERVER_CACHE_0_INNER, arguments);
});
registerServerReference($$RSC_SERVER_CACHE_0, "c03128060c414d59f8552e4788b846c0d2b7f74743", null);
function createCachedFn(start) {
......
......@@ -12,12 +12,12 @@ export enum E {
}
export default interface D {
}
const $$RSC_SERVER_CACHE_0_INNER = async function Page() {};
export var $$RSC_SERVER_CACHE_0 = $$reactCache__(function Page() {
return $$cache__("default", "803128060c414d59f8552e4788b846c0d2b7f74743", 0, async function Page() {}, arguments);
return $$cache__("default", "803128060c414d59f8552e4788b846c0d2b7f74743", 0, $$RSC_SERVER_CACHE_0_INNER, arguments);
});
registerServerReference($$RSC_SERVER_CACHE_0, "803128060c414d59f8552e4788b846c0d2b7f74743", null);
Object["defineProperty"]($$RSC_SERVER_CACHE_0, "name", {
value: "Page",
writable: false
value: "Page"
});
export var Page = $$RSC_SERVER_CACHE_0;
......@@ -2,23 +2,23 @@
import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption";
import { cache as $$cache__ } from "private-next-rsc-cache-wrapper";
import { cache as $$reactCache__ } from "react";
const $$RSC_SERVER_CACHE_0_INNER = async function foo() {};
export var $$RSC_SERVER_CACHE_0 = $$reactCache__(function foo() {
return $$cache__("default", "803128060c414d59f8552e4788b846c0d2b7f74743", 0, async function() {}, arguments);
return $$cache__("default", "803128060c414d59f8552e4788b846c0d2b7f74743", 0, $$RSC_SERVER_CACHE_0_INNER, arguments);
});
registerServerReference($$RSC_SERVER_CACHE_0, "803128060c414d59f8552e4788b846c0d2b7f74743", null);
Object["defineProperty"]($$RSC_SERVER_CACHE_0, "name", {
value: "foo",
writable: false
value: "foo"
});
const foo = $$RSC_SERVER_CACHE_0;
const $$RSC_SERVER_CACHE_1_INNER = async function bar() {
return foo();
};
export var $$RSC_SERVER_CACHE_1 = $$reactCache__(function bar() {
return $$cache__("default", "80951c375b4a6a6e89d67b743ec5808127cfde405d", 0, async function bar() {
return foo();
}, arguments);
return $$cache__("default", "80951c375b4a6a6e89d67b743ec5808127cfde405d", 0, $$RSC_SERVER_CACHE_1_INNER, arguments);
});
registerServerReference($$RSC_SERVER_CACHE_1, "80951c375b4a6a6e89d67b743ec5808127cfde405d", null);
Object["defineProperty"]($$RSC_SERVER_CACHE_1, "name", {
value: "bar",
writable: false
value: "bar"
});
export var bar = $$RSC_SERVER_CACHE_1;
{"version":3,"sources":["input.js"],"sourcesContent":["'use cache'\n\nconst foo = async () => {\n 'use cache'\n}\n\nexport async function bar() {\n return foo()\n}\n"],"names":[],"mappings":";;;;WAEY,sCAAA,SAAN;WAAM,sEAAA,kBAEZ;;AAFY;;;;;AAAZ,MAAM;WAIC,sCAAA,SAAe;WAAf,sEAAA,eAAe;QACpB,OAAO;IACT;;AAFO;;;;;AAAP,WAAsB"}
{"version":3,"sources":["input.js"],"sourcesContent":["'use cache'\n\nconst foo = async () => {\n 'use cache'\n}\n\nexport async function bar() {\n return foo()\n}\n"],"names":[],"mappings":";;;;AAEY,MAAA,6BAAA,eAAN,OAEN;WAFY,sCAAA,SAAN;WAAM;;AAAA;;;;AAAZ,MAAM;AAIC,MAAA,6BAAA,eAAe;IACpB,OAAO;AACT;WAFO,sCAAA,SAAe;WAAf;;AAAA;;;;AAAP,WAAsB"}
function createCacheFn() {
return async () => {
'use cache'
throw new Error('kaputt!')
}
}
const cached = createCacheFn()
export default async function Page() {
return <p>A page with an anonymous cache function. {await cached()}</p>
}
import { nextTestSetup } from 'e2e-utils'
import { waitForNoRedbox } from '../../../lib/next-test-utils'
const cacheComponentsEnabled = process.env.__NEXT_CACHE_COMPONENTS === 'true'
describe('use-cache-errors', () => {
const { next } = nextTestSetup({
const { next, isRspack, isTurbopack } = nextTestSetup({
files: __dirname,
})
const isRspack = Boolean(process.env.NEXT_RSPACK)
it('should not show a false-positive compiler error about a misplaced "use cache" directive', async () => {
// This is a regression test to ensure that an injected React Refresh
......@@ -50,4 +51,70 @@ describe('use-cache-errors', () => {
`)
}
})
it('should not leak generated internal cache function names in call stacks', async () => {
const browser = await next.browser('/anonymous')
if (cacheComponentsEnabled) {
if (isTurbopack) {
await expect(browser).toDisplayRedbox(`
{
"description": "kaputt!",
"environmentLabel": "Prerender",
"label": "Runtime Error",
"source": "app/anonymous/page.tsx (4:11) @ <anonymous>
> 4 | throw new Error('kaputt!')
| ^",
"stack": [
"<anonymous> app/anonymous/page.tsx (4:11)",
],
}
`)
} else {
await expect(browser).toDisplayRedbox(`
{
"description": "kaputt!",
"environmentLabel": "Prerender",
"label": "Runtime Error",
"source": "app/anonymous/page.tsx (4:11) @ eval
> 4 | throw new Error('kaputt!')
| ^",
"stack": [
"eval app/anonymous/page.tsx (4:11)",
],
}
`)
}
} else {
if (isTurbopack) {
await expect(browser).toDisplayRedbox(`
{
"description": "kaputt!",
"environmentLabel": "Cache",
"label": "Runtime Error",
"source": "app/anonymous/page.tsx (4:11) @ <anonymous>
> 4 | throw new Error('kaputt!')
| ^",
"stack": [
"<anonymous> app/anonymous/page.tsx (4:11)",
],
}
`)
} else {
await expect(browser).toDisplayRedbox(`
{
"description": "kaputt!",
"environmentLabel": "Cache",
"label": "Runtime Error",
"source": "app/anonymous/page.tsx (4:11) @ eval
> 4 | throw new Error('kaputt!')
| ^",
"stack": [
"eval app/anonymous/page.tsx (4:11)",
],
}
`)
}
}
})
})
......@@ -2149,7 +2149,7 @@ describe('Cache Components Errors', () => {
} else {
expect(output).toMatchInlineSnapshot(`
"Error: Route /use-cache-cookies used \`cookies()\` inside "use cache". Accessing Dynamic data sources inside a cache scope is not supported. If you need this data inside a cached function use \`cookies()\` outside of the cached function and pass the required dynamic data in as an argument. See more info here: https://nextjs.org/docs/messages/next-request-in-use-cache
at <unknown> (app/use-cache-cookies/page.tsx:22:11)
at a (app/use-cache-cookies/page.tsx:22:11)
20 | // in userland.
21 | try {
> 22 | await cookies()
......@@ -2275,7 +2275,7 @@ describe('Cache Components Errors', () => {
if (isTurbopack) {
expect(output).toMatchInlineSnapshot(`
"Error: Route /use-cache-draft-mode used "draftMode().enable()" inside "use cache". The enabled status of \`draftMode()\` can be read in caches but you must not enable or disable \`draftMode()\` inside a cache. See more info here: https://nextjs.org/docs/messages/next-request-in-use-cache
at <unknown> (app/use-cache-draft-mode/page.tsx:20:26)
at a (app/use-cache-draft-mode/page.tsx:20:26)
18 | // here to ensure that this error is shown even when it's caught in userland.
19 | try {
> 20 | ;(await draftMode()).enable()
......@@ -2360,7 +2360,7 @@ describe('Cache Components Errors', () => {
} else {
expect(output).toMatchInlineSnapshot(`
"Error: Route /use-cache-headers used \`headers()\` inside "use cache". Accessing Dynamic data sources inside a cache scope is not supported. If you need this data inside a cached function use \`headers()\` outside of the cached function and pass the required dynamic data in as an argument. See more info here: https://nextjs.org/docs/messages/next-request-in-use-cache
at <unknown> (app/use-cache-headers/page.tsx:21:11)
at a (app/use-cache-headers/page.tsx:21:11)
19 | // to ensure that this error is shown even when it's caught in userland.
20 | try {
> 21 | await headers()
......
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