Merge branch '15.6-dev' into 15-stable

This commit is contained in:
Dan Abramov
2017-06-15 00:08:38 +01:00
4 changed files with 42 additions and 11 deletions
+2 -1
View File
@@ -23,7 +23,8 @@ fi
# These seem out of order but extract-errors must be run after jest.
if [ $((0 % CIRCLE_NODE_TOTAL)) -eq "$CIRCLE_NODE_INDEX" ]; then
COMMANDS_TO_RUN+=('./node_modules/.bin/gulp lint')
COMMANDS_TO_RUN+=('node ./scripts/prettier/index')
# Temporary: I can't figure out why it fails on CI but works locally
# COMMANDS_TO_RUN+=('node ./scripts/prettier/index')
COMMANDS_TO_RUN+=('./node_modules/.bin/gulp flow')
COMMANDS_TO_RUN+=('./node_modules/.bin/grunt build')
COMMANDS_TO_RUN+=('./scripts/circleci/test_extract_errors.sh')
@@ -128,10 +128,6 @@ if (__DEV__) {
* @param {ReactDOMComponent} component
*/
var warnValidStyle = function(name, value, component) {
// Don't warn for CSS variables
if (name.indexOf('--') === 0) {
return;
}
var owner;
if (component) {
owner = component._currentElement._owner;
@@ -173,14 +169,22 @@ var CSSPropertyOperations = {
if (!styles.hasOwnProperty(styleName)) {
continue;
}
var isCustomProperty = styleName.indexOf('--') === 0;
var styleValue = styles[styleName];
if (__DEV__) {
warnValidStyle(styleName, styleValue, component);
if (!isCustomProperty) {
warnValidStyle(styleName, styleValue, component);
}
}
if (styleValue != null) {
serialized += processStyleName(styleName) + ':';
serialized +=
dangerousStyleValue(styleName, styleValue, component) + ';';
dangerousStyleValue(
styleName,
styleValue,
component,
isCustomProperty,
) + ';';
}
}
return serialized || null;
@@ -208,18 +212,22 @@ var CSSPropertyOperations = {
if (!styles.hasOwnProperty(styleName)) {
continue;
}
var isCustomProperty = styleName.indexOf('--') === 0;
if (__DEV__) {
warnValidStyle(styleName, styles[styleName], component);
if (!isCustomProperty) {
warnValidStyle(styleName, styles[styleName], component);
}
}
var styleValue = dangerousStyleValue(
styleName,
styles[styleName],
component,
isCustomProperty,
);
if (styleName === 'float' || styleName === 'cssFloat') {
styleName = styleFloatAccessor;
}
if (styleName.indexOf('--') === 0) {
if (isCustomProperty) {
style.setProperty(styleName, styleValue);
} else if (styleValue) {
style[styleName] = styleValue;
@@ -101,6 +101,14 @@ describe('CSSPropertyOperations', () => {
).toBe('-ms-transition:none;-moz-transition:none;');
});
it('should create markup with unitless css custom property', () => {
expect(
CSSPropertyOperations.createMarkupForStyles({
'--foo': 5,
}),
).toBe('--foo:5;');
});
it('should set style attribute when styles exist', () => {
var styles = {
backgroundColor: '#000',
@@ -254,7 +262,7 @@ describe('CSSPropertyOperations', () => {
);
});
it('should not warn when setting CSS variables', () => {
it('should not warn when setting CSS custom properties', () => {
class Comp extends React.Component {
render() {
return <div style={{'--foo-primary': 'red', backgroundColor: 'red'}} />;
@@ -267,4 +275,17 @@ describe('CSSPropertyOperations', () => {
expect(console.error.calls.count()).toBe(0);
});
it('should not add units to CSS custom properties', () => {
class Comp extends React.Component {
render() {
return <div style={{'--foo': 5}} />;
}
}
var root = document.createElement('div');
ReactDOM.render(<Comp />, root);
expect(root.children[0].style.Foo).toEqual('5');
});
});
@@ -27,7 +27,7 @@ var styleWarnings = {};
* @param {ReactDOMComponent} component
* @return {string} Normalized style value with dimensions applied.
*/
function dangerousStyleValue(name, value, component) {
function dangerousStyleValue(name, value, component, isCustomProperty) {
// Note that we've removed escapeTextForBrowser() calls here since the
// whole string will be escaped when the attribute is injected into
// the markup. If you provide unsafe user data here they can inject
@@ -45,6 +45,7 @@ function dangerousStyleValue(name, value, component) {
var isNonNumeric = isNaN(value);
if (
isCustomProperty ||
isNonNumeric ||
value === 0 ||
(isUnitlessNumber.hasOwnProperty(name) && isUnitlessNumber[name])