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
7 changes: 7 additions & 0 deletions .changeset/weak-maps-dress.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@opennextjs/cloudflare": minor
---

Add the `routePreloadingBehavior` to the options of `defineCloudflareConfig`.

The default is set to "none" as other values might increase CPU usage on cold starts.
19 changes: 17 additions & 2 deletions packages/cloudflare/src/api/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
BaseOverride,
LazyLoadedOverride,
OpenNextConfig as AwsOpenNextConfig,
type RoutePreloadingBehavior,
} from "@opennextjs/aws/types/open-next";
import type {
CDNInvalidationHandler,
Expand Down Expand Up @@ -45,6 +46,13 @@ export type CloudflareOverrides = {
* @default false
*/
enableCacheInterception?: boolean;

/**
* Route preloading behavior.
* Using a value other than "none" can result in higher CPU usage on cold starts.
* @default "none"
*/
routePreloadingBehavior?: RoutePreloadingBehavior;
};

/**
Expand All @@ -54,7 +62,14 @@ export type CloudflareOverrides = {
* @returns the OpenNext configuration object
*/
export function defineCloudflareConfig(config: CloudflareOverrides = {}): OpenNextConfig {
const { incrementalCache, tagCache, queue, cachePurge, enableCacheInterception = false } = config;
const {
incrementalCache,
tagCache,
queue,
cachePurge,
enableCacheInterception = false,
routePreloadingBehavior = "none",
} = config;

return {
default: {
Expand All @@ -67,7 +82,7 @@ export function defineCloudflareConfig(config: CloudflareOverrides = {}): OpenNe
queue: resolveQueue(queue),
cdnInvalidation: resolveCdnInvalidation(cachePurge),
},
routePreloadingBehavior: "withWaitUntil",
routePreloadingBehavior,
},
// node:crypto is used to compute cache keys
edgeExternals: ["node:crypto"],
Expand Down