Skip to content

Commit

Permalink
fix: setting the right tag values for fetch cache (#304)
Browse files Browse the repository at this point in the history
* fix: get tag values for fetch cache
  • Loading branch information
mathisobadia committed Nov 27, 2023
1 parent 8bc075b commit 250e9e1
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions packages/open-next/src/adapters/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ type IncrementalCacheValue =
| CachedFetchValue
| CachedRouteValue;

type IncrementalCacheContext = {
revalidate?: number | false | undefined;
fetchCache?: boolean | undefined;
fetchUrl?: string | undefined;
fetchIdx?: number | undefined;
tags?: string[] | undefined;
};

interface CacheHandlerContext {
fs?: never;
dev?: boolean;
Expand Down Expand Up @@ -243,7 +251,11 @@ export default class S3Cache {
}
}

async set(key: string, data?: IncrementalCacheValue): Promise<void> {
async set(
key: string,
data?: IncrementalCacheValue,
ctx?: IncrementalCacheContext,
): Promise<void> {
if (globalThis.disableIncrementalCache) {
return;
}
Expand Down Expand Up @@ -294,7 +306,7 @@ export default class S3Cache {
// If we use an in house version of getDerivedTags in build we should use it here instead of next's one
const derivedTags: string[] =
data?.kind === "FETCH"
? data.data.tags ?? []
? ctx?.tags ?? data?.data?.tags ?? [] // before version 14 next.js used data?.data?.tags so we keep it for backward compatibility
: data?.kind === "PAGE"
? data.headers?.["x-next-cache-tags"]?.split(",") ?? []
: [];
Expand Down

1 comment on commit 250e9e1

@vercel
Copy link

@vercel vercel bot commented on 250e9e1 Nov 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

open-next – ./

open-next.vercel.app
open-next-git-main-sst-dev.vercel.app
open-next-sst-dev.vercel.app

Please sign in to comment.