-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
chore(open-next): apply various improvements #8304
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
dario-piotrowicz
merged 23 commits into
nodejs:main
from
dario-piotrowicz:dario/open-next-improvements
Nov 25, 2025
+276
−196
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
6a8f860
bump wrangler and open-next adapter
dario-piotrowicz 89b6b2f
for the open-next incremental cache use R2 with regional cache instea…
dario-piotrowicz 670e686
add open-next DO queue
dario-piotrowicz 1ef4730
enable open-next cache interception
dario-piotrowicz 6cb2454
add open-next custom image loader
dario-piotrowicz 7436b9f
add inline comment for regional cache
dario-piotrowicz d5fffab
define `OPEN_NEXT_CLOUDFLARE` variable in `next.consstants.mjs`
dario-piotrowicz 12ede14
avoid ternaries in `next.config.mjs`
dario-piotrowicz f137edb
update cloudflare-build-and-deployment
dario-piotrowicz ee80f76
move image-loader file inside cloudflare directory
dario-piotrowicz b114d77
add missing parenthesis
dario-piotrowicz b889f9d
add env variables for R2 cache batch uploads
dario-piotrowicz 10a5ae6
remove extra backtick
dario-piotrowicz 9626161
allow the open-next version of the site to be built using turbo and r…
dario-piotrowicz 9d63850
Bump `@opennextjs/cloudflare` to `1.13.1` and remove no-longer needed…
dario-piotrowicz 5134a76
update image-loader code as suggested
dario-piotrowicz 2a984f8
use arrow functions
dario-piotrowicz d4d116a
move getImagesConfig to its own file
dario-piotrowicz 22df719
add mapping from string urls to URL objects
dario-piotrowicz 5bbe6f7
move cloudflare constant in `next.constants.cloudflare.mjs`
dario-piotrowicz dbf3b69
add brief documentation regarding the cloudflare image loader
dario-piotrowicz 75fad0b
Update apps/site/next.config.mjs
dario-piotrowicz 8b26595
fix linting issues
dario-piotrowicz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
avivkeller marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| import type { ImageLoaderProps } from 'next/image'; | ||
|
|
||
| const normalizeSrc = (src: string) => { | ||
| return src.startsWith('/') ? src.slice(1) : src; | ||
| }; | ||
|
|
||
| export default function cloudflareLoader({ | ||
dario-piotrowicz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| src, | ||
| width, | ||
| quality, | ||
| }: ImageLoaderProps) { | ||
| if (process.env.NODE_ENV === 'development') { | ||
dario-piotrowicz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // Serve the original image when using `next dev` | ||
| return src; | ||
| } | ||
|
|
||
| // Sets the requested width by next/image | ||
| const params = new Map<string, string>(); | ||
|
|
||
| if (width > 0) { | ||
| params.set('width', `${width}`); | ||
| } | ||
|
|
||
| if (quality && quality > 0) { | ||
| params.set('quality', `${quality}`); | ||
| } | ||
|
|
||
| const pathParams = [...params] | ||
| .map(([key, value]) => `${key}=${value}`) | ||
| .join(','); | ||
|
|
||
| return `/cdn-cgi/image/${pathParams}/${normalizeSrc(src)}`; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| 'use strict'; | ||
|
|
||
| /** | ||
| * Whether the build process is targeting the Cloudflare open-next build or not. | ||
| * | ||
| * 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, once it does that remove the manual `OPEN_NEXT_CLOUDFLARE` | ||
| * definition in the package.json script. | ||
| */ | ||
| export const OPEN_NEXT_CLOUDFLARE = process.env.OPEN_NEXT_CLOUDFLARE; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| import { OPEN_NEXT_CLOUDFLARE } from './next.constants.cloudflare.mjs'; | ||
| import { ENABLE_STATIC_EXPORT } from './next.constants.mjs'; | ||
|
|
||
| const remotePatterns = [ | ||
| 'https://avatars.githubusercontent.com/**', | ||
| 'https://bestpractices.coreinfrastructure.org/**', | ||
| 'https://raw.githubusercontent.com/nodejs/**', | ||
| 'https://user-images.githubusercontent.com/**', | ||
| 'https://website-assets.oramasearch.com/**', | ||
| ]; | ||
|
|
||
| export const getImagesConfig = () => { | ||
| if (OPEN_NEXT_CLOUDFLARE) { | ||
| // If we're building for the Cloudflare deployment we want to use the custom cloudflare image loader | ||
| // | ||
| // Important: The custom loader ignores `remotePatterns` as those are configured as allowed source origins | ||
| // (https://developers.cloudflare.com/images/transform-images/sources/) | ||
| // in the Cloudflare dashboard itself instead (to the exact same values present in `remotePatterns` above). | ||
| // | ||
| return { | ||
| loader: 'custom', | ||
| loaderFile: './cloudflare/image-loader.ts', | ||
| }; | ||
| } | ||
|
|
||
| return { | ||
| // We disable image optimisation during static export builds | ||
| unoptimized: ENABLE_STATIC_EXPORT, | ||
| // We add it to the remote pattern for the static images we use from multiple sources | ||
| // to be marked as safe sources (these come from Markdown files) | ||
| remotePatterns: remotePatterns.map(url => new URL(url)), | ||
| }; | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.