Skip to content

fix(tagCache): do not call writeTags with an empty list #828

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/lemon-needles-fold.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@opennextjs/aws": patch
---

fix(tagCache): do not call writeTags with an empty list
7 changes: 6 additions & 1 deletion packages/open-next/src/adapters/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,12 @@ export default class Cache {
if (config?.disableTagCache || config?.disableIncrementalCache) {
return;
}
const _tags = Array.isArray(tags) ? tags : [tags];
if (_tags.length === 0) {
return;
}

try {
const _tags = Array.isArray(tags) ? tags : [tags];
if (globalThis.tagCache.mode === "nextMode") {
const paths = (await globalThis.tagCache.getPathsByTags?.(_tags)) ?? [];

Expand All @@ -336,6 +340,7 @@ export default class Cache {
}
return;
}

for (const tag of _tags) {
debug("revalidateTag", tag);
// Find all keys with the given tag
Expand Down
8 changes: 8 additions & 0 deletions packages/tests-unit/tests/adapters/cache.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,14 @@ describe("CacheHandler", () => {
expect(invalidateCdnHandler.invalidatePaths).not.toHaveBeenCalled();
});

it("Should not call writeTags when the tag list is empty for nextMode", async () => {
globalThis.tagCache.mode = "nextMode";
await cache.revalidateTag([]);

expect(tagCache.writeTags).not.toHaveBeenCalled();
expect(invalidateCdnHandler.invalidatePaths).not.toHaveBeenCalled();
});

it("Should call writeTags and invalidateCdnHandler.invalidatePaths for nextMode that supports getPathsByTags", async () => {
globalThis.tagCache.mode = "nextMode";
globalThis.tagCache.getPathsByTags = vi
Expand Down