Skip to content

Commit a02ef30

Browse files
danielkovpieh
authored andcommitted
fix(gatsby-pugin-typography): headerComponents is now tolerant to null values (#12551)
## Description As of right now null values may occur in `headerComponents`. This commit makes the typography plugin tolerant to these occurrences with simple null check. ## Related Issues Fixes #12549
1 parent 95155e0 commit a02ef30

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

packages/gatsby-plugin-typography/src/__tests__/gatsby-ssr.js

+20
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,24 @@ describe(`onPreRenderHTML`, () => {
100100

101101
expect(spies.replaceHeadComponents).toHaveBeenCalledWith(components)
102102
})
103+
104+
it(`does not fail when head components include null`, () => {
105+
const components = [
106+
{
107+
key: `link-1234`,
108+
},
109+
{
110+
key: `link-preload`,
111+
},
112+
{
113+
key: `_____01234_____`,
114+
},
115+
null,
116+
]
117+
118+
const spies = setup(clone(components))
119+
120+
expect(spies.replaceHeadComponents).toHaveBeenCalledWith(components)
121+
expect(spies.replaceHeadComponents).toHaveReturned()
122+
})
103123
})

packages/gatsby-plugin-typography/src/gatsby-ssr.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ exports.onRenderBody = ({ setHeadComponents }, pluginOptions) => {
2424
exports.onPreRenderHTML = ({ getHeadComponents, replaceHeadComponents }) => {
2525
const headComponents = getHeadComponents()
2626
headComponents.sort((x, y) => {
27-
if (x.key === `TypographyStyle`) {
27+
if (x && x.key === `TypographyStyle`) {
2828
return -1
29-
} else if (y.key === `TypographyStyle`) {
29+
} else if (y && y.key === `TypographyStyle`) {
3030
return 1
3131
}
3232
return 0

0 commit comments

Comments
 (0)