-
Notifications
You must be signed in to change notification settings - Fork 10.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[gatsby-plugin-typography] fails to compile when headerComponents include null #12549
Comments
While this is is valid In gatsby/packages/gatsby/cache-dir/static-entry.js Lines 71 to 111 in 95155e0
We could add utility const removeNulls = components => {
if (Array.isArray(components)) {
// remove falsy items
return components.filter(val => val)
} else {
// we also accept single components, so we need to handle this case as well
return components ? [components] : []
}
} And then adjust const setHeadComponents = components => {
- headComponents = headComponents.concat(components)
+ headComponents = headComponents.concat(removeNulls(components))
} and const replacePostBodyComponents = components => {
- postBodyComponents = components
+ postBodyComponents = removeNulls(components)
}
That would be great too. As mentioned above this list ideally is sanitized already, but some sanity checks won't hurt |
I've approached it from the plugin side - as it targets this particular issue - and added fault tolerancy and tests. |
Description
After upgrading from
v1
tov2
following the official guide I am witnessing the following issue:I realise this is because in the following method:
the value of
headComponents
isReact.ReactNode[]
, which can includenull
as valid values. In my project one of the other plugins injects anull
into this array, which shouldn't cause an issue to this plugin in my opinion.Steps to reproduce
gatsby-plugin-typography
to plugins array.null
in the headers in some way (e.g.: inside<Helmet/>
.develop || build
.Expected result
It should tolerate
null
and build normally.Actual result
TypeError: Cannot read property 'key' of null
Environment
System: OS: macOS 10.14.4 CPU: (8) x64 Intel(R) Core(TM) i7-7820HQ CPU @ 2.90GHz Shell: 5.3 - /bin/zsh Binaries: Node: 11.10.0 - /var/folders/r5/9r6yq3695tqgy0z3bswzxn8h0000gn/T/yarn--1552498926309-0.6699258377655932/node Yarn: 1.13.0 - /var/folders/r5/9r6yq3695tqgy0z3bswzxn8h0000gn/T/yarn--1552498926309-0.6699258377655932/yarn npm: 5.7.1 - /usr/local/bin/npm Languages: Python: 2.7.10 - /usr/bin/python Browsers: Chrome: 72.0.3626.121 Firefox: 61.0.2 Safari: 12.1 npmPackages: gatsby: 2.1.31 => 2.1.31 gatsby-plugin-catch-links: 2.0.13 => 2.0.13 gatsby-plugin-feed: 2.0.15 => 2.0.15 gatsby-plugin-google-analytics: 2.0.17 => 2.0.17 gatsby-plugin-manifest: 2.0.24 => 2.0.24 gatsby-plugin-netlify: 2.0.12 => 2.0.12 gatsby-plugin-nprogress: 2.0.10 => 2.0.10 gatsby-plugin-offline: 2.0.25 => 2.0.25 gatsby-plugin-react-helmet: 3.0.9 => 3.0.9 gatsby-plugin-sharp: ^2.0.28 => 2.0.28 gatsby-plugin-sitemap: 2.0.9 => 2.0.9 gatsby-plugin-styletron: 3.0.5 => 3.0.5 gatsby-plugin-typography: 2.2.9 => 2.2.9 gatsby-remark-autolink-headers: 2.0.16 => 2.0.16 gatsby-remark-copy-linked-files: 2.0.10 => 2.0.10 gatsby-remark-emoji: 0.0.2 => 0.0.2 gatsby-remark-images: 3.0.9 => 3.0.9 gatsby-remark-prismjs: 3.2.5 => 3.2.5 gatsby-remark-responsive-iframe: 2.0.10 => 2.0.10 gatsby-remark-smartypants: 2.0.9 => 2.0.9 gatsby-source-filesystem: 2.0.24 => 2.0.24 gatsby-transformer-remark: 2.3.2 => 2.3.2
Summary
When headers contain
null
gatsby-plugin-typography
fails to process headers when moving typography related header components to the top.I can create a PR with a simple null check fix if that's ok, unless this is the correct behaviour.
The text was updated successfully, but these errors were encountered: