Skip to content

Commit 23a2bcb

Browse files
jdcataldopieh
authored andcommitted
fix(gatsby-remark-images-contentful): avoid modifying options when passed by reference (#17880)
1 parent 6a8e697 commit 23a2bcb

File tree

2 files changed

+9
-13
lines changed

2 files changed

+9
-13
lines changed

packages/gatsby-remark-images-contentful/src/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@ module.exports = async (
6161
const optionsHash = createContentDigest(options)
6262

6363
const cacheKey = `remark-images-ctf-${fileName}-${optionsHash}`
64-
let cahedRawHTML = await cache.get(cacheKey)
64+
let cachedRawHTML = await cache.get(cacheKey)
6565

66-
if (cahedRawHTML) {
67-
return cahedRawHTML
66+
if (cachedRawHTML) {
67+
return cachedRawHTML
6868
}
6969
const metaReader = sharp()
7070

packages/gatsby-remark-images-contentful/src/utils/index.js

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,17 @@ const getBase64Img = async url => {
1616

1717
const buildResponsiveSizes = async ({ metadata, imageUrl, options = {} }) => {
1818
const { width, height, density } = metadata
19+
const { sizeByPixelDensity, maxWidth, sizes } = options
1920
const aspectRatio = width / height
2021
const pixelRatio =
21-
options.sizeByPixelDensity && typeof density === `number` && density > 0
22+
sizeByPixelDensity && typeof density === `number` && density > 0
2223
? density / 72
2324
: 1
2425

25-
const presentationWidth = Math.min(
26-
options.maxWidth,
27-
Math.round(width / pixelRatio)
28-
)
26+
const presentationWidth = Math.min(maxWidth, Math.round(width / pixelRatio))
2927
const presentationHeight = Math.round(presentationWidth * (height / width))
30-
31-
if (!options.sizes) {
32-
options.sizes = `(max-width: ${presentationWidth}px) 100vw, ${presentationWidth}px`
33-
}
28+
const sizesQuery =
29+
sizes || `(max-width: ${presentationWidth}px) 100vw, ${presentationWidth}px`
3430

3531
const images = []
3632

@@ -64,7 +60,7 @@ const buildResponsiveSizes = async ({ metadata, imageUrl, options = {} }) => {
6460
srcSet,
6561
webpSrcSet,
6662
src: imageUrl,
67-
sizes: options.sizes,
63+
sizes: sizesQuery,
6864
density,
6965
presentationWidth,
7066
presentationHeight,

0 commit comments

Comments
 (0)