Skip to content
Draft
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
3 changes: 3 additions & 0 deletions examples/playground15/next.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ const nextConfig: NextConfig = {
},
deploymentId: getDeploymentId(),
trailingSlash: true,
images: {
formats: ["image/avif", "image/webp"],
},
};

export default nextConfig;
5 changes: 4 additions & 1 deletion examples/playground15/wrangler.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,8 @@
"database_id": "db_id",
"database_name": "db_name"
}
]
],
"images": {
"binding": "IMAGES"
}
}
3 changes: 3 additions & 0 deletions packages/cloudflare/src/api/cloudflare-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ declare global {
// Asset binding
ASSETS?: Fetcher;

// Images binding
IMAGES?: ImagesBinding;

// Environment to use when loading Next `.env` files
// Default to "production"
NEXTJS_ENV?: string;
Expand Down
24 changes: 24 additions & 0 deletions packages/cloudflare/src/cli/build/open-next/compile-images.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,25 @@ export async function compileImages(options: BuildOptions) {
: {};

const __IMAGES_REMOTE_PATTERNS__ = JSON.stringify(imagesManifest?.images?.remotePatterns ?? []);
const __IMAGES_LOCAL_PATTERNS_DEFINED__ = JSON.stringify(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this needed given that __IMAGES_LOCAL_PATTERNS__ default to an empty list?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, Next.js treats undefined and an empty list differently

Array.isArray(imagesManifest?.images?.localPatterns)
);
const __IMAGES_LOCAL_PATTERNS__ = JSON.stringify(imagesManifest?.images?.localPatterns ?? []);
const __IMAGES_DEVICE_SIZES__ = JSON.stringify(imagesManifest?.images?.deviceSizes ?? defaultDeviceSizes);
const __IMAGES_IMAGE_SIZES__ = JSON.stringify(imagesManifest?.images?.imageSizes ?? defaultImageSizes);
const __IMAGES_QUALITIES__ = JSON.stringify(imagesManifest?.images?.qualities ?? defaultQualities);
const __IMAGES_FORMATS__ = JSON.stringify(imagesManifest?.images?.formats ?? defaultFormats);
const __IMAGES_MINIMUM_CACHE_TTL__ = JSON.stringify(
imagesManifest?.images?.minimumCacheTTL ?? defaultMinimumCacheTTL
);
const __IMAGES_ALLOW_SVG__ = JSON.stringify(Boolean(imagesManifest?.images?.dangerouslyAllowSVG));
const __IMAGES_CONTENT_SECURITY_POLICY__ = JSON.stringify(
imagesManifest?.images?.contentSecurityPolicy ?? "script-src 'none'; frame-src 'none'; sandbox;"
);
const __IMAGES_CONTENT_DISPOSITION__ = JSON.stringify(
imagesManifest?.images?.contentDispositionType ?? "attachment"
);
const __IMAGES_MAX_REDIRECTS__ = JSON.stringify(imagesManifest?.images?.maximumRedirects ?? 3);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was changed to 3 from unlimited in Next.js 16

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could use unlimited then (and maybe add your comment as a code comment on this file/line)


await build({
entryPoints: [imagesPath],
Expand All @@ -38,10 +49,23 @@ export async function compileImages(options: BuildOptions) {
platform: "node",
define: {
__IMAGES_REMOTE_PATTERNS__,
__IMAGES_LOCAL_PATTERNS_DEFINED__,
__IMAGES_LOCAL_PATTERNS__,
__IMAGES_DEVICE_SIZES__,
__IMAGES_IMAGE_SIZES__,
__IMAGES_QUALITIES__,
__IMAGES_FORMATS__,
__IMAGES_MINIMUM_CACHE_TTL__,
__IMAGES_ALLOW_SVG__,
__IMAGES_CONTENT_SECURITY_POLICY__,
__IMAGES_CONTENT_DISPOSITION__,
__IMAGES_MAX_REDIRECTS__,
},
});
}

const defaultDeviceSizes = [640, 750, 828, 1080, 1200, 1920, 2048, 3840];
const defaultImageSizes = [32, 48, 64, 96, 128, 256, 384];
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before Next.js 16, 16 was also included

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would use Next 16 (and add comments on the lines).

nit: maybe move those constants up (i.e. before they are used)

const defaultQualities = [75];
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before Next.js 16, the default behavior was to allow values from 1-100

const defaultFormats = ["image/webp"];
const defaultMinimumCacheTTL = 14400;
Loading
Loading