Skip to content

Commit 4b31804

Browse files
authored
Check if set(Body|Html)Attributes functions exist before using (#2476)
Since older versions of Gatsby won't have them.
1 parent 6050743 commit 4b31804

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

packages/gatsby-plugin-react-helmet/src/gatsby-ssr.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,13 @@ exports.onRenderBody = (
55
pluginOptions
66
) => {
77
const helmet = Helmet.renderStatic()
8-
setHtmlAttributes(helmet.htmlAttributes.toComponent())
9-
setBodyAttributes(helmet.bodyAttributes.toComponent())
8+
// These action functions were added partway through the Gatsby 1.x cycle.
9+
if (setHtmlAttributes) {
10+
setHtmlAttributes(helmet.htmlAttributes.toComponent())
11+
}
12+
if (setBodyAttributes) {
13+
setBodyAttributes(helmet.bodyAttributes.toComponent())
14+
}
1015
setHeadComponents([
1116
helmet.title.toComponent(),
1217
helmet.link.toComponent(),

packages/gatsby-remark-images/src/__tests__/__snapshots__/index.js.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ exports[`it transforms HTML img tags 1`] = `
66
77
<span class=\\"gatsby-resp-image-wrapper\\" style=\\"position: relative; display: block; ; max-width: 300px; margin-left: auto; margin-right: auto;\\">
88
<span class=\\"gatsby-resp-image-background-image\\" style=\\"padding-bottom: 133.33333333333331%; position: relative; bottom: 0; left: 0; background-image: url(&apos;url(&apos;data:image/png;base64, iVBORw)&apos;); background-size: cover; display: block;\\">
9-
<img class=\\"gatsby-resp-image-image\\" style=\\"width: 100%; margin: 0; vertical-align: middle; position: absolute; top: 0; left: 0; box-shadow: inset 0px 0px 0px 400px white;\\" alt=\\"my image\\" title=\\"\\" src=\\"not-a-real-dir/image/my-image.jpeg\\" srcset=\\"not-a-real-dir/image/my-image.jpeg, not-a-real-dir/image/my-image.jpeg\\" sizes=\\"(max-width: 650px) 100vw, 650px\\">
9+
<img class=\\"gatsby-resp-image-image\\" style=\\"width: 100%; height: 100%; margin: 0; vertical-align: middle; position: absolute; top: 0; left: 0; box-shadow: inset 0px 0px 0px 400px white;\\" alt=\\"my image\\" title=\\"\\" src=\\"not-a-real-dir/image/my-image.jpeg\\" srcset=\\"not-a-real-dir/image/my-image.jpeg, not-a-real-dir/image/my-image.jpeg\\" sizes=\\"(max-width: 650px) 100vw, 650px\\">
1010
</span>
1111
</span>
1212
@@ -34,7 +34,7 @@ exports[`it transforms images in markdown 1`] = `
3434
>
3535
<img
3636
class=\\"gatsby-resp-image-image\\"
37-
style=\\"width: 100%; margin: 0; vertical-align: middle; position: absolute; top: 0; left: 0; box-shadow: inset 0px 0px 0px 400px white;\\"
37+
style=\\"width: 100%; height: 100%; margin: 0; vertical-align: middle; position: absolute; top: 0; left: 0; box-shadow: inset 0px 0px 0px 400px white;\\"
3838
alt=\\"image\\"
3939
title=\\"\\"
4040
src=\\"not-a-real-dir/images/my-image.jpeg\\"

0 commit comments

Comments
 (0)