Skip to content

Commit 268d982

Browse files
authored
fix(gatsby-image): do not render the source tag if no srcSet is provided (#26766)
1 parent 123b19f commit 268d982

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

packages/gatsby-image/src/__tests__/index.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,4 +369,16 @@ describe(`<Image />`, () => {
369369
const placeholderImageTag = setup().querySelector(`picture img`)
370370
expect(placeholderImageTag.getAttribute(`aria-hidden`)).toBe(null)
371371
})
372+
373+
it(`should not have a "source" tag if no srcSet is provided`, () => {
374+
jest.spyOn(global.console, `warn`)
375+
376+
const props = {
377+
fixed: { ...fixedShapeMock, srcSet: null, srcSetWebp: null },
378+
}
379+
const sourceTag = setup(false, props).querySelector(`source`)
380+
expect(sourceTag).toEqual(null)
381+
382+
expect(console.warn).toBeCalled()
383+
})
372384
})

packages/gatsby-image/src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ function generateImageSources(imageVariants) {
176176
sizes={sizes}
177177
/>
178178
)}
179-
<source media={media} srcSet={srcSet} sizes={sizes} />
179+
{srcSet && <source media={media} srcSet={srcSet} sizes={sizes} />}
180180
</React.Fragment>
181181
))
182182
}

0 commit comments

Comments
 (0)