From 4176a20ed055fd9536a8e82ecb577e2c85660b83 Mon Sep 17 00:00:00 2001 From: Henri Beck Date: Sat, 16 Mar 2019 23:58:32 +0100 Subject: [PATCH 1/4] Add failing test --- packages/react-jss/src/JssProvider.test.js | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/packages/react-jss/src/JssProvider.test.js b/packages/react-jss/src/JssProvider.test.js index 0a60c2971..bd3fe29b8 100644 --- a/packages/react-jss/src/JssProvider.test.js +++ b/packages/react-jss/src/JssProvider.test.js @@ -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 '.' @@ -249,9 +250,13 @@ describe('React-JSS: JssProvider', () => { } const MyComponent = withStyles(styles)() let generateId = createGenerateId() + const jss = create(preset()) + + // Because we currently run the tests in the browser, we will need to reset the renderer here again + jss.options.Renderer = null TestRenderer.create( - + ) @@ -269,7 +274,7 @@ describe('React-JSS: JssProvider', () => { generateId = createGenerateId() TestRenderer.create( - + ) @@ -295,15 +300,19 @@ describe('React-JSS: JssProvider', () => { const customSheets2 = new SheetsRegistry() const generateId1 = createGenerateId() const generateId2 = createGenerateId() + const jss = create(preset()) + + // Because we currently run the tests in the browser, we will need to reset the renderer here again + jss.options.Renderer = null TestRenderer.create( - + ) TestRenderer.create( - + ) @@ -312,6 +321,7 @@ describe('React-JSS: JssProvider', () => { const result2 = customSheets2.toString() expect(result1).to.equal(result2) + expect(result1.length > 0).to.be(true) }) }) }) From 2165061faba5e34f955260b119cf1eaac83b3323 Mon Sep 17 00:00:00 2001 From: Henri Beck Date: Sun, 17 Mar 2019 00:06:11 +0100 Subject: [PATCH 2/4] Fix tests --- packages/jss/.size-snapshot.json | 28 ++++++++++++++-------------- packages/jss/src/StyleSheet.js | 10 ++++++++-- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/packages/jss/.size-snapshot.json b/packages/jss/.size-snapshot.json index e945641d9..1802b89fc 100644 --- a/packages/jss/.size-snapshot.json +++ b/packages/jss/.size-snapshot.json @@ -1,30 +1,30 @@ { "dist/jss.js": { - "bundled": 58916, - "minified": 21875, - "gzipped": 6588 + "bundled": 58956, + "minified": 21874, + "gzipped": 6584 }, "dist/jss.min.js": { - "bundled": 57750, - "minified": 20957, - "gzipped": 6147 + "bundled": 57790, + "minified": 20956, + "gzipped": 6142 }, "dist/jss.cjs.js": { - "bundled": 54372, - "minified": 23786, - "gzipped": 6637 + "bundled": 54404, + "minified": 23785, + "gzipped": 6633 }, "dist/jss.esm.js": { - "bundled": 53876, - "minified": 23382, - "gzipped": 6555, + "bundled": 53908, + "minified": 23381, + "gzipped": 6551, "treeshaked": { "rollup": { - "code": 19017, + "code": 19016, "import_statements": 281 }, "webpack": { - "code": 20432 + "code": 20431 } } } diff --git a/packages/jss/src/StyleSheet.js b/packages/jss/src/StyleSheet.js index 27b886795..4d9dc31de 100644 --- a/packages/jss/src/StyleSheet.js +++ b/packages/jss/src/StyleSheet.js @@ -59,9 +59,15 @@ 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 + } + this.attached = true + + if (this.renderer) { + this.renderer.attach() + } // Order is important, because we can't use insertRule API if style element is not attached. if (!this.deployed) this.deploy() return this From bc81d0eceab5b0898ab497a740d6943e700d49c9 Mon Sep 17 00:00:00 2001 From: Henri Beck Date: Sun, 17 Mar 2019 00:16:59 +0100 Subject: [PATCH 3/4] Fix tests --- packages/jss/.size-snapshot.json | 28 ++++++++++++++-------------- packages/jss/src/StyleSheet.js | 7 +++++-- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/packages/jss/.size-snapshot.json b/packages/jss/.size-snapshot.json index 1802b89fc..79616d90b 100644 --- a/packages/jss/.size-snapshot.json +++ b/packages/jss/.size-snapshot.json @@ -1,30 +1,30 @@ { "dist/jss.js": { - "bundled": 58956, - "minified": 21874, - "gzipped": 6584 + "bundled": 58976, + "minified": 21880, + "gzipped": 6588 }, "dist/jss.min.js": { - "bundled": 57790, - "minified": 20956, - "gzipped": 6142 + "bundled": 57810, + "minified": 20962, + "gzipped": 6146 }, "dist/jss.cjs.js": { - "bundled": 54404, - "minified": 23785, - "gzipped": 6633 + "bundled": 54422, + "minified": 23791, + "gzipped": 6638 }, "dist/jss.esm.js": { - "bundled": 53908, - "minified": 23381, - "gzipped": 6551, + "bundled": 53926, + "minified": 23387, + "gzipped": 6555, "treeshaked": { "rollup": { - "code": 19016, + "code": 19022, "import_statements": 281 }, "webpack": { - "code": 20431 + "code": 20437 } } } diff --git a/packages/jss/src/StyleSheet.js b/packages/jss/src/StyleSheet.js index 4d9dc31de..51bced697 100644 --- a/packages/jss/src/StyleSheet.js +++ b/packages/jss/src/StyleSheet.js @@ -65,9 +65,12 @@ export default class StyleSheet { this.attached = true - if (this.renderer) { - this.renderer.attach() + if (!this.renderer) { + return this } + + this.renderer.attach() + // Order is important, because we can't use insertRule API if style element is not attached. if (!this.deployed) this.deploy() return this From ef25bcdcefc022da6392a1c0aa7706a2ec405bfc Mon Sep 17 00:00:00 2001 From: Oleg Isonen Date: Sun, 17 Mar 2019 16:10:03 +0100 Subject: [PATCH 4/4] fix order attached flag needs to be set after attachment, otherwise the sheet will be already considered when finding the right position in DomRenderer to attach the sheet after --- changelog.md | 6 +++++ packages/jss/.size-snapshot.json | 28 +++++++++++----------- packages/jss/src/StyleSheet.js | 23 +++++------------- packages/react-jss/src/JssProvider.test.js | 12 ++++------ 4 files changed, 30 insertions(+), 39 deletions(-) diff --git a/changelog.md b/changelog.md index 2453751fc..ded894706 100755 --- a/changelog.md +++ b/changelog.md @@ -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)) diff --git a/packages/jss/.size-snapshot.json b/packages/jss/.size-snapshot.json index 79616d90b..0424e2707 100644 --- a/packages/jss/.size-snapshot.json +++ b/packages/jss/.size-snapshot.json @@ -1,30 +1,30 @@ { "dist/jss.js": { - "bundled": 58976, - "minified": 21880, - "gzipped": 6588 + "bundled": 58897, + "minified": 21872, + "gzipped": 6582 }, "dist/jss.min.js": { - "bundled": 57810, - "minified": 20962, - "gzipped": 6146 + "bundled": 57731, + "minified": 20954, + "gzipped": 6139 }, "dist/jss.cjs.js": { - "bundled": 54422, - "minified": 23791, - "gzipped": 6638 + "bundled": 54357, + "minified": 23783, + "gzipped": 6633 }, "dist/jss.esm.js": { - "bundled": 53926, - "minified": 23387, - "gzipped": 6555, + "bundled": 53861, + "minified": 23379, + "gzipped": 6550, "treeshaked": { "rollup": { - "code": 19022, + "code": 19014, "import_statements": 281 }, "webpack": { - "code": 20437 + "code": 20429 } } } diff --git a/packages/jss/src/StyleSheet.js b/packages/jss/src/StyleSheet.js index 51bced697..319e566ff 100644 --- a/packages/jss/src/StyleSheet.js +++ b/packages/jss/src/StyleSheet.js @@ -59,18 +59,9 @@ export default class StyleSheet { * Attach renderable to the render tree. */ attach(): this { - if (this.attached) { - return this - } - + if (this.attached) return this + if (this.renderer) this.renderer.attach() this.attached = true - - if (!this.renderer) { - return this - } - - this.renderer.attach() - // Order is important, because we can't use insertRule API if style element is not attached. if (!this.deployed) this.deploy() return this @@ -80,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 } @@ -184,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 } diff --git a/packages/react-jss/src/JssProvider.test.js b/packages/react-jss/src/JssProvider.test.js index bd3fe29b8..dcb7c28a8 100644 --- a/packages/react-jss/src/JssProvider.test.js +++ b/packages/react-jss/src/JssProvider.test.js @@ -250,10 +250,8 @@ describe('React-JSS: JssProvider', () => { } const MyComponent = withStyles(styles)() let generateId = createGenerateId() - const jss = create(preset()) - - // Because we currently run the tests in the browser, we will need to reset the renderer here again - jss.options.Renderer = null + // Remove renderer to simulate a non-browser env. + const jss = create({...preset(), Renderer: null}) TestRenderer.create( @@ -300,10 +298,8 @@ describe('React-JSS: JssProvider', () => { const customSheets2 = new SheetsRegistry() const generateId1 = createGenerateId() const generateId2 = createGenerateId() - const jss = create(preset()) - - // Because we currently run the tests in the browser, we will need to reset the renderer here again - jss.options.Renderer = null + // Remove renderer to simulate a non-browser env. + const jss = create({...preset(), Renderer: null}) TestRenderer.create(