Skip to content

Commit

Permalink
add localPatterns to next/legacy/image
Browse files Browse the repository at this point in the history
  • Loading branch information
styfle committed Oct 1, 2024
1 parent dac699b commit 246d0c2
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions packages/next/src/client/legacy/image.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,25 @@ function defaultLoader({
)
}

if (src.startsWith('/') && config.localPatterns) {
if (
process.env.NODE_ENV !== 'test' &&
// micromatch isn't compatible with edge runtime
process.env.NEXT_RUNTIME !== 'edge'
) {
// We use dynamic require because this should only error in development
const {
hasLocalMatch,
} = require('../../shared/lib/match-local-pattern')
if (!hasLocalMatch(config.localPatterns, src)) {
throw new Error(
`Invalid src prop (${src}) on \`next/image\` does not match \`images.localPatterns\` configured in your \`next.config.js\`\n` +
`See more info: https://nextjs.org/docs/messages/next-image-unconfigured-localpatterns`
)
}
}
}

if (!src.startsWith('/') && (config.domains || config.remotePatterns)) {
let parsedSrc: URL
try {
Expand Down

0 comments on commit 246d0c2

Please sign in to comment.