Skip to content

Commit 2094c9b

Browse files
authored
fix issue with fetch cache for new page (#497)
* fix issue with fetch cache for new page * fix typo * Create tame-foxes-compete.md
1 parent 85af1ce commit 2094c9b

File tree

3 files changed

+27
-21
lines changed

3 files changed

+27
-21
lines changed

.changeset/tame-foxes-compete.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"open-next": patch
3+
---
4+
5+
fix issue with fetch cache for new page

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

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -147,27 +147,24 @@ export default class S3Cache {
147147

148148
if (value === undefined) return null;
149149

150-
// For cases where we don't have tags, we need to ensure that we insert at least an entry
151-
// for this specific paths, otherwise we might not be able to invalidate it
150+
// For cases where we don't have tags, we need to ensure that the soft tags are not being revalidated
151+
// We only need to check for the path as it should already contain all the tags
152152
if ((tags ?? []).length === 0) {
153-
// First we check if we have any tags for the given key
154-
const storedTags = await globalThis.tagCache.getByPath(key);
155-
if (storedTags.length === 0) {
156-
// Then we need to find the path for the given key
157-
const path = softTags?.find(
158-
(tag) =>
159-
tag.startsWith("_N_T_/") &&
160-
!tag.endsWith("layout") &&
161-
!tag.endsWith("page"),
153+
// Then we need to find the path for the given key
154+
const path = softTags?.find(
155+
(tag) =>
156+
tag.startsWith("_N_T_/") &&
157+
!tag.endsWith("layout") &&
158+
!tag.endsWith("page"),
159+
);
160+
if (path) {
161+
const pathLastModified = await globalThis.tagCache.getLastModified(
162+
path.replace("_N_T_/", ""),
163+
lastModified,
162164
);
163-
if (path) {
164-
// And write the path with the tag
165-
await globalThis.tagCache.writeTags([
166-
{
167-
path: key,
168-
tag: path,
169-
},
170-
]);
165+
if (pathLastModified === -1) {
166+
// In case the path has been revalidated, we don't want to use the fetch cache
167+
return null;
171168
}
172169
}
173170
}
@@ -338,6 +335,9 @@ export default class S3Cache {
338335
tagsToWrite.map((tag) => ({
339336
path: key,
340337
tag: tag,
338+
// In case the tags are not there we just need to create them
339+
// but we don't want them to return from `getLastModified` as they are not stale
340+
revalidatedAt: 1,
341341
})),
342342
);
343343
}

packages/open-next/src/build.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,8 @@ async function createCacheAssets(monorepoRoot: string) {
600600
path.relative(outputPath, filePath).replace(".meta", ""),
601601
),
602602
},
603-
revalidatedAt: { N: `${Date.now()}` },
603+
// We don't care about the revalidation time here, we just need to make sure it's there
604+
revalidatedAt: { N: "1" },
604605
});
605606
});
606607
}
@@ -632,7 +633,7 @@ async function createCacheAssets(monorepoRoot: string) {
632633
path.relative(fetchCachePath, filepath),
633634
),
634635
},
635-
revalidatedAt: { N: `${Date.now()}` },
636+
revalidatedAt: { N: "1" },
636637
});
637638
});
638639
},

0 commit comments

Comments
 (0)