Skip to content
Permalink
Browse files

fix(gatsby-ssr): Added a check for href and src in props before regex…

…p testing them.
  • Loading branch information
itmayziii committed Jun 27, 2019
1 parent 9b59ff5 commit 8eb6565e769872b35b86f7b6d4758b4791a76a57
Showing with 8 additions and 2 deletions.
  1. +6 −0 README.md
  2. +2 −2 src/gatsby-ssr.ts
@@ -13,6 +13,12 @@ but rest knowing that this plugin is currently 100% unit tested. Go ahead and ru
:warning: This plugin should be included last in your `gatsby-config.js` as it relies on [onPreRenderHTML](https://www.gatsbyjs.org/docs/ssr-apis/#onPreRenderHTML)
`replaceHeadComponents` and `replacePostBodyComponents`. :warning:

## Available options (if any)

`exclude`: `string` - Will be used as a regular expression to test whether or not a Gatsby javascript file should be excluded by this plugin. The default behavior is that all Gatsby
javascript files are removed by this plugin, so this option gives you a chance to "exclude them from being excluded :sweat_smile:". A use case for this option is to not remove the
webpack-runtime.js file that Gatsby ships by default in case you have other javascript that relies on that runtime.

## When do I use this plugin?

Use this plugin if you want to remove the javascript that comes out of the box with Gatsby. This is useful if your site is truly a static site with no interactivity or maybe the
@@ -48,7 +48,7 @@ function getHeadComponentsNoJS (headComponents: ReactNode[], pluginOptions: Plug
return true
}

if (pluginOptions.exclude && RegExp(pluginOptions.exclude).test(headComponent.props.href)) {
if (pluginOptions.exclude && headComponent.props.href && RegExp(pluginOptions.exclude).test(headComponent.props.href)) {
return true
}

@@ -72,7 +72,7 @@ function getPostBodyComponentsNoJS (postBodyComponents: ReactNode[], pluginOptio
return true
}

if (pluginOptions.exclude && RegExp(pluginOptions.exclude).test(postBodyComponent.props.src)) {
if (pluginOptions.exclude && postBodyComponent.props.src && RegExp(pluginOptions.exclude).test(postBodyComponent.props.src)) {
return true
}

0 comments on commit 8eb6565

Please sign in to comment.
You can’t perform that action at this time.