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 {
if (this.dev && !ctx.fetchCache) return
// FetchCache has upper limit of 2MB per-entry currently
const itemSize = JSON.stringify(data).length
if (
ctx.fetchCache &&
// we don't show this error/warning when a custom cache handler is being used
// as it might not have this limit
!this.hasCustomCacheHandler &&
JSON.stringify(data).length > 2 * 1024 * 1024
itemSize > 2 * 1024 * 1024
) {
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
}
......
......@@ -3091,7 +3091,7 @@ createNextDescribe(
.length
).toBe(2)
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'
}, 'success')
......@@ -3122,7 +3122,7 @@ createNextDescribe(
}, 'success')
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