Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't hyphenate custom CSS properties for ReactDOMServer #16167

Merged
merged 8 commits into from Jul 26, 2019
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -57,6 +57,15 @@ describe('CSSPropertyOperations', () => {
expect(html).toContain('"-ms-transition:none;-moz-transition:none"');
});

it('should not hyphenate custom CSS property', () => {
const styles = {
'--someColor': '#000000',
};
const div = <div style={styles} />;
const html = ReactDOMServer.renderToString(div);
expect(html).toContain('"--someColor:#000000"');
});

it('should set style attribute when styles exist', () => {
const styles = {
backgroundColor: '#000',
Expand Down
3 changes: 2 additions & 1 deletion packages/react-dom/src/server/ReactPartialRenderer.js
Expand Up @@ -209,10 +209,11 @@ function validateDangerousTag(tag) {

const styleNameCache = {};
const processStyleName = function(styleName) {
const isCustomProperty = styleName.indexOf('--') === 0;
bedakb marked this conversation as resolved.
Show resolved Hide resolved
if (styleNameCache.hasOwnProperty(styleName)) {
return styleNameCache[styleName];
}
const result = hyphenateStyleName(styleName);
const result = isCustomProperty ? styleName : hyphenateStyleName(styleName);
styleNameCache[styleName] = result;
return result;
};
Expand Down