From 794b4fd452bf3e24a98014ca8094fa5f2568f4d7 Mon Sep 17 00:00:00 2001 From: Daniel Emod Kovacs Date: Wed, 13 Mar 2019 19:53:10 +0100 Subject: [PATCH] Closes #12549 gatsby-pugin-typography is now tolerant to null values in head components --- .../src/__tests__/gatsby-ssr.js | 20 +++++++++++++++++++ .../src/gatsby-ssr.js | 4 ++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/packages/gatsby-plugin-typography/src/__tests__/gatsby-ssr.js b/packages/gatsby-plugin-typography/src/__tests__/gatsby-ssr.js index 2bb0e086e218f..75e00384ef0d1 100644 --- a/packages/gatsby-plugin-typography/src/__tests__/gatsby-ssr.js +++ b/packages/gatsby-plugin-typography/src/__tests__/gatsby-ssr.js @@ -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() + }) }) diff --git a/packages/gatsby-plugin-typography/src/gatsby-ssr.js b/packages/gatsby-plugin-typography/src/gatsby-ssr.js index b0156b076f51a..e654ecf3643f5 100644 --- a/packages/gatsby-plugin-typography/src/gatsby-ssr.js +++ b/packages/gatsby-plugin-typography/src/gatsby-ssr.js @@ -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