Skip to content

Commit

Permalink
micro fix of the cache limit check (vercel#60249)
Browse files Browse the repository at this point in the history
### Fixing a bug

I'm sorry, I have no idea how I managed to delete this, as I just copied
the code.

However, I had to figure out why the tests passed. When I test the
running application locally, it works as expected.

So, when a route is first used in a running production application in a
test, `ctx.fetchCache` is `undefined`. Therefore, the error rule does
not trigger on the first request, and the cache is successfully written.
This may result in artifacts in FetchCache in Vercel and possibly in
other parts of the code.

```ts
if (
  ctx.fetchCache && // <- Undefined on first request
  // 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
) {
  if (this.dev) {
    throw new Error(`fetch for over 2MB of data can not be cached`)
  }
  return
}
```

I'm 95% sure that this is a bug and it shouldn't work like this. I'll
look into this later and if there is an error, I'll put it into a task
and try to figure it out later.

Unfortunately, the
[test](https://github.com/vordgi/next.js/blob/7e028fb6d8598cfcca8de514e4608374f931c973/test/e2e/app-dir/app-static/app-static.test.ts#L3080)
from [previous PR](vercel#59976) is not
working yet, although it is correct from my point of view. I think it
should be kept and the problem above should be fixed.

Co-authored-by: JJ Kasper <jj@jjsweb.site>
  • Loading branch information
2 people authored and agustints committed Jan 6, 2024
1 parent 6497c2d commit 444e3bb
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion packages/next/src/server/lib/incremental-cache/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ export class IncrementalCache implements IncrementalCacheType {
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 &&
!this.hasCustomCacheHandler &&
JSON.stringify(data).length > 2 * 1024 * 1024
) {
if (this.dev) {
Expand Down

0 comments on commit 444e3bb

Please sign in to comment.