diff --git a/packages/contentful/cypress/component/ContentfulVisual.cy.tsx b/packages/contentful/cypress/component/ContentfulVisual.cy.tsx index ffa7e3b..cc5ab49 100644 --- a/packages/contentful/cypress/component/ContentfulVisual.cy.tsx +++ b/packages/contentful/cypress/component/ContentfulVisual.cy.tsx @@ -63,6 +63,9 @@ describe('contentful visual entry props', () => { portraitVideo: null, }} />) + // There should be no vidoes rendered + cy.get("video").should("not.exist"); + // Portrait asset cy.get('img').hasDimensions(VW, VW) cy.get('img').its('[0].currentSrc') @@ -84,6 +87,9 @@ describe('contentful visual entry props', () => { portraitImage: null, }} />) + // There should be no imgs rendered + cy.get('img').should('not.exist') + // Portrait asset cy.get('video').its('[0].currentSrc') .should('contain', portraitVideoAsset.url) diff --git a/packages/contentful/src/lib/urlBuilding.ts b/packages/contentful/src/lib/urlBuilding.ts index cc7d668..40a48c7 100644 --- a/packages/contentful/src/lib/urlBuilding.ts +++ b/packages/contentful/src/lib/urlBuilding.ts @@ -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) }) diff --git a/packages/react/src/PictureImage.tsx b/packages/react/src/PictureImage.tsx index 9c94436..7a9ad9e 100644 --- a/packages/react/src/PictureImage.tsx +++ b/packages/react/src/PictureImage.tsx @@ -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 s. A `null` type is // always added to create fallback sources for native mime-type of the