Skip to content

Commit

Permalink
fix(fetch-cache): add suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
samcx committed Apr 22, 2024
1 parent a5831b1 commit 8f72817
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions packages/next/src/server/lib/incremental-cache/fetch-cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,14 +253,16 @@ export default class FetchCache implements CacheHandler {
throw new Error(`invalid response from cache ${res.status}`)
}

const cached: IncrementalCacheValue = await res.json()
const cachedParsed = zCachedFetchValue.safeParse(cached)
const json: IncrementalCacheValue = await res.json()
const parsed = zCachedFetchValue.safeParse(json)

if (!cachedParsed.success) {
this.debug && console.log({ cached })
if (!parsed.success) {
this.debug && console.log({ json })
throw new Error('invalid cache value')
}

const { data: cached } = parsed

// if new tags were specified, merge those tags to the existing tags
if (cached.kind === 'FETCH') {
cached.tags ??= []
Expand Down

0 comments on commit 8f72817

Please sign in to comment.