Skip to content

Commit 195b67d

Browse files
authored
fix(tagCache): do not call writeTags with an empty list (#828)
1 parent 199a26f commit 195b67d

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

.changeset/lemon-needles-fold.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(tagCache): do not call writeTags with an empty list

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,8 +311,12 @@ export default class Cache {
311311
if (config?.disableTagCache || config?.disableIncrementalCache) {
312312
return;
313313
}
314+
const _tags = Array.isArray(tags) ? tags : [tags];
315+
if (_tags.length === 0) {
316+
return;
317+
}
318+
314319
try {
315-
const _tags = Array.isArray(tags) ? tags : [tags];
316320
if (globalThis.tagCache.mode === "nextMode") {
317321
const paths = (await globalThis.tagCache.getPathsByTags?.(_tags)) ?? [];
318322

@@ -336,6 +340,7 @@ export default class Cache {
336340
}
337341
return;
338342
}
343+
339344
for (const tag of _tags) {
340345
debug("revalidateTag", tag);
341346
// Find all keys with the given tag

packages/tests-unit/tests/adapters/cache.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,14 @@ describe("CacheHandler", () => {
587587
expect(invalidateCdnHandler.invalidatePaths).not.toHaveBeenCalled();
588588
});
589589

590+
it("Should not call writeTags when the tag list is empty for nextMode", async () => {
591+
globalThis.tagCache.mode = "nextMode";
592+
await cache.revalidateTag([]);
593+
594+
expect(tagCache.writeTags).not.toHaveBeenCalled();
595+
expect(invalidateCdnHandler.invalidatePaths).not.toHaveBeenCalled();
596+
});
597+
590598
it("Should call writeTags and invalidateCdnHandler.invalidatePaths for nextMode that supports getPathsByTags", async () => {
591599
globalThis.tagCache.mode = "nextMode";
592600
globalThis.tagCache.getPathsByTags = vi

0 commit comments

Comments
 (0)