Skip to content
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/major-actors-make.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@opennextjs/cloudflare": patch
---

fix(tag-cache): forward `isStale()` in `withFilter`
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const mockedTagCache = {
getPathsByTags: vi.fn(),
hasBeenRevalidated: vi.fn(),
writeTags: vi.fn(),
isStale: vi.fn(),
} satisfies NextModeTagCache;

const filterFn = (tag: string) => tag.startsWith("valid_");
Expand Down Expand Up @@ -108,6 +109,42 @@ describe("withFilter", () => {
expect(tagCache.getPathsByTags).toBeUndefined();
});

it("should filter out tags based on isStale", async () => {
const tagCache = withFilter({
tagCache: mockedTagCache,
filterFn,
});

const tags = ["valid_tag", "invalid_tag"];
const lastModified = Date.now();

await tagCache.isStale?.(tags, lastModified);
expect(mockedTagCache.isStale).toHaveBeenCalledWith(["valid_tag"], lastModified);
});

it("should not call isStale if no tags are valid", async () => {
const tagCache = withFilter({
tagCache: mockedTagCache,
filterFn,
});
const tags = ["invalid_tag"];
const lastModified = Date.now();
await tagCache.isStale?.(tags, lastModified);
expect(mockedTagCache.isStale).not.toHaveBeenCalled();
});

it("should not create a function if isStale is not defined", async () => {
const tagCache = withFilter({
tagCache: {
...mockedTagCache,
isStale: undefined,
},
filterFn,
});

expect(tagCache.isStale).toBeUndefined();
});

it("should filter soft tags", () => {
const tagCache = withFilter({
tagCache: mockedTagCache,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,15 @@ export function withFilter({ tagCache, filterFn }: WithFilterOptions): NextModeT
}
return tagCache.writeTags(filteredTags);
},
isStale: tagCache.isStale
? async (tags, lastModified) => {
const filteredTags = tags.filter(filterFn);
if (filteredTags.length === 0) {
return false;
}
return tagCache.isStale!(filteredTags, lastModified);
}
: undefined,
};
}

Expand Down
Loading