Skip to content
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

Fixes Issue 258 #259

Merged
merged 5 commits into from
Mar 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "react-helmet",
"description": "A document head manager for React",
"version": "5.0.1",
"version": "5.0.2",
"main": "./lib/Helmet.js",
"author": "NFL <engineers@nfl.com>",
"contributors": [
Expand Down
6 changes: 3 additions & 3 deletions src/HelmetUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const getTitleFromPropsList = (propsList) => {

const innermostDefaultTitle = getInnermostProperty(propsList, HELMET_PROPS.DEFAULT_TITLE);

return innermostTitle || innermostDefaultTitle || "";
return innermostTitle || innermostDefaultTitle || undefined;
};

const getOnChangeClientState = (propsList) => {
Expand Down Expand Up @@ -301,7 +301,7 @@ const handleClientStateChange = (newState) => {
};

const updateTitle = (title, attributes) => {
if (document.title !== title) {
if (typeof title === "string" && document.title !== title) {
document.title = title;
}

Expand Down Expand Up @@ -508,7 +508,7 @@ const mapStateOnServer = ({
noscriptTags,
scriptTags,
styleTags,
title,
title = "",
titleAttributes
}) => ({
base: getMethodsForTag(TAG_NAMES.BASE, baseTag, encode),
Expand Down
50 changes: 47 additions & 3 deletions test/HelmetDeclarativeTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,50 @@ describe("Helmet - Declarative API", () => {
done();
});
});

it("retains existing title tag when no title tag is defined", (done) => {
headElement.innerHTML = `<title>Existing Title</title>`;

ReactDOM.render(
<Helmet>
<meta name="keywords" content="stuff" />
</Helmet>,
container
);

requestIdleCallback(() => {
expect(document.title).to.equal("Existing Title");

done();
});
});

it("clears title tag if empty title is defined", (done) => {
ReactDOM.render(
<Helmet>
<title>Existing Title</title>
<meta name="keywords" content="stuff" />
</Helmet>,
container
);

requestIdleCallback(() => {
expect(document.title).to.equal("Existing Title");

ReactDOM.render(
<Helmet>
<title>{" "}</title>
<meta name="keywords" content="stuff" />
</Helmet>,
container
);

requestIdleCallback(() => {
expect(document.title).to.equal("");
done();
});
});
});
});

describe("title attributes", () => {
Expand Down Expand Up @@ -3076,7 +3120,7 @@ describe("Helmet - Declarative API", () => {
<Helmet>
<title>Test Title</title>
<Helmet>
<title>Title you'll never see</title>
<title>Title you will never see</title>
</Helmet>
</Helmet>,
container
Expand All @@ -3102,7 +3146,7 @@ describe("Helmet - Declarative API", () => {
<Helmet>
<title>Test Title</title>
<div>
<title>Title you'll never see</title>
<title>Title you will never see</title>
</div>
</Helmet>,
container
Expand Down Expand Up @@ -3163,7 +3207,7 @@ describe("Helmet - Declarative API", () => {
<Helmet>
<title>Test Title</title>
<script>
<title>Title you'll never see</title>
<title>Title you will never see</title>
</script>
</Helmet>,
container
Expand Down