Skip to content

Commit e8971cd

Browse files
authored
retrieve the preview ID from process.env (#1015)
1 parent f4b53b9 commit e8971cd

File tree

4 files changed

+49
-42
lines changed

4 files changed

+49
-42
lines changed

.changeset/honest-games-tell.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@opennextjs/cloudflare": patch
3+
---
4+
5+
memory queue: retrieve the preview ID from `process.env`

packages/cloudflare/src/api/overrides/queue/memory-queue.spec.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
import { generateMessageGroupId } from "@opennextjs/aws/core/routing/queue.js";
2-
import { afterEach, beforeAll, describe, expect, it, vi } from "vitest";
2+
import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
33

44
import cache, { DEFAULT_REVALIDATION_TIMEOUT_MS } from "./memory-queue.js";
55

6-
vi.mock("./.next/prerender-manifest.json", () => Promise.resolve({ preview: { previewModeId: "id" } }));
7-
86
const mockServiceWorkerFetch = vi.fn();
97
vi.mock("../../cloudflare-context", () => ({
108
getCloudflareContext: () => ({
@@ -21,11 +19,18 @@ const generateMessageBody = ({ host, url }: { host: string; url: string }) => ({
2119

2220
describe("MemoryQueue", () => {
2321
beforeAll(() => {
24-
vi.useFakeTimers();
2522
globalThis.internalFetch = vi.fn().mockReturnValue(new Promise((res) => setTimeout(() => res(true), 1)));
2623
});
2724

28-
afterEach(() => vi.clearAllMocks());
25+
beforeEach(() => {
26+
vi.useFakeTimers();
27+
vi.stubEnv("NEXT_PREVIEW_MODE_ID", "id");
28+
return () => {
29+
vi.useRealTimers();
30+
vi.unstubAllEnvs();
31+
vi.clearAllMocks();
32+
};
33+
});
2934

3035
it("should process revalidations for a path", async () => {
3136
const firstRequest = cache.send({

packages/cloudflare/src/api/overrides/queue/memory-queue.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,10 @@ export class MemoryQueue implements Queue {
3434
try {
3535
const protocol = host.includes("localhost") ? "http" : "https";
3636

37-
// TODO: Drop the import - https://github.com/opennextjs/opennextjs-cloudflare/issues/361
38-
// @ts-ignore
39-
const manifest = await import("./.next/prerender-manifest.json");
4037
response = await service.fetch(`${protocol}://${host}${url}`, {
4138
method: "HEAD",
4239
headers: {
43-
"x-prerender-revalidate": manifest.preview.previewModeId,
40+
"x-prerender-revalidate": process.env.NEXT_PREVIEW_MODE_ID!,
4441
"x-isr": "1",
4542
},
4643
// We want to timeout the revalidation to avoid hanging the queue

0 commit comments

Comments
 (0)