diff --git a/.changeset/gold-penguins-walk.md b/.changeset/gold-penguins-walk.md new file mode 100644 index 000000000..e13671bd1 --- /dev/null +++ b/.changeset/gold-penguins-walk.md @@ -0,0 +1,5 @@ +--- +"@opennextjs/aws": minor +--- + +fix: allow bypassing the Tag Cache in the interceptor diff --git a/packages/open-next/src/core/routing/cacheInterceptor.ts b/packages/open-next/src/core/routing/cacheInterceptor.ts index 69a3498d2..cbbfdc6c2 100644 --- a/packages/open-next/src/core/routing/cacheInterceptor.ts +++ b/packages/open-next/src/core/routing/cacheInterceptor.ts @@ -233,11 +233,11 @@ export async function cacheInterceptor( cachedData.value?.type === "route" ) { const tags = getTagsFromValue(cachedData.value); - const _hasBeenRevalidated = await hasBeenRevalidated( - localizedPath, - tags, - cachedData, - ); + + const _hasBeenRevalidated = cachedData.shouldBypassTagCache + ? false + : await hasBeenRevalidated(localizedPath, tags, cachedData); + if (_hasBeenRevalidated) { return event; } diff --git a/packages/tests-unit/tests/core/routing/cacheInterceptor.test.ts b/packages/tests-unit/tests/core/routing/cacheInterceptor.test.ts index 8e9ef20e4..2fa8021df 100644 --- a/packages/tests-unit/tests/core/routing/cacheInterceptor.test.ts +++ b/packages/tests-unit/tests/core/routing/cacheInterceptor.test.ts @@ -170,6 +170,23 @@ describe("cacheInterceptor", () => { expect(result).toEqual(event); }); + it("should bypass the tag cache when shouldBypassTagCache is true", async () => { + const event = createEvent({ + url: "/albums", + }); + incrementalCache.get.mockResolvedValueOnce({ + value: { + type: "app", + html: "Hello, world!", + }, + shouldBypassTagCache: true, + }); + + await cacheInterceptor(event); + + expect(tagCache.getLastModified).not.toHaveBeenCalled(); + }); + it("should take no action when tagCache lasModified is -1 for route type", async () => { const event = createEvent({ url: "/albums",