Skip to content

Commit

Permalink
fix(gatsby-pugin-typography): headerComponents is now tolerant to nul…
Browse files Browse the repository at this point in the history
…l 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
  • Loading branch information
danielkov authored and pieh committed Mar 13, 2019
1 parent 95155e0 commit a02ef30
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
20 changes: 20 additions & 0 deletions packages/gatsby-plugin-typography/src/__tests__/gatsby-ssr.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,24 @@ describe(`onPreRenderHTML`, () => {

expect(spies.replaceHeadComponents).toHaveBeenCalledWith(components)
})

it(`does not fail when head components include null`, () => {
const components = [
{
key: `link-1234`,
},
{
key: `link-preload`,
},
{
key: `_____01234_____`,
},
null,
]

const spies = setup(clone(components))

expect(spies.replaceHeadComponents).toHaveBeenCalledWith(components)
expect(spies.replaceHeadComponents).toHaveReturned()
})
})
4 changes: 2 additions & 2 deletions packages/gatsby-plugin-typography/src/gatsby-ssr.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ exports.onRenderBody = ({ setHeadComponents }, pluginOptions) => {
exports.onPreRenderHTML = ({ getHeadComponents, replaceHeadComponents }) => {
const headComponents = getHeadComponents()
headComponents.sort((x, y) => {
if (x.key === `TypographyStyle`) {
if (x && x.key === `TypographyStyle`) {
return -1
} else if (y.key === `TypographyStyle`) {
} else if (y && y.key === `TypographyStyle`) {
return 1
}
return 0
Expand Down

0 comments on commit a02ef30

Please sign in to comment.