Skip to content

Commit

Permalink
Fixed mistakenly removed loading prop validation for image component
Browse files Browse the repository at this point in the history
  • Loading branch information
atcastle committed Jan 5, 2021
1 parent 60a0415 commit d126aad
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions packages/next/client/image.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
ImageConfig,
imageConfigDefault,
LoaderValue,
VALID_LOADERS,
} from '../next-server/server/image-config'
import { useIntersection } from './use-intersection'

Expand Down Expand Up @@ -174,15 +173,11 @@ function getInt(x: unknown): number | undefined {
}

function defaultImageLoader(loaderProps: ImageLoaderProps) {
const load = loaders.get(configLoader)
if (!load) {
throw new Error(
`Unknown "loader" found in "next.config.js". Expected: ${VALID_LOADERS.join(
', '
)}. Received: ${configLoader}`
)
}

// Can disregard case with configLoader not in loaders list because
// that's checked for in config.ts
const load = loaders.get(configLoader) as (
props: DefaultImageLoaderProps
) => string
return load({ root: configPath, ...loaderProps })
}

Expand Down Expand Up @@ -231,6 +226,13 @@ export default function Image({
).join(',')}.`
)
}
if (!VALID_LOADING_VALUES.includes(loading)) {
throw new Error(
`Image with src "${src}" has invalid "loading" property. Provided "${loading}" should be one of ${VALID_LOADING_VALUES.map(
String
).join(',')}.`
)
}
if (priority && loading === 'lazy') {
throw new Error(
`Image with src "${src}" has both "priority" and "loading='lazy'" properties. Only one should be used.`
Expand Down

0 comments on commit d126aad

Please sign in to comment.