Skip to content

Commit

Permalink
fix(gatsby-image): do not render the source tag if no srcSet is provi…
Browse files Browse the repository at this point in the history
…ded (#26766)
  • Loading branch information
anasbouzid authored Sep 3, 2020
1 parent 123b19f commit 268d982
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
12 changes: 12 additions & 0 deletions packages/gatsby-image/src/__tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -369,4 +369,16 @@ describe(`<Image />`, () => {
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()
})
})
2 changes: 1 addition & 1 deletion packages/gatsby-image/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ function generateImageSources(imageVariants) {
sizes={sizes}
/>
)}
<source media={media} srcSet={srcSet} sizes={sizes} />
{srcSet && <source media={media} srcSet={srcSet} sizes={sizes} />}
</React.Fragment>
))
}
Expand Down

0 comments on commit 268d982

Please sign in to comment.