Skip to content

Commit 580fad1

Browse files
authored
fix(dev-overrides): Make fs-dev tagCache override work with BUILD_ID (opennextjs#967)
* fix(dev-overrides): Make fs-dev tagCache override work with BUILD_ID * rm func * review
1 parent ef4948b commit 580fad1

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed

.changeset/light-pumas-call.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@opennextjs/aws": patch
3+
---
4+
5+
fix(dev-overrides): Make fs-dev tagCache override work with BUILD_ID

packages/open-next/src/overrides/tagCache/fs-dev.ts

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,39 +16,45 @@ let tags = JSON.parse(tagContent) as {
1616
revalidatedAt: { N: string };
1717
}[];
1818

19+
const { NEXT_BUILD_ID } = process.env;
20+
21+
function buildKey(key: string) {
22+
return path.posix.join(NEXT_BUILD_ID ?? "", key);
23+
}
24+
1925
const tagCache: TagCache = {
2026
name: "fs-dev",
2127
mode: "original",
2228
getByPath: async (path: string) => {
2329
return tags
24-
.filter((tagPathMapping) => tagPathMapping.path.S === path)
25-
.map((tag) => tag.tag.S);
30+
.filter((tagPathMapping) => tagPathMapping.path.S === buildKey(path))
31+
.map((tag) => tag.tag.S.replace(`${NEXT_BUILD_ID}/`, ""));
2632
},
2733
getByTag: async (tag: string) => {
2834
return tags
29-
.filter((tagPathMapping) => tagPathMapping.tag.S === tag)
30-
.map((tag) => tag.path.S);
35+
.filter((tagPathMapping) => tagPathMapping.tag.S === buildKey(tag))
36+
.map((tagEntry) => tagEntry.path.S.replace(`${NEXT_BUILD_ID}/`, ""));
3137
},
3238
getLastModified: async (path: string, lastModified?: number) => {
3339
const revalidatedTags = tags.filter(
3440
(tagPathMapping) =>
35-
tagPathMapping.path.S === path &&
41+
tagPathMapping.path.S === buildKey(path) &&
3642
Number.parseInt(tagPathMapping.revalidatedAt.N) > (lastModified ?? 0),
3743
);
3844
return revalidatedTags.length > 0 ? -1 : (lastModified ?? Date.now());
3945
},
4046
writeTags: async (newTags) => {
4147
const newTagsSet = new Set(
42-
newTags.map(({ tag, path }) => `${tag}-${path}`),
48+
newTags.map(({ tag, path }) => `${buildKey(tag)}-${buildKey(path)}`),
4349
);
4450
const unchangedTags = tags.filter(
4551
({ tag, path }) => !newTagsSet.has(`${tag.S}-${path.S}`),
4652
);
4753
tags = unchangedTags.concat(
48-
newTags.map((tag) => ({
49-
tag: { S: tag.tag },
50-
path: { S: tag.path },
51-
revalidatedAt: { N: String(tag.revalidatedAt ?? 1) },
54+
newTags.map((item) => ({
55+
tag: { S: buildKey(item.tag) },
56+
path: { S: buildKey(item.path) },
57+
revalidatedAt: { N: `${item.revalidatedAt ?? Date.now()}` },
5258
})),
5359
);
5460
},

0 commit comments

Comments
 (0)