Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-helmet-async

Package Overview
Dependencies
Maintainers
1
Versions
57
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-helmet-async - npm Package Compare versions

Comparing version 0.1.0 to 0.2.0-beta.0

.circleci/config.yml

59

es/Dispatcher.js

@@ -7,2 +7,4 @@ 'use strict';

var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

@@ -42,8 +44,35 @@

function Dispatcher() {
var _ref;
var _temp, _this, _ret;
_classCallCheck(this, Dispatcher);
return _possibleConstructorReturn(this, (Dispatcher.__proto__ || Object.getPrototypeOf(Dispatcher)).apply(this, arguments));
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = Dispatcher.__proto__ || Object.getPrototypeOf(Dispatcher)).call.apply(_ref, [this].concat(args))), _this), _this.rendered = false, _temp), _possibleConstructorReturn(_this, _ret);
}
_createClass(Dispatcher, [{
key: 'init',
// componentWillMount will be deprecated
// for SSR, initialize on first render
// constructor is also unsafe in StrictMode
value: function init() {
if (this.rendered) {
return;
}
this.rendered = true;
var helmetInstances = this.props.context.helmetInstances;
helmetInstances.add(this);
this.emitChange();
}
}, {
key: 'shouldComponentUpdate',

@@ -56,9 +85,11 @@ value: function shouldComponentUpdate(nextProps) {

value: function emitChange() {
var _context = this.context,
helmetInstances = _context.helmetInstances,
setHelmet = _context.setHelmet;
var _props$context = this.props.context,
helmetInstances = _props$context.helmetInstances,
setHelmet = _props$context.setHelmet;
var serverState = null;
var state = (0, _utils.reducePropsToState)(helmetInstances.get().map(function (instance) {
return instance.props;
var props = _extends({}, instance.props);
delete props.context;
return props;
}));

@@ -70,13 +101,5 @@ if (_Provider2.default.canUseDOM) {

}
setHelmet(serverState, state);
setHelmet(serverState);
}
}, {
key: 'componentWillMount',
value: function componentWillMount() {
var helmetInstances = this.context.helmetInstances;
helmetInstances.add(this);
this.emitChange();
}
}, {
key: 'componentDidUpdate',

@@ -89,3 +112,3 @@ value: function componentDidUpdate() {

value: function componentWillUnmount() {
var helmetInstances = this.context.helmetInstances;
var helmetInstances = this.props.context.helmetInstances;

@@ -98,2 +121,4 @@ helmetInstances.remove(this);

value: function render() {
this.init();
return null;

@@ -106,3 +131,5 @@ }

Dispatcher.contextTypes = _Provider.providerShape;
Dispatcher.propTypes = {
context: _Provider.providerShape.isRequired
};
exports.default = Dispatcher;

@@ -29,5 +29,5 @@ 'use strict';

var _deepEqual = require('deep-equal');
var _reactFastCompare = require('react-fast-compare');
var _deepEqual2 = _interopRequireDefault(_deepEqual);
var _reactFastCompare2 = _interopRequireDefault(_reactFastCompare);

@@ -38,2 +38,6 @@ var _invariant = require('invariant');

var _Context = require('./Context');
var _Context2 = _interopRequireDefault(_Context);
var _Dispatcher = require('./Dispatcher');

@@ -92,3 +96,3 @@

value: function shouldComponentUpdate(nextProps) {
return !(0, _deepEqual2.default)(this.props, nextProps);
return !(0, _reactFastCompare2.default)(this.props, nextProps);
}

@@ -245,3 +249,9 @@ /* eslint-enable react/prop-types, react/forbid-prop-types, react/require-default-props */

return _react2.default.createElement(_Dispatcher2.default, newProps);
return _react2.default.createElement(
_Context2.default.Consumer,
null,
function (context) {
return _react2.default.createElement(_Dispatcher2.default, _extends({}, newProps, { context: context }));
}
);
}

@@ -248,0 +258,0 @@ }]);

@@ -12,2 +12,4 @@ 'use strict';

var _react2 = _interopRequireDefault(_react);
var _propTypes = require('prop-types');

@@ -17,2 +19,6 @@

var _Context = require('./Context');
var _Context2 = _interopRequireDefault(_Context);
var _server = require('./server');

@@ -32,3 +38,3 @@

var providerShape = exports.providerShape = {
var providerShape = exports.providerShape = _propTypes2.default.shape({
setHelmet: _propTypes2.default.func,

@@ -40,3 +46,3 @@ helmetInstances: _propTypes2.default.shape({

})
};
});

@@ -48,28 +54,2 @@ var canUseDOM = typeof document !== 'undefined';

_createClass(Provider, [{
key: 'getChildContext',
value: function getChildContext() {
var _this2 = this;
return {
setHelmet: function setHelmet(serverState, state) {
_this2.props.context.helmet = serverState;
_this2.props.context.state = state;
},
helmetInstances: {
get: function get() {
return _this2.instances;
},
add: function add(instance) {
_this2.instances.push(instance);
},
remove: function remove(instance) {
var index = _this2.instances.indexOf(instance);
_this2.instances.splice(index, 1);
}
}
};
}
}]);
function Provider(props) {

@@ -81,2 +61,19 @@ _classCallCheck(this, Provider);

_this.instances = [];
_this.value = {
setHelmet: function setHelmet(serverState) {
_this.props.context.helmet = serverState;
},
helmetInstances: {
get: function get() {
return _this.instances;
},
add: function add(instance) {
_this.instances.push(instance);
},
remove: function remove(instance) {
var index = _this.instances.indexOf(instance);
_this.instances.splice(index, 1);
}
}
};

@@ -105,3 +102,7 @@

value: function render() {
return this.props.children;
return _react2.default.createElement(
_Context2.default.Provider,
{ value: this.value },
this.props.children
);
}

@@ -121,3 +122,2 @@ }]);

};
Provider.childContextTypes = providerShape;
exports.default = Provider;

@@ -156,3 +156,3 @@ 'use strict';

var attributeKey = keys[i];
var tagUnion = Object.assign({}, approvedSeenTags[attributeKey], instanceSeenTags[attributeKey]);
var tagUnion = _extends({}, approvedSeenTags[attributeKey], instanceSeenTags[attributeKey]);

@@ -159,0 +159,0 @@ approvedSeenTags[attributeKey] = tagUnion;

@@ -7,2 +7,4 @@ 'use strict';

var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

@@ -42,8 +44,35 @@

function Dispatcher() {
var _ref;
var _temp, _this, _ret;
_classCallCheck(this, Dispatcher);
return _possibleConstructorReturn(this, (Dispatcher.__proto__ || Object.getPrototypeOf(Dispatcher)).apply(this, arguments));
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = Dispatcher.__proto__ || Object.getPrototypeOf(Dispatcher)).call.apply(_ref, [this].concat(args))), _this), _this.rendered = false, _temp), _possibleConstructorReturn(_this, _ret);
}
_createClass(Dispatcher, [{
key: 'init',
// componentWillMount will be deprecated
// for SSR, initialize on first render
// constructor is also unsafe in StrictMode
value: function init() {
if (this.rendered) {
return;
}
this.rendered = true;
var helmetInstances = this.props.context.helmetInstances;
helmetInstances.add(this);
this.emitChange();
}
}, {
key: 'shouldComponentUpdate',

@@ -56,9 +85,11 @@ value: function shouldComponentUpdate(nextProps) {

value: function emitChange() {
var _context = this.context,
helmetInstances = _context.helmetInstances,
setHelmet = _context.setHelmet;
var _props$context = this.props.context,
helmetInstances = _props$context.helmetInstances,
setHelmet = _props$context.setHelmet;
var serverState = null;
var state = (0, _utils.reducePropsToState)(helmetInstances.get().map(function (instance) {
return instance.props;
var props = _extends({}, instance.props);
delete props.context;
return props;
}));

@@ -70,13 +101,5 @@ if (_Provider2.default.canUseDOM) {

}
setHelmet(serverState, state);
setHelmet(serverState);
}
}, {
key: 'componentWillMount',
value: function componentWillMount() {
var helmetInstances = this.context.helmetInstances;
helmetInstances.add(this);
this.emitChange();
}
}, {
key: 'componentDidUpdate',

@@ -89,3 +112,3 @@ value: function componentDidUpdate() {

value: function componentWillUnmount() {
var helmetInstances = this.context.helmetInstances;
var helmetInstances = this.props.context.helmetInstances;

@@ -98,2 +121,4 @@ helmetInstances.remove(this);

value: function render() {
this.init();
return null;

@@ -106,3 +131,5 @@ }

Dispatcher.contextTypes = _Provider.providerShape;
Dispatcher.propTypes = {
context: _Provider.providerShape.isRequired
};
exports.default = Dispatcher;

@@ -29,5 +29,5 @@ 'use strict';

var _deepEqual = require('deep-equal');
var _reactFastCompare = require('react-fast-compare');
var _deepEqual2 = _interopRequireDefault(_deepEqual);
var _reactFastCompare2 = _interopRequireDefault(_reactFastCompare);

@@ -38,2 +38,6 @@ var _invariant = require('invariant');

var _Context = require('./Context');
var _Context2 = _interopRequireDefault(_Context);
var _Dispatcher = require('./Dispatcher');

@@ -92,3 +96,3 @@

value: function shouldComponentUpdate(nextProps) {
return !(0, _deepEqual2.default)(this.props, nextProps);
return !(0, _reactFastCompare2.default)(this.props, nextProps);
}

@@ -245,3 +249,9 @@ /* eslint-enable react/prop-types, react/forbid-prop-types, react/require-default-props */

return _react2.default.createElement(_Dispatcher2.default, newProps);
return _react2.default.createElement(
_Context2.default.Consumer,
null,
function (context) {
return _react2.default.createElement(_Dispatcher2.default, _extends({}, newProps, { context: context }));
}
);
}

@@ -248,0 +258,0 @@ }]);

@@ -12,2 +12,4 @@ 'use strict';

var _react2 = _interopRequireDefault(_react);
var _propTypes = require('prop-types');

@@ -17,2 +19,6 @@

var _Context = require('./Context');
var _Context2 = _interopRequireDefault(_Context);
var _server = require('./server');

@@ -32,3 +38,3 @@

var providerShape = exports.providerShape = {
var providerShape = exports.providerShape = _propTypes2.default.shape({
setHelmet: _propTypes2.default.func,

@@ -40,3 +46,3 @@ helmetInstances: _propTypes2.default.shape({

})
};
});

@@ -48,28 +54,2 @@ var canUseDOM = typeof document !== 'undefined';

_createClass(Provider, [{
key: 'getChildContext',
value: function getChildContext() {
var _this2 = this;
return {
setHelmet: function setHelmet(serverState, state) {
_this2.props.context.helmet = serverState;
_this2.props.context.state = state;
},
helmetInstances: {
get: function get() {
return _this2.instances;
},
add: function add(instance) {
_this2.instances.push(instance);
},
remove: function remove(instance) {
var index = _this2.instances.indexOf(instance);
_this2.instances.splice(index, 1);
}
}
};
}
}]);
function Provider(props) {

@@ -81,2 +61,19 @@ _classCallCheck(this, Provider);

_this.instances = [];
_this.value = {
setHelmet: function setHelmet(serverState) {
_this.props.context.helmet = serverState;
},
helmetInstances: {
get: function get() {
return _this.instances;
},
add: function add(instance) {
_this.instances.push(instance);
},
remove: function remove(instance) {
var index = _this.instances.indexOf(instance);
_this.instances.splice(index, 1);
}
}
};

@@ -105,3 +102,7 @@

value: function render() {
return this.props.children;
return _react2.default.createElement(
_Context2.default.Provider,
{ value: this.value },
this.props.children
);
}

@@ -121,3 +122,2 @@ }]);

};
Provider.childContextTypes = providerShape;
exports.default = Provider;

@@ -156,3 +156,3 @@ 'use strict';

var attributeKey = keys[i];
var tagUnion = Object.assign({}, approvedSeenTags[attributeKey], instanceSeenTags[attributeKey]);
var tagUnion = _extends({}, approvedSeenTags[attributeKey], instanceSeenTags[attributeKey]);

@@ -159,0 +159,0 @@ approvedSeenTags[attributeKey] = tagUnion;

{
"name": "react-helmet-async",
"version": "0.1.0",
"version": "0.2.0-beta.0",
"description": "Thread-safe Helmet for React 16+ and friends",
"main": "lib/index.js",
"repository": "http://github.com/NYTimes/react-helmet-async",
"author": "Scott Taylor",
"author": "Scott Taylor <scott.c.taylor@mac.com>",
"license": "Apache-2.0",
"typings": "index.d.ts",
"dependencies": {
"deep-equal": "^1.0.1",
"invariant": "^2.2.4",
"prop-types": "^15.6.1",
"react-fast-compare": "^2.0.2",
"shallowequal": "^1.0.2"

@@ -18,7 +18,7 @@ },

"babel-cli": "^6.26.0",
"babel-core": "^6.26.0",
"babel-eslint": "^8.2.2",
"babel-jest": "^22.4.3",
"babel-core": "^6.26.3",
"babel-eslint": "^8.2.3",
"babel-jest": "^22.4.4",
"babel-plugin-transform-class-properties": "^6.24.1",
"babel-plugin-transform-es2015-modules-commonjs": "^6.26.0",
"babel-plugin-transform-es2015-modules-commonjs": "^6.26.2",
"babel-plugin-transform-object-rest-spread": "^6.26.0",

@@ -32,19 +32,19 @@ "babel-preset-kyt-react": "^0.3.0",

"eslint-config-prettier": "^2.9.0",
"eslint-plugin-import": "^2.10.0",
"eslint-plugin-jest": "^21.15.0",
"eslint-plugin-import": "^2.12.0",
"eslint-plugin-jest": "^21.17.0",
"eslint-plugin-json": "^1.2.0",
"eslint-plugin-jsx-a11y": "^6.0.3",
"eslint-plugin-prettier": "^2.6.0",
"eslint-plugin-react": "^7.7.0",
"jest-cli": "^22.4.3",
"jsdom": "^11.7.0",
"prettier": "^1.11.1",
"eslint-plugin-react": "^7.9.1",
"jest-cli": "^22.4.4",
"jsdom": "^11.11.0",
"prettier": "^1.13.5",
"prettier-eslint-cli": "^4.7.1",
"react": "^16.2.0",
"react-dom": "^16.2.0",
"react": "^16.4.1",
"react-dom": "^16.4.1",
"regenerator-runtime": "^0.11.1"
},
"peerDependencies": {
"react": "^16.2.0",
"react-dom": "^16.2.0"
"react": "^16.4.1",
"react-dom": "^16.4.1"
},

@@ -51,0 +51,0 @@ "scripts": {

# react-helmet-async
[![CircleCI](https://circleci.com/gh/staylor/react-helmet-async.svg?style=svg)](https://circleci.com/gh/staylor/react-helmet-async)
This package is a fork of [React Helmet](https://github.com/nfl/react-helmet).
`<Helmet>` usage is synonymous, but server and client now requires `<HelmetProvider>` to encapsulate state per request.
`react-helmet` relies on `react-side-effect`, which is not thread-safe. If you are doing anything asynchronous on the server, you need Helmet to to encapsulate data on a per-request basis, this package does just that.
`react-helmet` relies on `react-side-effect`, which is not thread-safe. If you are doing anything asynchronous on the server, you need Helmet to encapsulate data on a per-request basis, this package does just that.

@@ -8,0 +10,0 @@ ## Usage

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc