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

[react-jss] Fix display names with spaces inside #1049

Merged
merged 2 commits into from
Mar 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions packages/react-jss/.size-snapshot.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
{
"dist/react-jss.js": {
"bundled": 109683,
"minified": 36814,
"gzipped": 11859
"bundled": 109703,
"minified": 36833,
"gzipped": 11871
},
"dist/react-jss.min.js": {
"bundled": 85144,
"minified": 29568,
"gzipped": 9685
},
"dist/react-jss.cjs.js": {
"bundled": 14716,
"minified": 6874,
"gzipped": 2310
"bundled": 14736,
"minified": 6893,
"gzipped": 2323
},
"dist/react-jss.esm.js": {
"bundled": 14035,
"minified": 6294,
"gzipped": 2193,
"bundled": 14055,
"minified": 6313,
"gzipped": 2207,
"treeshaked": {
"rollup": {
"code": 1946,
Expand Down
3 changes: 2 additions & 1 deletion packages/react-jss/src/withStyles.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ export default function withStyles<Theme: {}, S: Styles<Theme>>(
InnerComponent: ComponentType<Props> = NoRenderer
): ComponentType<Props> => {
const displayName = getDisplayName(InnerComponent)
const defaultClassNamePrefix = process.env.NODE_ENV === 'production' ? '' : `${displayName}-`
const defaultClassNamePrefix =
process.env.NODE_ENV === 'production' ? '' : `${displayName.replace(/\s/g, '-')}-`
const managerId = managersCounter++
const manager = new SheetsManager()
const noTheme = {}
Expand Down
8 changes: 7 additions & 1 deletion packages/react-jss/src/withStyles.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,10 +218,11 @@ describe('React-JSS: withStyles', () => {
return `${rule.key}-id`
}

const renderTest = () => {
const renderTest = (displayName = 'DisplayNameTest') => {
function DisplayNameTest() {
return null
}
DisplayNameTest.displayName = displayName
const MyComponent = withStyles({
a: {color: 'red'}
})(DisplayNameTest)
Expand All @@ -237,6 +238,11 @@ describe('React-JSS: withStyles', () => {
expect(classNamePrefix).to.be('DisplayNameTest-')
})

it('should handle spaces correctly', () => {
renderTest('Display Name Test')
expect(classNamePrefix).to.be('Display-Name-Test-')
})

it('should pass no prefix in production', () => {
process.env.NODE_ENV = 'production'
renderTest()
Expand Down