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

[jss] Fix SSR rendering #1064

Merged
merged 5 commits into from
Mar 17, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
## Next

## Bug fixes

- [jss] Fix SSR aggregation regression ([#1064](https://github.com/cssinjs/jss/pull/1064))

## 10.0.0-alpha.13 (2019-3-12)

### Bug fixes

- [react-jss] Replace spaces inside the display name with hyphens ([#1049](https://github.com/cssinjs/jss/pull/1049))
Expand Down
28 changes: 14 additions & 14 deletions packages/jss/.size-snapshot.json
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
{
"dist/jss.js": {
"bundled": 58916,
"minified": 21875,
"gzipped": 6588
"bundled": 58897,
"minified": 21872,
"gzipped": 6582
},
"dist/jss.min.js": {
"bundled": 57750,
"minified": 20957,
"gzipped": 6147
"bundled": 57731,
"minified": 20954,
"gzipped": 6139
},
"dist/jss.cjs.js": {
"bundled": 54372,
"minified": 23786,
"gzipped": 6637
"bundled": 54357,
"minified": 23783,
"gzipped": 6633
},
"dist/jss.esm.js": {
"bundled": 53876,
"minified": 23382,
"gzipped": 6555,
"bundled": 53861,
"minified": 23379,
"gzipped": 6550,
"treeshaked": {
"rollup": {
"code": 19017,
"code": 19014,
"import_statements": 281
},
"webpack": {
"code": 20432
"code": 20429
}
}
}
Expand Down
14 changes: 6 additions & 8 deletions packages/jss/src/StyleSheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ export default class StyleSheet {
* Attach renderable to the render tree.
*/
attach(): this {
if (this.attached || !this.renderer) return this
this.renderer.attach()
if (this.attached) return this
if (this.renderer) this.renderer.attach()
this.attached = true
// Order is important, because we can't use insertRule API if style element is not attached.
if (!this.deployed) this.deploy()
Expand All @@ -71,8 +71,8 @@ export default class StyleSheet {
* Remove renderable from render tree.
*/
detach(): this {
if (!this.attached || !this.renderer) return this
this.renderer.detach()
if (!this.attached) return this
if (this.renderer) this.renderer.detach()
this.attached = false
return this
}
Expand Down Expand Up @@ -175,10 +175,8 @@ export default class StyleSheet {
* Deploy pure CSS string to a renderable.
*/
deploy(): this {
if (this.renderer) {
this.renderer.deploy()
this.deployed = true
}
if (this.renderer) this.renderer.deploy()
this.deployed = true
return this
}

Expand Down
14 changes: 10 additions & 4 deletions packages/react-jss/src/JssProvider.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import React from 'react'
import {stripIndent} from 'common-tags'
import {create} from 'jss'
import TestRenderer from 'react-test-renderer'
import preset from 'jss-preset-default'

import withStyles, {SheetsRegistry, JssProvider} from '.'

Expand Down Expand Up @@ -249,9 +250,11 @@ describe('React-JSS: JssProvider', () => {
}
const MyComponent = withStyles(styles)()
let generateId = createGenerateId()
// Remove renderer to simulate a non-browser env.
const jss = create({...preset(), Renderer: null})

TestRenderer.create(
<JssProvider registry={registry} generateId={generateId}>
<JssProvider registry={registry} generateId={generateId} jss={jss}>
<MyComponent border="green" />
</JssProvider>
)
Expand All @@ -269,7 +272,7 @@ describe('React-JSS: JssProvider', () => {
generateId = createGenerateId()

TestRenderer.create(
<JssProvider registry={registry} generateId={generateId}>
<JssProvider registry={registry} generateId={generateId} jss={jss}>
<MyComponent border="blue" />
</JssProvider>
)
Expand All @@ -295,15 +298,17 @@ describe('React-JSS: JssProvider', () => {
const customSheets2 = new SheetsRegistry()
const generateId1 = createGenerateId()
const generateId2 = createGenerateId()
// Remove renderer to simulate a non-browser env.
const jss = create({...preset(), Renderer: null})

TestRenderer.create(
<JssProvider registry={customSheets1} generateId={generateId1}>
<JssProvider registry={customSheets1} generateId={generateId1} jss={jss}>
<MyComponent color="#000" />
</JssProvider>
)

TestRenderer.create(
<JssProvider registry={customSheets2} generateId={generateId2}>
<JssProvider registry={customSheets2} generateId={generateId2} jss={jss}>
<MyComponent color="#000" />
</JssProvider>
)
Expand All @@ -312,6 +317,7 @@ describe('React-JSS: JssProvider', () => {
const result2 = customSheets2.toString()

expect(result1).to.equal(result2)
expect(result1.length > 0).to.be(true)
})
})
})