Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/honest-games-tell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@opennextjs/cloudflare": patch
---

memory queue: retrieve the preview ID from `process.env`
15 changes: 10 additions & 5 deletions packages/cloudflare/src/api/overrides/queue/memory-queue.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { generateMessageGroupId } from "@opennextjs/aws/core/routing/queue.js";
import { afterEach, beforeAll, describe, expect, it, vi } from "vitest";
import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest";

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

vi.mock("./.next/prerender-manifest.json", () => Promise.resolve({ preview: { previewModeId: "id" } }));

const mockServiceWorkerFetch = vi.fn();
vi.mock("../../cloudflare-context", () => ({
getCloudflareContext: () => ({
Expand All @@ -21,11 +19,18 @@ const generateMessageBody = ({ host, url }: { host: string; url: string }) => ({

describe("MemoryQueue", () => {
beforeAll(() => {
vi.useFakeTimers();
globalThis.internalFetch = vi.fn().mockReturnValue(new Promise((res) => setTimeout(() => res(true), 1)));
});

afterEach(() => vi.clearAllMocks());
beforeEach(() => {
vi.useFakeTimers();
vi.stubEnv("NEXT_PREVIEW_MODE_ID", "id");
return () => {
vi.useRealTimers();
vi.unstubAllEnvs();
vi.clearAllMocks();
};
});

it("should process revalidations for a path", async () => {
const firstRequest = cache.send({
Expand Down
5 changes: 1 addition & 4 deletions packages/cloudflare/src/api/overrides/queue/memory-queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,10 @@ export class MemoryQueue implements Queue {
try {
const protocol = host.includes("localhost") ? "http" : "https";

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