Skip to content

Use OPEN_NEXT_CLOUDFLARE from Cloudflare open-next adapter #8018

@dario-piotrowicz

Description

@dario-piotrowicz

The open-next adapter should introduce an OPEN_NEXT_CLOUDFLARE environment variable that the site should be used to detect when it is targeting Cloudflare as its deploying platform.

Currently this type of detection is done in less ideal ways in a few different places:

// TODO(@avivkeller): When available, use `OPEN_NEXT_CLOUDFLARE` environmen
// variable for detection instead of current method, which will enable better
// tree-shaking.
// Reference: https://github.com/nodejs/nodejs.org/pull/7896#issuecomment-3009480615
engine:
'Cloudflare' in globalThis
? createJavaScriptRegexEngine()
: await createOnigurumaEngine(import('shiki/wasm')),

// If we're building for the Cloudflare deployment we want to set
// an appropriate deploymentId (needed for skew protection)
// TODO: The `OPEN_NEXT_CLOUDFLARE` environment variable is being
// defined in the worker building script, ideally the open-next
// adapter should set it itself when it invokes the Next.js build
// process, onces it does that remove the manual `OPEN_NEXT_CLOUDFLARE`
// definition in the package.json script.
deploymentId: process.env.OPEN_NEXT_CLOUDFLARE
? getDeploymentId()
: undefined,

"cloudflare:build:worker": "OPEN_NEXT_CLOUDFLARE=true opennextjs-cloudflare build",

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    📋 Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions