Skip to content

Commit 78131d0

Browse files
committed
WIP
1 parent 2c7d3eb commit 78131d0

File tree

4 files changed

+63
-1
lines changed

4 files changed

+63
-1
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
'use server';
2+
3+
// eslint-disable-next-line @typescript-eslint/no-restricted-imports
4+
import NextImage, { ImageProps } from 'next/image';
5+
6+
import { buildConfig } from '~/build-config/reader';
7+
import bcCdnImageLoader from '~/lib/cdn-image-loader';
8+
9+
function shouldUseLoaderProp(props: ImageProps): boolean {
10+
if (typeof props.src !== 'string') return false;
11+
12+
const { src } = props;
13+
14+
return buildConfig.get('urls').cdnUrls.some((cdn) => src.startsWith(`https://${cdn}`));
15+
}
16+
17+
/**
18+
* This component should be used in place of Next's `Image` component for images from the
19+
* BigCommerce platform, which will reduce load on the Next.js application for image assets.
20+
*
21+
* It defaults to use the default loader in Next.js if it's an image not from the BigCommerce CDN.
22+
*
23+
* @returns {React.ReactElement} The `<Image>` component
24+
*/
25+
export const Image = ({ ...props }: ImageProps) => {
26+
const loader = shouldUseLoaderProp(props) ? bcCdnImageLoader : undefined;
27+
28+
return <NextImage loader={loader} {...props} />;
29+
};

core/next.config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { writeBuildConfig } from './build-config/writer';
66
import { client } from './client';
77
import { graphql } from './client/graphql';
88
import { cspHeader } from './lib/content-security-policy';
9+
import withPlaiceholder from "@plaiceholder/next";
910

1011
const withNextIntl = createNextIntlPlugin({
1112
experimental: {
@@ -113,6 +114,9 @@ export default async (): Promise<NextConfig> => {
113114
// Apply withNextIntl to the config
114115
nextConfig = withNextIntl(nextConfig);
115116

117+
// Apply withPlaiceholder to the config
118+
nextConfig = withPlaiceholder(nextConfig);
119+
116120
if (process.env.ANALYZE === 'true') {
117121
const withBundleAnalyzer = bundleAnalyzer();
118122

core/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"@conform-to/react": "^1.6.1",
1818
"@conform-to/zod": "^1.6.1",
1919
"@icons-pack/react-simple-icons": "^11.2.0",
20+
"@plaiceholder/next": "^3.0.0",
2021
"@radix-ui/react-accordion": "^1.2.11",
2122
"@radix-ui/react-checkbox": "^1.3.2",
2223
"@radix-ui/react-dialog": "^1.1.14",
@@ -55,6 +56,7 @@
5556
"next-intl": "^4.1.0",
5657
"nuqs": "^2.4.3",
5758
"p-lazy": "^5.0.0",
59+
"plaiceholder": "^3.0.0",
5860
"react": "^19.1.0",
5961
"react-day-picker": "^9.7.0",
6062
"react-dom": "^19.1.0",

pnpm-lock.yaml

Lines changed: 28 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)