Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix blur-up preview image not working on initial page load (#14816)
Previously this effect only worked for AJAX-based page loads. This change allows the effect to (mostly) work on initial load when the JS isn't yet loaded. If JS is already loaded then the original behaviour is preserved. This increases the head size by 160 bytes but decreases the size of each image element by 103 bytes. The head is only downloaded on initial page load (not AJAX loads), so if the visitor encounters 2 or more images during their visit then this change was worth it.
- Loading branch information
1 parent
13abb7c
commit c4a7c40
Showing
6 changed files
with
70 additions
and
60 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
/constants.js | ||
/gatsby-browser.js | ||
/gatsby-ssr.js | ||
/index.js | ||
/__tests__/* | ||
tests |
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 |
---|---|---|
@@ -1,3 +1,13 @@ | ||
exports.DEFAULT_OPTIONS = { | ||
maxWidth: 650, | ||
wrapperStyle: ``, | ||
backgroundColor: `white`, | ||
linkImagesToOriginal: true, | ||
showCaptions: false, | ||
withWebp: false, | ||
tracedSVG: false, | ||
} | ||
|
||
exports.imageClass = `gatsby-resp-image-image` | ||
exports.imageWrapperClass = `gatsby-resp-image-wrapper` | ||
exports.imageBackgroundClass = `gatsby-resp-image-background-image` |
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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import React from "react" | ||
|
||
const { imageClass } = require(`./constants`) | ||
|
||
exports.onRenderBody = ({ setHeadComponents }) => { | ||
const style = ` | ||
.${imageClass} { | ||
width: 100%; | ||
height: 100%; | ||
margin: 0; | ||
vertical-align: middle; | ||
position: absolute; | ||
top: 0; | ||
left: 0; | ||
color: transparent; | ||
}` | ||
.replace(/\s*\n\s*/g, ``) | ||
.replace(/: /g, `:`) | ||
.replace(/ \{/g, `{`) | ||
|
||
setHeadComponents([ | ||
<style type="text/css" key="gatsby-remark-images-styles"> | ||
{style} | ||
</style>, | ||
]) | ||
} |
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