Skip to content

Commit

Permalink
Don’t render a picture if there is no img src
Browse files Browse the repository at this point in the history
  • Loading branch information
weotch committed Nov 20, 2024
1 parent aafae1f commit f368cb5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/contentful/src/lib/urlBuilding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ export const defaultImageLoader: ImageLoader = ({
src.portraitImage.url :
src.image?.url || src.url

// If no URL found, return nothing
if (!url) return ''

// Make Contentful resizing instructions
const query = new URLSearchParams({ w: String(width) })

Expand Down
1 change: 1 addition & 0 deletions packages/react/src/PictureImage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export default function PictureImage(props: PictureImageProps): ReactNode {

// Make the img src url
const srcUrl = makeSrcUrl(src, imageLoader)
if (!srcUrl) return null

// Make array or props that will be used to make <source>s. A `null` type is
// always added to create fallback sources for native mime-type of the
Expand Down

0 comments on commit f368cb5

Please sign in to comment.