function HelmetWrapper() {
_classCallCheck(this, HelmetWrapper);
return _possibleConstructorReturn(this, _React$Component.apply(this, arguments));
}n/a
function HelmetWrapper() {
_classCallCheck(this, HelmetWrapper);
return _possibleConstructorReturn(this, _React$Component.apply(this, arguments));
}n/a
function HelmetWrapper() {
_classCallCheck(this, HelmetWrapper);
return _possibleConstructorReturn(this, _React$Component.apply(this, arguments));
}n/a
function peek() {
return state;
}...
<Helmet>
<title>Fancy title</title>
</Helmet>,
container
);
requestIdleCallback(() => {
expect(Helmet.peek().title).to.be.equal("Fancy title");
Helmet.canUseDOM = false;
expect(Helmet.peek().title).to.be.equal("Fancy title");
Helmet.canUseDOM = true;
done();
});
});
...renderStatic = function () {
var mappedState = Component.rewind();
if (!mappedState) {
// provide fallback if mappedState is undefined
mappedState = (0, _HelmetUtils.mapStateOnServer)({
baseTag: [],
bodyAttributes: {},
encodeSpecialCharacters: true,
htmlAttributes: {},
linkTags: [],
metaTags: [],
noscriptTags: [],
scriptTags: [],
styleTags: [],
title: "",
titleAttributes: {}
});
}
return mappedState;
}...
<a name="5.0.0"></a>
# [5.0.0](https://github.com/nfl/react-helmet/compare/4.0.0...v5.0.0) (2017-03-21)
### Features
- New Simplified API (fully backward-compatible) - Helmet now takes plain HTML tags for the majority of the API with just a few
remaining props for Helmet - retaining `titleTemplate`, `defaultTitle`, `onChangeClientState`, and one new - `encodeSpecialCharacters
` - refer to README for details. Directly passing Helmet props will be deprecated in the future. [(#246)](https://github.com/nfl
/react-helmet/pull/246)
- `requestIdleCallback` utilized to consolidate DOM changes and makes these non-blocking for things like animations. Fixes first
client-side render not matching server-side render. Maintains one DOM change between route changes on the client-side as well. [(#
248)](https://github.com/nfl/react-helmet/pull/248)
- On server-side, `Helmet.renderStatic()` aliased to `Helmet.rewind()` for more clarity
. `rewind` will be deprecated in the future.
- Yarn support
# 4.0.0
### Features
- Replacing PlainComponent with stateless functional component `NullComponent`, with a hard requirement to use React 15 or higher
.
...rewind = function () {
var mappedState = Component.rewind();
if (!mappedState) {
// provide fallback if mappedState is undefined
mappedState = (0, _HelmetUtils.mapStateOnServer)({
baseTag: [],
bodyAttributes: {},
encodeSpecialCharacters: true,
htmlAttributes: {},
linkTags: [],
metaTags: [],
noscriptTags: [],
scriptTags: [],
styleTags: [],
title: "",
titleAttributes: {}
});
}
return mappedState;
}...
<a name="5.0.0"></a>
# [5.0.0](https://github.com/nfl/react-helmet/compare/4.0.0...v5.0.0) (2017-03-21)
### Features
- New Simplified API (fully backward-compatible) - Helmet now takes plain HTML tags for the majority of the API with just a few
remaining props for Helmet - retaining `titleTemplate`, `defaultTitle`, `onChangeClientState`, and one new - `encodeSpecialCharacters
` - refer to README for details. Directly passing Helmet props will be deprecated in the future. [(#246)](https://github.com/nfl
/react-helmet/pull/246)
- `requestIdleCallback` utilized to consolidate DOM changes and makes these non-blocking for things like animations. Fixes first
client-side render not matching server-side render. Maintains one DOM change between route changes on the client-side as well. [(#
248)](https://github.com/nfl/react-helmet/pull/248)
- On server-side, `Helmet.renderStatic()` aliased to `Helmet.rewind()` for more clarity
. `rewind` will be deprecated in the future.
- Yarn support
# 4.0.0
### Features
- Replacing PlainComponent with stateless functional component `NullComponent`, with a hard requirement to use React 15 or higher
.
...base = function () { [native code] }n/a
bodyAttributes = function () { [native code] }n/a
children = function () { [native code] }n/a
defaultTitle = function () { [native code] }n/a
encodeSpecialCharacters = function () { [native code] }n/a
htmlAttributes = function () { [native code] }n/a
link = function () { [native code] }n/a
meta = function () { [native code] }n/a
noscript = function () { [native code] }n/a
onChangeClientState = function () { [native code] }n/a
script = function () { [native code] }n/a
style = function () { [native code] }n/a
title = function () { [native code] }n/a
titleAttributes = function () { [native code] }n/a
titleTemplate = function () { [native code] }n/a
function flattenArrayTypeChildren(_ref) {
var _extends2;
var child = _ref.child,
arrayTypeChildren = _ref.arrayTypeChildren,
newChildProps = _ref.newChildProps,
nestedChildren = _ref.nestedChildren;
return _extends({}, arrayTypeChildren, (_extends2 = {}, _extends2[child.type] = [].concat(arrayTypeChildren[child.type] || [], [
_extends({}, newChildProps, this.mapNestedChildrenToProps(child, nestedChildren))]), _extends2));
}...
switch (child.type) {
case TAG_NAMES.LINK:
case TAG_NAMES.META:
case TAG_NAMES.NOSCRIPT:
case TAG_NAMES.SCRIPT:
case TAG_NAMES.STYLE:
arrayTypeChildren = _this2.flattenArrayTypeChildren({
child: child,
arrayTypeChildren: arrayTypeChildren,
newChildProps: newChildProps,
nestedChildren: nestedChildren
});
break;
...function mapArrayTypeChildrenToProps(arrayTypeChildren, newProps) {
var newFlattenedProps = _extends({}, newProps);
Object.keys(arrayTypeChildren).forEach(function (arrayChildName) {
var _extends5;
newFlattenedProps = _extends({}, newFlattenedProps, (_extends5 = {}, _extends5[arrayChildName] = arrayTypeChildren[arrayChildName
], _extends5));
});
return newFlattenedProps;
}...
newChildProps: newChildProps,
nestedChildren: nestedChildren
});
break;
}
});
newProps = this.mapArrayTypeChildrenToProps(arrayTypeChildren, newProps);
return newProps;
};
HelmetWrapper.prototype.render = function render() {
var _props = this.props,
children = _props.children,
props = _objectWithoutProperties(_props, ["children"]);
...function mapChildrenToProps(children, newProps) {
var _this2 = this;
var arrayTypeChildren = {};
_react2.default.Children.forEach(children, function (child) {
if (!child || !child.props) {
return;
}
var _child$props = child.props,
nestedChildren = _child$props.children,
childProps = _objectWithoutProperties(_child$props, ["children"]);
var newChildProps = (0, _HelmetUtils.convertReactPropstoHtmlAttributes)(childProps);
_this2.warnOnInvalidChildren(child, nestedChildren);
switch (child.type) {
case _HelmetConstants.TAG_NAMES.LINK:
case _HelmetConstants.TAG_NAMES.META:
case _HelmetConstants.TAG_NAMES.NOSCRIPT:
case _HelmetConstants.TAG_NAMES.SCRIPT:
case _HelmetConstants.TAG_NAMES.STYLE:
arrayTypeChildren = _this2.flattenArrayTypeChildren({
child: child,
arrayTypeChildren: arrayTypeChildren,
newChildProps: newChildProps,
nestedChildren: nestedChildren
});
break;
default:
newProps = _this2.mapObjectTypeChildren({
child: child,
newProps: newProps,
newChildProps: newChildProps,
nestedChildren: nestedChildren
});
break;
}
});
newProps = this.mapArrayTypeChildrenToProps(arrayTypeChildren, newProps);
return newProps;
}...
var _props = this.props,
children = _props.children,
props = _objectWithoutProperties(_props, ["children"]);
var newProps = _extends({}, props);
if (children) {
newProps = this.mapChildrenToProps(children, newProps);
}
return React.createElement(Component, newProps);
};
_createClass(HelmetWrapper, null, [{
key: "canUseDOM",
...function mapNestedChildrenToProps(child, nestedChildren) {
if (!nestedChildren) {
return null;
}
switch (child.type) {
case _HelmetConstants.TAG_NAMES.SCRIPT:
case _HelmetConstants.TAG_NAMES.NOSCRIPT:
return {
innerHTML: nestedChildren
};
case _HelmetConstants.TAG_NAMES.STYLE:
return {
cssText: nestedChildren
};
}
throw new Error("<" + child.type + " /> elements are self-closing and can not contain children. Refer to our API for more information
.");
}...
var _extends2;
var child = _ref.child,
arrayTypeChildren = _ref.arrayTypeChildren,
newChildProps = _ref.newChildProps,
nestedChildren = _ref.nestedChildren;
return _extends({}, arrayTypeChildren, (_extends2 = {}, _extends2[child.type] = [].concat(arrayTypeChildren[child.type] || [], [
_extends({}, newChildProps, this.mapNestedChildrenToProps(child, nestedChildren))]),
_extends2));
};
HelmetWrapper.prototype.mapObjectTypeChildren = function mapObjectTypeChildren(_ref2) {
var _extends3, _extends4;
var child = _ref2.child,
newProps = _ref2.newProps,
...function mapObjectTypeChildren(_ref2) {
var _extends3, _extends4;
var child = _ref2.child,
newProps = _ref2.newProps,
newChildProps = _ref2.newChildProps,
nestedChildren = _ref2.nestedChildren;
switch (child.type) {
case _HelmetConstants.TAG_NAMES.TITLE:
return _extends({}, newProps, (_extends3 = {}, _extends3[child.type] = nestedChildren, _extends3.titleAttributes = _extends
({}, newChildProps), _extends3));
case _HelmetConstants.TAG_NAMES.BODY:
return _extends({}, newProps, {
bodyAttributes: _extends({}, newChildProps)
});
case _HelmetConstants.TAG_NAMES.HTML:
return _extends({}, newProps, {
htmlAttributes: _extends({}, newChildProps)
});
}
return _extends({}, newProps, (_extends4 = {}, _extends4[child.type] = _extends({}, newChildProps), _extends4));
}...
arrayTypeChildren: arrayTypeChildren,
newChildProps: newChildProps,
nestedChildren: nestedChildren
});
break;
default:
newProps = _this2.mapObjectTypeChildren({
child: child,
newProps: newProps,
newChildProps: newChildProps,
nestedChildren: nestedChildren
});
break;
}
...function render() {
var _props = this.props,
children = _props.children,
props = _objectWithoutProperties(_props, ["children"]);
var newProps = _extends({}, props);
if (children) {
newProps = this.mapChildrenToProps(children, newProps);
}
return _react2.default.createElement(Component, newProps);
}...
afterEach(() => {
ReactDOM.unmountComponentAtNode(container);
});
describe("api", () => {
describe("title", () => {
it("updates page title", (done) => {
ReactDOM.render(
<Helmet
defaultTitle={"Fallback"}
>
<title>Test Title</title>
</Helmet>,
container
);
...function shouldComponentUpdate(nextProps) {
return !(0, _deepEqual2.default)(this.props, nextProps);
}n/a
function warnOnInvalidChildren(child, nestedChildren) {
if (process.env.NODE_ENV !== "production") {
if (!_HelmetConstants.VALID_TAG_NAMES.some(function (name) {
return child.type === name;
})) {
if (typeof child.type === "function") {
return (0, _HelmetUtils.warn)("You may be attempting to nest <Helmet> components within each other, which is not
allowed. Refer to our API for more information.");
}
return (0, _HelmetUtils.warn)("Only elements types " + _HelmetConstants.VALID_TAG_NAMES.join(", ") + " are allowed.
Helmet does not support rendering <" + child.type + "> elements. Refer to our API for more information.");
}
if (nestedChildren && typeof nestedChildren !== "string") {
throw new Error("Helmet expects a string as a child of <" + child.type + ">. Did you forget to wrap your children in
braces? ( <" + child.type + ">{``}</" + child.type + "> ) Refer to our API for more information.");
}
}
return true;
}...
var _child$props = child.props,
nestedChildren = _child$props.children,
childProps = _objectWithoutProperties(_child$props, ["children"]);
var newChildProps = convertReactPropstoHtmlAttributes(childProps);
_this2.warnOnInvalidChildren(child, nestedChildren);
switch (child.type) {
case TAG_NAMES.LINK:
case TAG_NAMES.META:
case TAG_NAMES.NOSCRIPT:
case TAG_NAMES.SCRIPT:
case TAG_NAMES.STYLE:
...function convertReactPropstoHtmlAttributes(props) {
var initAttributes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
return Object.keys(props).reduce(function (obj, key) {
obj[_HelmetConstants.HTML_TAG_MAP[key] || key] = props[key];
return obj;
}, initAttributes);
}n/a
function handleClientStateChange(newState) {
var baseTag = newState.baseTag,
bodyAttributes = newState.bodyAttributes,
htmlAttributes = newState.htmlAttributes,
linkTags = newState.linkTags,
metaTags = newState.metaTags,
noscriptTags = newState.noscriptTags,
onChangeClientState = newState.onChangeClientState,
scriptTags = newState.scriptTags,
styleTags = newState.styleTags,
title = newState.title,
titleAttributes = newState.titleAttributes;
if (_helmetIdleCallback) {
cancelIdleCallback(_helmetIdleCallback);
}
_helmetIdleCallback = requestIdleCallback(function () {
updateAttributes(_HelmetConstants.TAG_NAMES.BODY, bodyAttributes);
updateAttributes(_HelmetConstants.TAG_NAMES.HTML, htmlAttributes);
updateTitle(title, titleAttributes);
var tagUpdates = {
baseTag: updateTags(_HelmetConstants.TAG_NAMES.BASE, baseTag),
linkTags: updateTags(_HelmetConstants.TAG_NAMES.LINK, linkTags),
metaTags: updateTags(_HelmetConstants.TAG_NAMES.META, metaTags),
noscriptTags: updateTags(_HelmetConstants.TAG_NAMES.NOSCRIPT, noscriptTags),
scriptTags: updateTags(_HelmetConstants.TAG_NAMES.SCRIPT, scriptTags),
styleTags: updateTags(_HelmetConstants.TAG_NAMES.STYLE, styleTags)
};
var addedTags = {};
var removedTags = {};
Object.keys(tagUpdates).forEach(function (tagType) {
var _tagUpdates$tagType = tagUpdates[tagType],
newTags = _tagUpdates$tagType.newTags,
oldTags = _tagUpdates$tagType.oldTags;
if (newTags.length) {
addedTags[tagType] = newTags;
}
if (oldTags.length) {
removedTags[tagType] = tagUpdates[tagType].oldTags;
}
});
_helmetIdleCallback = null;
onChangeClientState(newState, addedTags, removedTags);
});
}n/a
function mapStateOnServer(_ref) {
var baseTag = _ref.baseTag,
bodyAttributes = _ref.bodyAttributes,
encode = _ref.encode,
htmlAttributes = _ref.htmlAttributes,
linkTags = _ref.linkTags,
metaTags = _ref.metaTags,
noscriptTags = _ref.noscriptTags,
scriptTags = _ref.scriptTags,
styleTags = _ref.styleTags,
_ref$title = _ref.title,
title = _ref$title === undefined ? "" : _ref$title,
titleAttributes = _ref.titleAttributes;
return {
base: getMethodsForTag(_HelmetConstants.TAG_NAMES.BASE, baseTag, encode),
bodyAttributes: getMethodsForTag(_HelmetConstants.ATTRIBUTE_NAMES.BODY, bodyAttributes, encode),
htmlAttributes: getMethodsForTag(_HelmetConstants.ATTRIBUTE_NAMES.HTML, htmlAttributes, encode),
link: getMethodsForTag(_HelmetConstants.TAG_NAMES.LINK, linkTags, encode),
meta: getMethodsForTag(_HelmetConstants.TAG_NAMES.META, metaTags, encode),
noscript: getMethodsForTag(_HelmetConstants.TAG_NAMES.NOSCRIPT, noscriptTags, encode),
script: getMethodsForTag(_HelmetConstants.TAG_NAMES.SCRIPT, scriptTags, encode),
style: getMethodsForTag(_HelmetConstants.TAG_NAMES.STYLE, styleTags, encode),
title: getMethodsForTag(_HelmetConstants.TAG_NAMES.TITLE, { title: title, titleAttributes: titleAttributes }, encode)
};
}n/a
function reducePropsToState(propsList) {
return {
baseTag: getBaseTagFromPropsList([_HelmetConstants.TAG_PROPERTIES.HREF], propsList),
bodyAttributes: getAttributesFromPropsList(_HelmetConstants.ATTRIBUTE_NAMES.BODY, propsList),
encode: getInnermostProperty(propsList, _HelmetConstants.HELMET_PROPS.ENCODE_SPECIAL_CHARACTERS),
htmlAttributes: getAttributesFromPropsList(_HelmetConstants.ATTRIBUTE_NAMES.HTML, propsList),
linkTags: getTagsFromPropsList(_HelmetConstants.TAG_NAMES.LINK, [_HelmetConstants.TAG_PROPERTIES.REL, _HelmetConstants.TAG_PROPERTIES
.HREF], propsList),
metaTags: getTagsFromPropsList(_HelmetConstants.TAG_NAMES.META, [_HelmetConstants.TAG_PROPERTIES.NAME, _HelmetConstants.
TAG_PROPERTIES.CHARSET, _HelmetConstants.TAG_PROPERTIES.HTTPEQUIV, _HelmetConstants.TAG_PROPERTIES.PROPERTY, _HelmetConstants.TAG_PROPERTIES
.ITEM_PROP], propsList),
noscriptTags: getTagsFromPropsList(_HelmetConstants.TAG_NAMES.NOSCRIPT, [_HelmetConstants.TAG_PROPERTIES.INNER_HTML], propsList
),
onChangeClientState: getOnChangeClientState(propsList),
scriptTags: getTagsFromPropsList(_HelmetConstants.TAG_NAMES.SCRIPT, [_HelmetConstants.TAG_PROPERTIES.SRC, _HelmetConstants
.TAG_PROPERTIES.INNER_HTML], propsList),
styleTags: getTagsFromPropsList(_HelmetConstants.TAG_NAMES.STYLE, [_HelmetConstants.TAG_PROPERTIES.CSS_TEXT], propsList),
title: getTitleFromPropsList(propsList),
titleAttributes: getAttributesFromPropsList(_HelmetConstants.ATTRIBUTE_NAMES.TITLE, propsList)
};
}n/a
requestIdleCallback = function (cb) {
var start = Date.now();
return setTimeout(function () {
cb({
didTimeout: false,
timeRemaining: function timeRemaining() {
return Math.max(0, 50 - (Date.now() - start));
}
});
}, 1);
}n/a
function warn(msg) {
return console && typeof console.warn === "function" && console.warn(msg);
}...
return function (id) {
return clearTimeout(id);
};
}();
var warn = function warn(msg) {
return console && typeof console.warn === "function" && console.warn(msg);
};
var _helmetIdleCallback = null;
var handleClientStateChange = function handleClientStateChange(newState) {
var baseTag = newState.baseTag,
bodyAttributes = newState.bodyAttributes,
...