From 268d9821eae24eed22d84ca060b98dc1aebbee11 Mon Sep 17 00:00:00 2001 From: Anas Date: Thu, 3 Sep 2020 11:40:04 +0100 Subject: [PATCH] fix(gatsby-image): do not render the source tag if no srcSet is provided (#26766) --- packages/gatsby-image/src/__tests__/index.js | 12 ++++++++++++ packages/gatsby-image/src/index.js | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/packages/gatsby-image/src/__tests__/index.js b/packages/gatsby-image/src/__tests__/index.js index 65c17498c6b90..4cce6922b04a0 100644 --- a/packages/gatsby-image/src/__tests__/index.js +++ b/packages/gatsby-image/src/__tests__/index.js @@ -369,4 +369,16 @@ describe(``, () => { const placeholderImageTag = setup().querySelector(`picture img`) expect(placeholderImageTag.getAttribute(`aria-hidden`)).toBe(null) }) + + it(`should not have a "source" tag if no srcSet is provided`, () => { + jest.spyOn(global.console, `warn`) + + const props = { + fixed: { ...fixedShapeMock, srcSet: null, srcSetWebp: null }, + } + const sourceTag = setup(false, props).querySelector(`source`) + expect(sourceTag).toEqual(null) + + expect(console.warn).toBeCalled() + }) }) diff --git a/packages/gatsby-image/src/index.js b/packages/gatsby-image/src/index.js index 22683f923ccde..4c9e43812928b 100644 --- a/packages/gatsby-image/src/index.js +++ b/packages/gatsby-image/src/index.js @@ -176,7 +176,7 @@ function generateImageSources(imageVariants) { sizes={sizes} /> )} - + {srcSet && } )) }