Skip to content

Commit 250e9e1

Browse files
authored
fix: setting the right tag values for fetch cache (#304)
* fix: get tag values for fetch cache
1 parent 8bc075b commit 250e9e1

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

packages/open-next/src/adapters/cache.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,14 @@ type IncrementalCacheValue =
6969
| CachedFetchValue
7070
| CachedRouteValue;
7171

72+
type IncrementalCacheContext = {
73+
revalidate?: number | false | undefined;
74+
fetchCache?: boolean | undefined;
75+
fetchUrl?: string | undefined;
76+
fetchIdx?: number | undefined;
77+
tags?: string[] | undefined;
78+
};
79+
7280
interface CacheHandlerContext {
7381
fs?: never;
7482
dev?: boolean;
@@ -243,7 +251,11 @@ export default class S3Cache {
243251
}
244252
}
245253

246-
async set(key: string, data?: IncrementalCacheValue): Promise<void> {
254+
async set(
255+
key: string,
256+
data?: IncrementalCacheValue,
257+
ctx?: IncrementalCacheContext,
258+
): Promise<void> {
247259
if (globalThis.disableIncrementalCache) {
248260
return;
249261
}
@@ -294,7 +306,7 @@ export default class S3Cache {
294306
// If we use an in house version of getDerivedTags in build we should use it here instead of next's one
295307
const derivedTags: string[] =
296308
data?.kind === "FETCH"
297-
? data.data.tags ?? []
309+
? ctx?.tags ?? data?.data?.tags ?? [] // before version 14 next.js used data?.data?.tags so we keep it for backward compatibility
298310
: data?.kind === "PAGE"
299311
? data.headers?.["x-next-cache-tags"]?.split(",") ?? []
300312
: [];

0 commit comments

Comments
 (0)