Skip to content

Commit d98ab7e

Browse files
committed
fix: enable using the direct queue for isr
1 parent e939d9f commit d98ab7e

File tree

9 files changed

+36
-16
lines changed

9 files changed

+36
-16
lines changed

.changeset/slimy-houses-punch.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@opennextjs/cloudflare": patch
3+
---
4+
5+
fix: enable using the `direct` queue for isr

examples/e2e/app-router/app/api/isr/route.ts

+13-3
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,21 @@ export const dynamic = "force-dynamic";
88
// This endpoint simulates an on demand revalidation request
99
export async function GET(request: NextRequest) {
1010
const cwd = process.cwd();
11-
const prerenderManifest = await fs.readFile(path.join(cwd, ".next/prerender-manifest.json"), "utf-8");
12-
const manifest = JSON.parse(prerenderManifest);
11+
12+
let manifest;
13+
// this fails at build time when next.js tries to evaluate the route
14+
try {
15+
// @ts-expect-error
16+
const prerenderManifest = await import(/* webpackIgnore: true */ "./.next/prerender-manifest.json");
17+
manifest = prerenderManifest.default;
18+
} catch {
19+
return new Response(null, { status: 500 });
20+
}
21+
1322
const previewId = manifest.preview.previewModeId;
1423

15-
const result = await fetch(`https://${request.headers.get("host")}/isr`, {
24+
const host = request.headers.get("host");
25+
const result = await fetch(`http${host?.includes("localhost") ? "" : "s"}://${host}/isr`, {
1626
headers: { "x-prerender-revalidate": previewId },
1727
method: "HEAD",
1828
});

examples/e2e/app-router/app/page.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export default function Home() {
2222
<Nav href={"/isr"} title="ISR">
2323
Incremental Static Regeneration revalidates every 10 seconds with a new timestamp
2424
</Nav>
25-
<Nav href={"/ssr"} title="SSR">
25+
<Nav href={"/ssr"} title="SSR" prefetch={false}>
2626
Server Side Render should generate a new timestamp on each load. Streaming support for loading...
2727
</Nav>
2828
<Nav href={"/api"} title="API">

examples/e2e/app-router/e2e/isr.revalidate.test.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { expect, test } from "@playwright/test";
22

3-
// Cache (and revalidation) is currently not supported: https://github.com/opennextjs/opennextjs-cloudflare/issues/105
4-
test.skip("Test revalidate", async ({ request }) => {
3+
test("Test revalidate", async ({ request }) => {
54
const result = await request.get("/api/isr");
65

76
expect(result.status()).toEqual(200);

examples/e2e/app-router/e2e/isr.test.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { expect, test } from "@playwright/test";
22

3-
// ISR is currently not supported: https://github.com/opennextjs/opennextjs-cloudflare/issues/105
4-
test.skip("Incremental Static Regeneration", async ({ page }) => {
3+
test("Incremental Static Regeneration", async ({ page }) => {
54
test.setTimeout(45000);
65
await page.goto("/");
76
await page.locator("[href='/isr']").click();
@@ -41,8 +40,7 @@ test.skip("Incremental Static Regeneration", async ({ page }) => {
4140
expect(newTime).not.toEqual(finalTime);
4241
});
4342

44-
// ISR is currently not supported: https://github.com/opennextjs/opennextjs-cloudflare/issues/105
45-
test.skip("headers", async ({ page }) => {
43+
test("headers", async ({ page }) => {
4644
let responsePromise = page.waitForResponse((response) => {
4745
return response.status() === 200;
4846
});

examples/e2e/app-router/open-next.config.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ const config: OpenNextConfig = {
77
wrapper: "cloudflare-node",
88
converter: "edge",
99
incrementalCache: async () => cache,
10+
queue: "direct",
11+
// Unused implementation
1012
tagCache: "dummy",
11-
queue: "dummy",
1213
},
1314
},
1415

examples/e2e/shared/components/Nav/index.tsx

+7-2
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,16 @@ type Props = PropsWithChildren & {
66
href: string;
77
title: string;
88
icon?: string;
9+
prefetch?: boolean;
910
};
1011
export default function Nav(p: Props) {
11-
const { children, href, title, icon = "/static/frank.webp" } = p;
12+
const { children, href, title, icon = "/static/frank.webp", prefetch } = p;
1213
return (
13-
<Link href={href} className="flex flex-col group border p-2 rounded-sm border-orange-500">
14+
<Link
15+
href={href}
16+
className="flex flex-col group border p-2 rounded-sm border-orange-500"
17+
prefetch={prefetch}
18+
>
1419
<div className="flex items-center relative">
1520
<div>{title}</div>
1621
<div>

examples/next-partial-prerendering/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"name": "next-partial-prerendering",
23
"private": true,
34
"scripts": {
45
"build": "next build",

packages/cloudflare/src/cli/build/utils/ensure-cf-config.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ export function ensureCloudflareConfig(config: OpenNextConfig) {
1212
dftMaybeUseCache:
1313
config.default?.override?.incrementalCache === "dummy" ||
1414
typeof config.default?.override?.incrementalCache === "function",
15-
dftUseDummyTagCacheAndQueue:
16-
config.default?.override?.tagCache === "dummy" && config.default?.override?.queue === "dummy",
15+
dftUseDummyTagCache: config.default?.override?.tagCache === "dummy",
16+
dftMaybeUseQueue:
17+
config.default?.override?.queue === "dummy" || config.default?.override?.queue === "direct",
1718
disableCacheInterception: config.dangerous?.enableCacheInterception !== true,
1819
mwIsMiddlewareExternal: config.middleware?.external == true,
1920
mwUseCloudflareWrapper: config.middleware?.override?.wrapper === "cloudflare-edge",
@@ -31,7 +32,7 @@ export function ensureCloudflareConfig(config: OpenNextConfig) {
3132
converter: "edge",
3233
incrementalCache: "dummy" | function,
3334
tagCache: "dummy",
34-
queue: "dummy",
35+
queue: "dummy" | "direct",
3536
},
3637
},
3738

0 commit comments

Comments
 (0)