styled-jsx
Advanced tools
Comparing version 4.0.0-alpha.1 to 4.0.0-alpha.2
"use strict"; | ||
exports.__esModule = true; | ||
exports["default"] = JSXStyle; | ||
exports.flush = flush; | ||
exports["default"] = void 0; | ||
@@ -13,59 +13,27 @@ var _react = require("react"); | ||
function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; } | ||
var styleSheetRegistry = new _stylesheetRegistry["default"](); | ||
var JSXStyle = /*#__PURE__*/function (_Component) { | ||
_inheritsLoose(JSXStyle, _Component); | ||
function JSXStyle(props) { | ||
var _this; | ||
_this = _Component.call(this, props) || this; | ||
_this.prevProps = {}; | ||
return _this; | ||
function JSXStyle(props) { | ||
if (typeof window === 'undefined') { | ||
styleSheetRegistry.add(props); | ||
return null; | ||
} | ||
JSXStyle.dynamic = function dynamic(info) { | ||
return info.map(function (tagInfo) { | ||
var baseId = tagInfo[0]; | ||
var props = tagInfo[1]; | ||
return styleSheetRegistry.computeId(baseId, props); | ||
}).join(' '); | ||
} // probably faster than PureComponent (shallowEqual) | ||
; | ||
(0, _react.useLayoutEffect)(function () { | ||
styleSheetRegistry.add(props); | ||
return function () { | ||
styleSheetRegistry.remove(props); | ||
}; // props.children can be string[], will be striped since id is identical | ||
}, [props.id, String(props.dynamic)]); | ||
return null; | ||
} | ||
var _proto = JSXStyle.prototype; | ||
JSXStyle.dynamic = function (info) { | ||
return info.map(function (tagInfo) { | ||
var baseId = tagInfo[0]; | ||
var props = tagInfo[1]; | ||
return styleSheetRegistry.computeId(baseId, props); | ||
}).join(' '); | ||
}; | ||
_proto.shouldComponentUpdate = function shouldComponentUpdate(otherProps) { | ||
return this.props.id !== otherProps.id || // We do this check because `dynamic` is an array of strings or undefined. | ||
// These are the computed values for dynamic styles. | ||
String(this.props.dynamic) !== String(otherProps.dynamic); | ||
}; | ||
_proto.componentWillUnmount = function componentWillUnmount() { | ||
styleSheetRegistry.remove(this.props); | ||
}; | ||
_proto.render = function render() { | ||
// This is a workaround to make the side effect async safe in the "render" phase. | ||
// See https://github.com/zeit/styled-jsx/pull/484 | ||
if (this.shouldComponentUpdate(this.prevProps)) { | ||
// Updates | ||
if (this.prevProps.id) { | ||
styleSheetRegistry.remove(this.prevProps); | ||
} | ||
styleSheetRegistry.add(this.props); | ||
this.prevProps = this.props; | ||
} | ||
return null; | ||
}; | ||
return JSXStyle; | ||
}(_react.Component); | ||
exports["default"] = JSXStyle; | ||
function flush() { | ||
@@ -72,0 +40,0 @@ var cssRules = styleSheetRegistry.cssRules(); |
{ | ||
"name": "styled-jsx", | ||
"version": "4.0.0-alpha.1", | ||
"version": "4.0.0-alpha.2", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "repository": "vercel/styled-jsx", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
104138
1673