Skip to content

Commit

Permalink
stop appending empty title tags
Browse files Browse the repository at this point in the history
  • Loading branch information
marvinjude authored and me4502 committed Aug 4, 2022
1 parent 6933a35 commit a9fd8ea
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
20 changes: 16 additions & 4 deletions gatsby-ssr.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
"use strict";
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Expand All @@ -8,19 +17,22 @@ var react_1 = __importDefault(require("react"));
var react_helmet_async_1 = require("react-helmet-async");
var context = {};
var onRenderBody = function (_a) {
var _b;
var setHeadComponents = _a.setHeadComponents, setHtmlAttributes = _a.setHtmlAttributes, setBodyAttributes = _a.setBodyAttributes;
var helmet = context.helmet;
if (helmet) {
setHeadComponents([
helmet.base.toComponent(),
helmet.title.toComponent(),
var baseComponent = helmet.base.toComponent();
var titleComponent = helmet.title.toComponent();
var components = [
helmet.priority.toComponent(),
helmet.meta.toComponent(),
helmet.link.toComponent(),
helmet.style.toComponent(),
helmet.script.toComponent(),
helmet.noscript.toComponent()
]);
];
setHeadComponents(((_b = titleComponent[0]) === null || _b === void 0 ? void 0 : _b.props.children)
? __spreadArray([baseComponent, titleComponent], components, true) : __spreadArray([baseComponent], components, true));
setHtmlAttributes(helmet.htmlAttributes.toComponent());
setBodyAttributes(helmet.bodyAttributes.toComponent());
}
Expand Down
15 changes: 11 additions & 4 deletions src/gatsby-ssr.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,23 @@ export const onRenderBody: GatsbySSR['onRenderBody'] = ({
const { helmet } = context;

if (helmet) {
setHeadComponents([
helmet.base.toComponent(),
helmet.title.toComponent(),
const baseComponent = helmet.base.toComponent();
const titleComponent = helmet.title.toComponent() as unknown as any[];
const components = [
helmet.priority.toComponent(),
helmet.meta.toComponent(),
helmet.link.toComponent(),
helmet.style.toComponent(),
helmet.script.toComponent(),
helmet.noscript.toComponent()
]);
];

setHeadComponents(
titleComponent[0]?.props.children
? [baseComponent, titleComponent, ...components]
: [baseComponent, ...components]
);

setHtmlAttributes(helmet.htmlAttributes.toComponent());
setBodyAttributes(helmet.bodyAttributes.toComponent());
}
Expand Down

0 comments on commit a9fd8ea

Please sign in to comment.