Skip to content

Commit 808acb4

Browse files
authored
Use componentDidMount for WithStyles (#1157)
* HOC should not attach sheets until mount, same as the new hook implementation * Fix potential FOUC by attaching sheet in HOC constructor when running in browser. * Call registry.add() on the client too for parity with the hooks implementation * use componentDidMount, add changelog * changelog * changelog
1 parent 743d628 commit 808acb4

3 files changed

Lines changed: 22 additions & 15 deletions

File tree

changelog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ Since you are interested in what happens next, in case, you work for a for-profi
44

55
---
66

7+
### Bug fixes
8+
9+
- [react-jss] withStyles shouldn't attach() on SSR ([#1149](https://github.com/cssinjs/jss/pull/1149), [#1157](https://github.com/cssinjs/jss/pull/1157))
10+
711
### Improvements
812

913
- [jss] Improve treeshaking for webpack by not using `global`. ([#1153](https://github.com/cssinjs/jss/pull/1153))

packages/react-jss/.size-snapshot.json

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
{
22
"dist/react-jss.js": {
3-
"bundled": 168372,
4-
"minified": 58132,
5-
"gzipped": 18988
3+
"bundled": 168517,
4+
"minified": 58191,
5+
"gzipped": 19016
66
},
77
"dist/react-jss.min.js": {
8-
"bundled": 111704,
9-
"minified": 41522,
10-
"gzipped": 14086
8+
"bundled": 111849,
9+
"minified": 41586,
10+
"gzipped": 14098
1111
},
1212
"dist/react-jss.cjs.js": {
13-
"bundled": 26415,
14-
"minified": 11502,
15-
"gzipped": 3809
13+
"bundled": 26550,
14+
"minified": 11551,
15+
"gzipped": 3816
1616
},
1717
"dist/react-jss.esm.js": {
18-
"bundled": 25453,
19-
"minified": 10667,
20-
"gzipped": 3688,
18+
"bundled": 25588,
19+
"minified": 10716,
20+
"gzipped": 3693,
2121
"treeshaked": {
2222
"rollup": {
2323
"code": 1841,

packages/react-jss/src/withStyles.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// @flow
22
import React, {Component, type ComponentType, type Node} from 'react'
3-
import isInBrowser from 'is-in-browser'
43
import hoistNonReactStatics from 'hoist-non-react-statics'
54
import {type StyleSheet, type Classes} from 'jss'
65
import {ThemeContext} from 'theming'
@@ -119,8 +118,12 @@ const withStyles = <Theme>(styles: Styles<Theme>, options?: HOCOptions<Theme> =
119118
if (sheet && registry) {
120119
registry.add(sheet)
121120
}
122-
if (isInBrowser) {
123-
WithStyles.manage(props, this.state)
121+
}
122+
123+
componentDidMount() {
124+
const {props, state} = this
125+
if (props && state) {
126+
WithStyles.manage(props, state)
124127
}
125128
}
126129

0 commit comments

Comments
 (0)