diff --git a/e2e-tests/gatsby-image/src/pages/fixed.js b/e2e-tests/gatsby-image/src/pages/fixed.js index cd08e25ef24ca..1194957f1a902 100644 --- a/e2e-tests/gatsby-image/src/pages/fixed.js +++ b/e2e-tests/gatsby-image/src/pages/fixed.js @@ -24,7 +24,7 @@ export const pageQuery = graphql` fruitsFixed: file(relativePath: { eq: "citrus-fruits.jpg" }) { childImageSharp { fixed(width: 500) { - ...GatsbyImageSharpFixed + ...GatsbyImageSharpFixed_withWebp } } } diff --git a/e2e-tests/gatsby-image/src/pages/fluid.js b/e2e-tests/gatsby-image/src/pages/fluid.js index a9796052d7306..76be7bcc666c2 100644 --- a/e2e-tests/gatsby-image/src/pages/fluid.js +++ b/e2e-tests/gatsby-image/src/pages/fluid.js @@ -24,7 +24,7 @@ export const pageQuery = graphql` fruitsFluid: file(relativePath: { eq: "citrus-fruits.jpg" }) { childImageSharp { fluid(maxWidth: 500) { - ...GatsbyImageSharpFluid + ...GatsbyImageSharpFluid_withWebp } } } diff --git a/packages/gatsby-image/README.md b/packages/gatsby-image/README.md index 6a7d7b5ade614..50910978ce1b6 100644 --- a/packages/gatsby-image/README.md +++ b/packages/gatsby-image/README.md @@ -348,3 +348,5 @@ You will need to add it in your graphql query as is shown in the following snipp - Gifs can't be resized the same way as pngs and jpegs, unfortunately—if you try to use a gif with `gatsby-image`, it won't work. For now, the best workaround is to [import the gif directly](/docs/adding-images-fonts-files). +- Lazy loading behavior is dependent on `IntersectionObserver` which is not available + in some fairly common browsers including Safari and IE. A polyfill is recommended. diff --git a/packages/gatsby-image/src/__tests__/__snapshots__/index.js.snap b/packages/gatsby-image/src/__tests__/__snapshots__/index.js.snap index bb686aed4abbc..c8f07e691e644 100644 --- a/packages/gatsby-image/src/__tests__/__snapshots__/index.js.snap +++ b/packages/gatsby-image/src/__tests__/__snapshots__/index.js.snap @@ -22,21 +22,19 @@ exports[` should render fixed size images 1`] = ` srcset="some srcSetWebp" type="image/webp" /> - Alt text for the image @@ -68,20 +66,18 @@ exports[` should render fluid images 1`] = ` srcset="some srcSetWebp" type="image/webp" /> - Alt text for the image diff --git a/packages/gatsby-image/src/__tests__/index.js b/packages/gatsby-image/src/__tests__/index.js index b4843777a2dbe..3a0e3e05508c0 100644 --- a/packages/gatsby-image/src/__tests__/index.js +++ b/packages/gatsby-image/src/__tests__/index.js @@ -58,6 +58,7 @@ describe(``, () => { it(`should have correct src, title and alt attributes`, () => { const imageTag = setup().querySelector(`picture img`) expect(imageTag.getAttribute(`src`)).toEqual(`test_image.jpg`) + expect(imageTag.getAttribute(`srcSet`)).toEqual(`some srcSet`) expect(imageTag.getAttribute(`title`)).toEqual(`Title for the image`) expect(imageTag.getAttribute(`alt`)).toEqual(`Alt text for the image`) }) diff --git a/packages/gatsby-image/src/index.js b/packages/gatsby-image/src/index.js index 0544e9b442729..63c26b7e64b8c 100644 --- a/packages/gatsby-image/src/index.js +++ b/packages/gatsby-image/src/index.js @@ -80,25 +80,26 @@ const noscriptImg = props => { const src = props.src ? `src="${props.src}" ` : `src="" ` // required attribute const sizes = props.sizes ? `sizes="${props.sizes}" ` : `` const srcSetWebp = props.srcSetWebp - ? `` - : `` - const srcSet = props.srcSet - ? `` + ? `` : `` + const srcSet = props.srcSet ? `srcset="${props.srcSet}" ` : `` const title = props.title ? `title="${props.title}" ` : `` const alt = props.alt ? `alt="${props.alt}" ` : `alt="" ` // required attribute const width = props.width ? `width="${props.width}" ` : `` const height = props.height ? `height="${props.height}" ` : `` const opacity = props.opacity ? props.opacity : `1` const transitionDelay = props.transitionDelay ? props.transitionDelay : `0.5s` - return `${srcSetWebp}${srcSet}` + return `${srcSetWebp}` } const Img = React.forwardRef((props, ref) => { - const { style, onLoad, onError, ...otherProps } = props + const { sizes, srcSet, src, style, onLoad, onError, ...otherProps } = props return ( )} - - {alt} )} - -