-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(gatsby-image): Safari Downloading multiple resolutions
Safari browser (Safari 12 / Mac OS) downloads multiple assets for a single `Img` tag. The observed behavior is that the attributes of the `img` tag are queued early in the parsing of the document. Resolved by removing the fallback `<source>` and placing those value back into the `<img>` tag. Additionally the order of the attributes of `img` are important as well. If `src` preceeds `srcSet` in the `<img>` Safari’s Pre-parser will enqueue both images to download. Finally - added a note regarding a dependency on IntersectionObserver for lazy-loading
- Loading branch information
Todd Brannam
committed
Feb 20, 2019
1 parent
d33b3ec
commit d909ded
Showing
6 changed files
with
21 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
? `<source type='image/webp' srcSet="${props.srcSetWebp}" ${sizes}/>` | ||
: `` | ||
const srcSet = props.srcSet | ||
? `<source srcSet="${props.srcSet}" ${sizes}/>` | ||
? `<source type='image/webp' srcset="${props.srcSetWebp}" ${sizes}/>` | ||
: `` | ||
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 `<picture>${srcSetWebp}${srcSet}<img ${width}${height}${src}${alt}${title}style="position:absolute;top:0;left:0;transition:opacity 0.5s;transition-delay:${transitionDelay};opacity:${opacity};width:100%;height:100%;object-fit:cover;object-position:center"/></picture>` | ||
return `<picture>${srcSetWebp}<img ${width}${height}${sizes}${srcSet}${src}${alt}${title}style="position:absolute;top:0;left:0;transition:opacity 0.5s;transition-delay:${transitionDelay};opacity:${opacity};width:100%;height:100%;object-fit:cover;object-position:center"/></picture>` | ||
} | ||
|
||
const Img = React.forwardRef((props, ref) => { | ||
const { style, onLoad, onError, ...otherProps } = props | ||
const { sizes, srcSet, src, style, onLoad, onError, ...otherProps } = props | ||
|
||
return ( | ||
<img | ||
sizes={sizes} | ||
srcSet={srcSet} | ||
This comment has been minimized.
Sorry, something went wrong.
tbrannam
Contributor
|
||
src={src} | ||
{...otherProps} | ||
onLoad={onLoad} | ||
onError={onError} | ||
|
@@ -315,12 +316,12 @@ class Image extends React.Component { | |
/> | ||
)} | ||
|
||
<source srcSet={image.srcSet} sizes={image.sizes} /> | ||
|
||
<Img | ||
alt={alt} | ||
title={title} | ||
sizes={image.sizes} | ||
src={image.src} | ||
srcSet={image.srcSet} | ||
style={imageStyle} | ||
ref={this.imageRef} | ||
onLoad={this.handleImageLoaded} | ||
|
@@ -399,14 +400,14 @@ class Image extends React.Component { | |
/> | ||
)} | ||
|
||
<source srcSet={image.srcSet} sizes={image.sizes} /> | ||
|
||
<Img | ||
alt={alt} | ||
title={title} | ||
width={image.width} | ||
height={image.height} | ||
sizes={image.sizes} | ||
src={image.src} | ||
srcSet={image.srcSet} | ||
style={imageStyle} | ||
ref={this.imageRef} | ||
onLoad={this.handleImageLoaded} | ||
|
added withWebp to force a source to continue to be generated to satisfy e2e tests