Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit daa330b

Browse files
authored
Feat Add additional params to the queue override (#773)
* add additional info on the queue message * add .js so that test doesn't fail in cloudflare * changeset * fix test * review fix
1 parent 656c709 commit daa330b

File tree

6 files changed

+29
-7
lines changed

6 files changed

+29
-7
lines changed

.changeset/sour-boxes-jump.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@opennextjs/aws": patch
3+
---
4+
5+
Add additional params to the queue override

packages/open-next/src/adapters/logger.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { isOpenNextError } from "utils/error";
1+
import { isOpenNextError } from "utils/error.js";
22

33
export function debug(...args: any[]) {
44
if (globalThis.openNextDebug) {

packages/open-next/src/core/routing/cacheInterceptor.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,12 @@ async function computeCacheControl(
6363
url = `${NextConfig.basePath}${url}`;
6464
}
6565
await globalThis.queue.send({
66-
MessageBody: { host, url },
66+
MessageBody: {
67+
host,
68+
url,
69+
eTag: etag,
70+
lastModified: lastModified ?? Date.now(),
71+
},
6772
MessageDeduplicationId: hash(`${path}-${lastModified}-${etag}`),
6873
MessageGroupId: generateMessageGroupId(path),
6974
});

packages/open-next/src/core/routing/util.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -324,11 +324,11 @@ export async function revalidateIfRequired(
324324

325325
// For some weird cases, lastModified is not set, haven't been able to figure out yet why
326326
// For those cases we add the etag to the deduplication id, it might help
327-
const etag = headers.etag ?? headers.ETag ?? "";
327+
const eTag = `${headers.etag ?? headers.ETag ?? ""}`;
328328

329329
await globalThis.queue.send({
330-
MessageBody: { host, url: revalidateUrl },
331-
MessageDeduplicationId: hash(`${rawPath}-${lastModified}-${etag}`),
330+
MessageBody: { host, url: revalidateUrl, eTag, lastModified },
331+
MessageDeduplicationId: hash(`${rawPath}-${lastModified}-${eTag}`),
332332
MessageGroupId: generateMessageGroupId(rawPath),
333333
});
334334
} catch (e) {

packages/open-next/src/types/overrides.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ export interface QueueMessage {
2020
MessageBody: {
2121
host: string;
2222
url: string;
23+
lastModified: number;
24+
eTag: string;
2325
};
2426
MessageGroupId: string;
2527
}

packages/tests-unit/tests/core/routing/util.test.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,12 @@ describe("revalidateIfRequired", () => {
668668
await revalidateIfRequired("localhost", "/path", headers);
669669

670670
expect(sendMock).toHaveBeenCalledWith({
671-
MessageBody: { host: "localhost", url: "/path" },
671+
MessageBody: {
672+
host: "localhost",
673+
url: "/path",
674+
eTag: expect.any(String),
675+
lastModified: expect.any(Number),
676+
},
672677
MessageDeduplicationId: expect.any(String),
673678
MessageGroupId: expect.any(String),
674679
});
@@ -682,7 +687,12 @@ describe("revalidateIfRequired", () => {
682687
await revalidateIfRequired("localhost", "/path", headers);
683688

684689
expect(sendMock).toHaveBeenCalledWith({
685-
MessageBody: { host: "localhost", url: "/path" },
690+
MessageBody: {
691+
host: "localhost",
692+
url: "/path",
693+
eTag: expect.any(String),
694+
lastModified: expect.any(Number),
695+
},
686696
MessageDeduplicationId: expect.any(String),
687697
MessageGroupId: expect.any(String),
688698
});

0 commit comments

Comments
 (0)