Unverified Commit 40bc285d authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Update data cache max size error (#62348)

Makes the error message more specific to Next.js and provides specific
size that exceeded the limit.

x-ref: [slack
thread](https://vercel.slack.com/archives/C05U6TZ2DCP/p1708543103375799)

Closes NEXT-2559
parent 5dd895db
...@@ -562,15 +562,18 @@ export class IncrementalCache implements IncrementalCacheType { ...@@ -562,15 +562,18 @@ export class IncrementalCache implements IncrementalCacheType {
if (this.dev && !ctx.fetchCache) return if (this.dev && !ctx.fetchCache) return
// FetchCache has upper limit of 2MB per-entry currently // FetchCache has upper limit of 2MB per-entry currently
const itemSize = JSON.stringify(data).length
if ( if (
ctx.fetchCache && ctx.fetchCache &&
// we don't show this error/warning when a custom cache handler is being used // we don't show this error/warning when a custom cache handler is being used
// as it might not have this limit // as it might not have this limit
!this.hasCustomCacheHandler && !this.hasCustomCacheHandler &&
JSON.stringify(data).length > 2 * 1024 * 1024 itemSize > 2 * 1024 * 1024
) { ) {
if (this.dev) { if (this.dev) {
throw new Error(`fetch for over 2MB of data can not be cached`) throw new Error(
`Failed to set Next.js data cache, items over 2MB can not be cached (${itemSize} bytes)`
)
} }
return return
} }
......
...@@ -3091,7 +3091,7 @@ createNextDescribe( ...@@ -3091,7 +3091,7 @@ createNextDescribe(
.length .length
).toBe(2) ).toBe(2)
expect(next.cliOutput.substring(cliOutputStart)).toContain( expect(next.cliOutput.substring(cliOutputStart)).toContain(
'Error: fetch for over 2MB of data can not be cached' 'Error: Failed to set Next.js data cache, items over 2MB can not be cached'
) )
return 'success' return 'success'
}, 'success') }, 'success')
...@@ -3122,7 +3122,7 @@ createNextDescribe( ...@@ -3122,7 +3122,7 @@ createNextDescribe(
}, 'success') }, 'success')
expect(next.cliOutput.substring(cliOutputStart)).not.toContain( expect(next.cliOutput.substring(cliOutputStart)).not.toContain(
'Error: fetch for over 2MB of data can not be cached' 'Error: Failed to set Next.js data cache, items over 2MB can not be cached'
) )
}) })
} }
......
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