From 1270295fb1e9d01ac76c26bc8fb02e377c1a32a2 Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Thu, 18 Sep 2025 10:27:35 +0200 Subject: [PATCH 1/2] fix: allow bypassing the Tag Cache in the interceptor --- .changeset/gold-penguins-walk.md | 5 +++++ .../open-next/src/core/routing/cacheInterceptor.ts | 10 +++++----- 2 files changed, 10 insertions(+), 5 deletions(-) create mode 100644 .changeset/gold-penguins-walk.md 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; } From fe84e30a92f77f3f596a7804e3242cb37c510713 Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Thu, 18 Sep 2025 12:09:35 +0200 Subject: [PATCH 2/2] fixup! test --- .../tests/core/routing/cacheInterceptor.test.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) 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",