Skip to content

Commit bc1d243

Browse files
committed
Add the routePreloadingBehavior to the options of defineCloudflareConfig
1 parent 64a10a6 commit bc1d243

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-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: 19 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,15 @@ export type CloudflareOverrides = {
4546
* @default false
4647
*/
4748
enableCacheInterception?: boolean;
49+
50+
/**
51+
* Set the route preloading behavior.
52+
*
53+
* Using a value other than "none" can result in higher CPU usage on cold starts.
54+
*
55+
* @default "none"
56+
*/
57+
routePreloadingBehavior?: RoutePreloadingBehavior;
4858
};
4959

5060
/**
@@ -54,7 +64,14 @@ export type CloudflareOverrides = {
5464
* @returns the OpenNext configuration object
5565
*/
5666
export function defineCloudflareConfig(config: CloudflareOverrides = {}): OpenNextConfig {
57-
const { incrementalCache, tagCache, queue, cachePurge, enableCacheInterception = false } = config;
67+
const {
68+
incrementalCache,
69+
tagCache,
70+
queue,
71+
cachePurge,
72+
enableCacheInterception = false,
73+
routePreloadingBehavior = "none",
74+
} = config;
5875

5976
return {
6077
default: {
@@ -67,7 +84,7 @@ export function defineCloudflareConfig(config: CloudflareOverrides = {}): OpenNe
6784
queue: resolveQueue(queue),
6885
cdnInvalidation: resolveCdnInvalidation(cachePurge),
6986
},
70-
routePreloadingBehavior: "withWaitUntil",
87+
routePreloadingBehavior,
7188
},
7289
// node:crypto is used to compute cache keys
7390
edgeExternals: ["node:crypto"],

0 commit comments

Comments
 (0)