From 4a60765289b1750081952473c8fd31df9f32b1e3 Mon Sep 17 00:00:00 2001 From: Richard Herrera Date: Fri, 24 Mar 2017 16:14:27 -0700 Subject: [PATCH] fix(#255): handle falsy children values (#256) --- src/Helmet.js | 4 ++++ test/HelmetDeclarativeTest.js | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/Helmet.js b/src/Helmet.js index 8dd32975..0d3640d2 100644 --- a/src/Helmet.js +++ b/src/Helmet.js @@ -198,6 +198,10 @@ const Helmet = (Component) => class HelmetWrapper extends React.Component { let arrayTypeChildren = {}; React.Children.forEach(children, (child) => { + if (!child || !child.props) { + return; + } + const {children: nestedChildren, ...childProps} = child.props; const newChildProps = convertReactPropstoHtmlAttributes(childProps); diff --git a/test/HelmetDeclarativeTest.js b/test/HelmetDeclarativeTest.js index 04087ea5..faede73b 100644 --- a/test/HelmetDeclarativeTest.js +++ b/test/HelmetDeclarativeTest.js @@ -3173,6 +3173,24 @@ describe("Helmet - Declarative API", () => { expect(renderInvalid).to.throw(Error, "Helmet expects a string as a child of ) Refer to our API for more information."); }); + it("handles undefined children", (done) => { + const charSet = undefined; + + ReactDOM.render( + + {charSet && } + Test Title + , + container + ); + + requestIdleCallback(() => { + expect(document.title).to.equal("Test Title"); + + done(); + }); + }); + it("recognizes valid tags regardless of attribute ordering", (done) => { ReactDOM.render(