Skip to content

Commit 0baa1f7

Browse files
authored
Remove one stack frame from 'use cache' call stacks (#85966)
1 parent cb6ee43 commit 0baa1f7

File tree

2 files changed

+1
-5
lines changed

2 files changed

+1
-5
lines changed

packages/next/src/server/use-cache/use-cache-wrapper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@ async function generateCacheEntryImpl(
588588
// though, until React awaits the promise so that React's request store (ALS)
589589
// is available when the function is invoked. This allows us, for example, to
590590
// capture logs so that we can later replay them.
591-
const resultPromise = createLazyResult(() => fn.apply(null, args))
591+
const resultPromise = createLazyResult(fn.bind(null, ...args))
592592

593593
let errors: Array<unknown> = []
594594

test/e2e/app-dir/cache-components-errors/cache-components-errors.test.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2169,7 +2169,6 @@ describe('Cache Components Errors', () => {
21692169
expect(output).toMatchInlineSnapshot(`
21702170
"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
21712171
at CookiesReadingComponent (webpack:///app/use-cache-cookies/page.tsx:22:18)
2172-
at <unknown> (webpack:///<next-src>)
21732172
20 | // in userland.
21742173
21 | try {
21752174
> 22 | await cookies()
@@ -2188,7 +2187,6 @@ describe('Cache Components Errors', () => {
21882187
"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
21892188
at a (<next-dist-dir>)
21902189
at b (<next-dist-dir>)
2191-
at c (<next-dist-dir>)
21922190
To get a more detailed stack trace and pinpoint the issue, try one of the following:
21932191
- Start the app in development mode by running \`next dev\`, then open "/use-cache-cookies" in your browser to investigate the error.
21942192
- Rerun the production build with \`next build --debug-prerender\` to generate better stack traces.
@@ -2380,7 +2378,6 @@ describe('Cache Components Errors', () => {
23802378
expect(output).toMatchInlineSnapshot(`
23812379
"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
23822380
at HeadersReadingComponent (webpack:///app/use-cache-headers/page.tsx:21:18)
2383-
at <unknown> (webpack:///<next-src>)
23842381
19 | // to ensure that this error is shown even when it's caught in userland.
23852382
20 | try {
23862383
> 21 | await headers()
@@ -2399,7 +2396,6 @@ describe('Cache Components Errors', () => {
23992396
"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
24002397
at a (<next-dist-dir>)
24012398
at b (<next-dist-dir>)
2402-
at c (<next-dist-dir>)
24032399
To get a more detailed stack trace and pinpoint the issue, try one of the following:
24042400
- Start the app in development mode by running \`next dev\`, then open "/use-cache-headers" in your browser to investigate the error.
24052401
- Rerun the production build with \`next build --debug-prerender\` to generate better stack traces.

0 commit comments

Comments
 (0)