diff --git a/.changeset/light-needles-smell.md b/.changeset/light-needles-smell.md new file mode 100644 index 000000000..d58ebd92f --- /dev/null +++ b/.changeset/light-needles-smell.md @@ -0,0 +1,5 @@ +--- +"@opennextjs/aws": patch +--- + +fix(cacheInterceptor): route cache handling diff --git a/packages/open-next/src/core/routing/cacheInterceptor.ts b/packages/open-next/src/core/routing/cacheInterceptor.ts index 51571b77d..69a3498d2 100644 --- a/packages/open-next/src/core/routing/cacheInterceptor.ts +++ b/packages/open-next/src/core/routing/cacheInterceptor.ts @@ -228,7 +228,10 @@ export async function cacheInterceptor( return event; } // We need to check the tag cache now - if (cachedData.value?.type === "app") { + if ( + cachedData.value?.type === "app" || + cachedData.value?.type === "route" + ) { const tags = getTagsFromValue(cachedData.value); const _hasBeenRevalidated = await hasBeenRevalidated( localizedPath, diff --git a/packages/tests-unit/tests/core/routing/cacheInterceptor.test.ts b/packages/tests-unit/tests/core/routing/cacheInterceptor.test.ts index 952ff3df4..8e9ef20e4 100644 --- a/packages/tests-unit/tests/core/routing/cacheInterceptor.test.ts +++ b/packages/tests-unit/tests/core/routing/cacheInterceptor.test.ts @@ -153,7 +153,7 @@ describe("cacheInterceptor", () => { ); }); - it("should take no action when tagCache lasModified is -1", async () => { + it("should take no action when tagCache lasModified is -1 for app type", async () => { const event = createEvent({ url: "/albums", }); @@ -170,6 +170,25 @@ describe("cacheInterceptor", () => { expect(result).toEqual(event); }); + it("should take no action when tagCache lasModified is -1 for route type", async () => { + const event = createEvent({ + url: "/albums", + }); + + const body = "route"; + incrementalCache.get.mockResolvedValueOnce({ + value: { + type: "route", + body: body, + revalidate: false, + }, + lastModified: new Date("2024-01-01T23:58:00Z").getTime(), + }); + tagCache.getLastModified.mockResolvedValueOnce(-1); + const result = await cacheInterceptor(event); + expect(result).toEqual(event); + }); + it("should retrieve page router content from stale cache", async () => { const event = createEvent({ url: "/revalidate", @@ -263,7 +282,7 @@ describe("cacheInterceptor", () => { ); }); - it("should take no action when cache returns unrecoginsed type", async () => { + it("should take no action when cache returns unrecognized type", async () => { const event = createEvent({ url: "/albums", });