diff --git a/scripts/fiber/tests-passing.txt b/scripts/fiber/tests-passing.txt index 0c658781d646..393fd2e8a94f 100644 --- a/scripts/fiber/tests-passing.txt +++ b/scripts/fiber/tests-passing.txt @@ -816,6 +816,7 @@ src/renderers/dom/shared/__tests__/CSSPropertyOperations-test.js * warns when miscapitalizing vendored style names * should warn about style having a trailing semicolon * should warn about style containing a NaN value +* should not warn when setting CSS variables src/renderers/dom/shared/__tests__/DOMPropertyOperations-test.js * should create markup for simple properties diff --git a/src/renderers/dom/shared/CSSPropertyOperations.js b/src/renderers/dom/shared/CSSPropertyOperations.js index a7a70ed89537..954be43910f3 100644 --- a/src/renderers/dom/shared/CSSPropertyOperations.js +++ b/src/renderers/dom/shared/CSSPropertyOperations.js @@ -134,6 +134,10 @@ 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; @@ -213,7 +217,9 @@ var CSSPropertyOperations = { if (styleName === 'float') { styleName = 'cssFloat'; } - if (styleValue) { + if (styleName.indexOf('--') === 0) { + style.setProperty(styleName, styleValue); + } else if (styleValue) { style[styleName] = styleValue; } else { var expansion = hasShorthandPropertyBug && diff --git a/src/renderers/dom/shared/__tests__/CSSPropertyOperations-test.js b/src/renderers/dom/shared/__tests__/CSSPropertyOperations-test.js index f1d9c567bfad..34469835dbec 100644 --- a/src/renderers/dom/shared/__tests__/CSSPropertyOperations-test.js +++ b/src/renderers/dom/shared/__tests__/CSSPropertyOperations-test.js @@ -253,4 +253,18 @@ describe('CSSPropertyOperations', () => { '\n\nCheck the render method of `Comp`.', ); }); + + it('should not warn when setting CSS variables', () => { + class Comp extends React.Component { + render() { + return
; + } + } + + spyOn(console, 'error'); + var root = document.createElement('div'); + ReactDOM.render(, root); + + expectDev(console.error.calls.count()).toBe(0); + }); });