Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
8 changes: 8 additions & 0 deletions .changeset/lovely-rooms-taste.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@opennextjs/cloudflare": patch
---

some performance improvements

- `enableCacheInterception` is now enabled by default, it loads ISR/SSG pages from cache without waiting for the js page bundle to load
- `routePreloadingBehavior` is now set to `withWaitUntil`, which means a single route js will be lazy loaded on cold start, but other routes will be preloaded using `waitUntil` for better performance
2 changes: 2 additions & 0 deletions examples/e2e/experimental/open-next.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ export default defineCloudflareConfig({
},
}),
queue: doQueue,
// Cache interception will break PPR
enableCacheInterception: false,
});
2 changes: 2 additions & 0 deletions examples/e2e/pages-router/open-next.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ import memoryQueue from "@opennextjs/cloudflare/overrides/queue/memory-queue";
export default defineCloudflareConfig({
incrementalCache: r2IncrementalCache,
queue: memoryQueue,
// We disable it because it breaks an e2e test that checks for the `x-powered-by` header
enableCacheInterception: false,
});
4 changes: 3 additions & 1 deletion examples/next-partial-prerendering/open-next.config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { defineCloudflareConfig } from '@opennextjs/cloudflare/config';

export default defineCloudflareConfig();
export default defineCloudflareConfig({
enableCacheInterception: false,
});
13 changes: 12 additions & 1 deletion packages/cloudflare/src/api/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ export type CloudflareOverrides = {
* Sets the revalidation queue implementation
*/
queue?: "direct" | Override<Queue>;

/**
* Enable cache interception
* Disable this if you want to use PPR
* @default true
*/
enableCacheInterception?: boolean;
};

/**
Expand All @@ -37,7 +44,7 @@ export type CloudflareOverrides = {
* @returns the OpenNext configuration object
*/
export function defineCloudflareConfig(config: CloudflareOverrides = {}): OpenNextConfig {
const { incrementalCache, tagCache, queue } = config;
const { incrementalCache, tagCache, queue, enableCacheInterception = true } = config;

return {
default: {
Expand All @@ -49,12 +56,16 @@ export function defineCloudflareConfig(config: CloudflareOverrides = {}): OpenNe
tagCache: resolveTagCache(tagCache),
queue: resolveQueue(queue),
},
routePreloadingBehavior: "withWaitUntil",
},
// node:crypto is used to compute cache keys
edgeExternals: ["node:crypto"],
cloudflare: {
useWorkerdCondition: true,
},
dangerous: {
enableCacheInterception,
},
};
}

Expand Down
Loading