From 05e13c0e4c77b48d01d2cf89f8cc4039fe2492da Mon Sep 17 00:00:00 2001 From: Dorseuil Nicolas Date: Thu, 13 Mar 2025 11:11:05 +0100 Subject: [PATCH 1/5] add additional info on the queue message --- packages/open-next/src/core/routing/cacheInterceptor.ts | 7 ++++++- packages/open-next/src/core/routing/util.ts | 4 ++-- packages/open-next/src/types/overrides.ts | 2 ++ 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/packages/open-next/src/core/routing/cacheInterceptor.ts b/packages/open-next/src/core/routing/cacheInterceptor.ts index 5c1bdce85..bb8814f12 100644 --- a/packages/open-next/src/core/routing/cacheInterceptor.ts +++ b/packages/open-next/src/core/routing/cacheInterceptor.ts @@ -63,7 +63,12 @@ async function computeCacheControl( url = `${NextConfig.basePath}${url}`; } await globalThis.queue.send({ - MessageBody: { host, url }, + MessageBody: { + host, + url, + eTag: etag, + lastModified: lastModified ?? Date.now(), + }, MessageDeduplicationId: hash(`${path}-${lastModified}-${etag}`), MessageGroupId: generateMessageGroupId(path), }); diff --git a/packages/open-next/src/core/routing/util.ts b/packages/open-next/src/core/routing/util.ts index 5e15e5c54..351c067b7 100644 --- a/packages/open-next/src/core/routing/util.ts +++ b/packages/open-next/src/core/routing/util.ts @@ -324,10 +324,10 @@ export async function revalidateIfRequired( // For some weird cases, lastModified is not set, haven't been able to figure out yet why // For those cases we add the etag to the deduplication id, it might help - const etag = headers.etag ?? headers.ETag ?? ""; + const etag = headers.etag ?? `${headers.ETag}` ?? ""; await globalThis.queue.send({ - MessageBody: { host, url: revalidateUrl }, + MessageBody: { host, url: revalidateUrl, eTag: etag, lastModified }, MessageDeduplicationId: hash(`${rawPath}-${lastModified}-${etag}`), MessageGroupId: generateMessageGroupId(rawPath), }); diff --git a/packages/open-next/src/types/overrides.ts b/packages/open-next/src/types/overrides.ts index 388448be0..4ea257270 100644 --- a/packages/open-next/src/types/overrides.ts +++ b/packages/open-next/src/types/overrides.ts @@ -20,6 +20,8 @@ export interface QueueMessage { MessageBody: { host: string; url: string; + lastModified: number; + eTag: string; }; MessageGroupId: string; } From f14b9b1912f35912cda7a21878005c65ed681328 Mon Sep 17 00:00:00 2001 From: Dorseuil Nicolas Date: Thu, 13 Mar 2025 11:12:08 +0100 Subject: [PATCH 2/5] add .js so that test doesn't fail in cloudflare --- packages/open-next/src/adapters/logger.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/open-next/src/adapters/logger.ts b/packages/open-next/src/adapters/logger.ts index fe471e832..24a3750b7 100644 --- a/packages/open-next/src/adapters/logger.ts +++ b/packages/open-next/src/adapters/logger.ts @@ -1,4 +1,4 @@ -import { isOpenNextError } from "utils/error"; +import { isOpenNextError } from "utils/error.js"; export function debug(...args: any[]) { if (globalThis.openNextDebug) { From ada432365d874362937bcd6bf61577c2ea172625 Mon Sep 17 00:00:00 2001 From: Dorseuil Nicolas Date: Thu, 13 Mar 2025 11:19:40 +0100 Subject: [PATCH 3/5] changeset --- .changeset/sour-boxes-jump.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/sour-boxes-jump.md diff --git a/.changeset/sour-boxes-jump.md b/.changeset/sour-boxes-jump.md new file mode 100644 index 000000000..1ccf38780 --- /dev/null +++ b/.changeset/sour-boxes-jump.md @@ -0,0 +1,5 @@ +--- +"@opennextjs/aws": patch +--- + +Add additional params to the queue override From dd37ee5f071bf52650756cf68df406053f84319b Mon Sep 17 00:00:00 2001 From: Dorseuil Nicolas Date: Thu, 13 Mar 2025 11:24:23 +0100 Subject: [PATCH 4/5] fix test --- .../tests-unit/tests/core/routing/util.test.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/packages/tests-unit/tests/core/routing/util.test.ts b/packages/tests-unit/tests/core/routing/util.test.ts index b3d721b56..6377371c5 100644 --- a/packages/tests-unit/tests/core/routing/util.test.ts +++ b/packages/tests-unit/tests/core/routing/util.test.ts @@ -668,7 +668,12 @@ describe("revalidateIfRequired", () => { await revalidateIfRequired("localhost", "/path", headers); expect(sendMock).toHaveBeenCalledWith({ - MessageBody: { host: "localhost", url: "/path" }, + MessageBody: { + host: "localhost", + url: "/path", + eTag: expect.any(String), + lastModified: expect.any(Number), + }, MessageDeduplicationId: expect.any(String), MessageGroupId: expect.any(String), }); @@ -682,7 +687,12 @@ describe("revalidateIfRequired", () => { await revalidateIfRequired("localhost", "/path", headers); expect(sendMock).toHaveBeenCalledWith({ - MessageBody: { host: "localhost", url: "/path" }, + MessageBody: { + host: "localhost", + url: "/path", + eTag: expect.any(String), + lastModified: expect.any(Number), + }, MessageDeduplicationId: expect.any(String), MessageGroupId: expect.any(String), }); From b63153fbf9d851712f4ce1e6d52dc9df0aed3174 Mon Sep 17 00:00:00 2001 From: Dorseuil Nicolas Date: Thu, 13 Mar 2025 13:48:15 +0100 Subject: [PATCH 5/5] review fix --- packages/open-next/src/core/routing/util.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/open-next/src/core/routing/util.ts b/packages/open-next/src/core/routing/util.ts index 351c067b7..b24f896c4 100644 --- a/packages/open-next/src/core/routing/util.ts +++ b/packages/open-next/src/core/routing/util.ts @@ -324,11 +324,11 @@ export async function revalidateIfRequired( // For some weird cases, lastModified is not set, haven't been able to figure out yet why // For those cases we add the etag to the deduplication id, it might help - const etag = headers.etag ?? `${headers.ETag}` ?? ""; + const eTag = `${headers.etag ?? headers.ETag ?? ""}`; await globalThis.queue.send({ - MessageBody: { host, url: revalidateUrl, eTag: etag, lastModified }, - MessageDeduplicationId: hash(`${rawPath}-${lastModified}-${etag}`), + MessageBody: { host, url: revalidateUrl, eTag, lastModified }, + MessageDeduplicationId: hash(`${rawPath}-${lastModified}-${eTag}`), MessageGroupId: generateMessageGroupId(rawPath), }); } catch (e) {