Skip to content

Commit de6a6cd

Browse files
authored
Add the routePreloadingBehavior to the options of defineCloudflareConfig (#696)
1 parent 903ad45 commit de6a6cd

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

.changeset/weak-maps-dress.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@opennextjs/cloudflare": minor
3+
---
4+
5+
Add the `routePreloadingBehavior` to the options of `defineCloudflareConfig`.
6+
7+
The default is set to "none" as other values might increase CPU usage on cold starts.

packages/cloudflare/src/api/config.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
BaseOverride,
44
LazyLoadedOverride,
55
OpenNextConfig as AwsOpenNextConfig,
6+
type RoutePreloadingBehavior,
67
} from "@opennextjs/aws/types/open-next";
78
import type {
89
CDNInvalidationHandler,
@@ -45,6 +46,13 @@ export type CloudflareOverrides = {
4546
* @default false
4647
*/
4748
enableCacheInterception?: boolean;
49+
50+
/**
51+
* Route preloading behavior.
52+
* Using a value other than "none" can result in higher CPU usage on cold starts.
53+
* @default "none"
54+
*/
55+
routePreloadingBehavior?: RoutePreloadingBehavior;
4856
};
4957

5058
/**
@@ -54,7 +62,14 @@ export type CloudflareOverrides = {
5462
* @returns the OpenNext configuration object
5563
*/
5664
export function defineCloudflareConfig(config: CloudflareOverrides = {}): OpenNextConfig {
57-
const { incrementalCache, tagCache, queue, cachePurge, enableCacheInterception = false } = config;
65+
const {
66+
incrementalCache,
67+
tagCache,
68+
queue,
69+
cachePurge,
70+
enableCacheInterception = false,
71+
routePreloadingBehavior = "none",
72+
} = config;
5873

5974
return {
6075
default: {
@@ -67,7 +82,7 @@ export function defineCloudflareConfig(config: CloudflareOverrides = {}): OpenNe
6782
queue: resolveQueue(queue),
6883
cdnInvalidation: resolveCdnInvalidation(cachePurge),
6984
},
70-
routePreloadingBehavior: "withWaitUntil",
85+
routePreloadingBehavior,
7186
},
7287
// node:crypto is used to compute cache keys
7388
edgeExternals: ["node:crypto"],

0 commit comments

Comments
 (0)