Skip to content

Commit

Permalink
Switch to async safe lifecycle methods (#464)
Browse files Browse the repository at this point in the history
  • Loading branch information
giuseppeg authored Aug 2, 2018
1 parent 93fabea commit 69c00d4
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 117 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
language: node_js
node_js:
- "8"
- "10"
- "10"
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,8 @@
"lint-staged": "7.0.0",
"mz": "^2.7.0",
"prettier": "^1.5.2",
"react": "^15.6.1",
"react-dom": "^15.6.1",
"react-jsdom": "^2.0.5",
"react": "^16.4.0",
"react-dom": "^16.4.0",
"xo": "0.20.3"
},
"peerDependencies": {
Expand Down
17 changes: 12 additions & 5 deletions src/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ import StyleSheetRegistry from './stylesheet-registry'
const styleSheetRegistry = new StyleSheetRegistry()

export default class JSXStyle extends Component {
constructor(props) {
super(props)

// SeverSideRendering only
if (typeof window === 'undefined') {
styleSheetRegistry.add(this.props)
}
}

static dynamic(info) {
return info
.map(tagInfo => {
Expand All @@ -14,18 +23,16 @@ export default class JSXStyle extends Component {
.join(' ')
}

componentWillMount() {
componentDidMount() {
styleSheetRegistry.add(this.props)
}

shouldComponentUpdate(nextProps) {
return this.props.css !== nextProps.css
}

// To avoid FOUC, we process new changes
// on `componentWillUpdate` rather than `componentDidUpdate`.
componentWillUpdate(nextProps) {
styleSheetRegistry.update(this.props, nextProps)
componentDidUpdate(prevProps) {
styleSheetRegistry.update(prevProps, this.props)
}

componentWillUnmount() {
Expand Down
68 changes: 0 additions & 68 deletions test/browser.js

This file was deleted.

57 changes: 17 additions & 40 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1593,14 +1593,6 @@ create-error-class@^3.0.0:
dependencies:
capture-stack-trace "^1.0.0"

create-react-class@^15.6.0:
version "15.6.3"
resolved "https://registry.yarnpkg.com/create-react-class/-/create-react-class-15.6.3.tgz#2d73237fb3f970ae6ebe011a9e66f46dbca80036"
dependencies:
fbjs "^0.8.9"
loose-envify "^1.3.1"
object-assign "^4.1.1"

cross-spawn@^5.0.1, cross-spawn@^5.1.0:
version "5.1.0"
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-5.1.0.tgz#e8bd0efee58fcff6f8f94510a0a554bbfa235449"
Expand Down Expand Up @@ -2223,7 +2215,7 @@ fast-levenshtein@~2.0.4:
version "2.0.6"
resolved "https://registry.yarnpkg.com/fast-levenshtein/-/fast-levenshtein-2.0.6.tgz#3d8a5c66883a16a30ca8643e851f19baa7797917"

fbjs@^0.8.16, fbjs@^0.8.9:
fbjs@^0.8.16:
version "0.8.16"
resolved "https://registry.yarnpkg.com/fbjs/-/fbjs-0.8.16.tgz#5e67432f550dc41b572bf55847b8aca64e5337db"
dependencies:
Expand Down Expand Up @@ -3329,7 +3321,7 @@ jsbn@~0.1.0:
version "0.1.1"
resolved "https://registry.yarnpkg.com/jsbn/-/jsbn-0.1.1.tgz#a5e654c2e5a2deb5f201d96cefbca80c0ef2f513"

jsdom@11.6.2, jsdom@^11.5.1:
jsdom@^11.5.1:
version "11.6.2"
resolved "https://registry.yarnpkg.com/jsdom/-/jsdom-11.6.2.tgz#25d1ef332d48adf77fc5221fe2619967923f16bb"
dependencies:
Expand Down Expand Up @@ -4406,11 +4398,10 @@ promise@^7.1.1:
dependencies:
asap "~2.0.3"

prop-types@^15.5.10:
version "15.6.1"
resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.6.1.tgz#36644453564255ddda391191fb3a125cbdf654ca"
prop-types@^15.6.0:
version "15.6.2"
resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.6.2.tgz#05d5ca77b4453e985d60fc7ff8c859094a497102"
dependencies:
fbjs "^0.8.16"
loose-envify "^1.3.1"
object-assign "^4.1.1"

Expand Down Expand Up @@ -4458,31 +4449,23 @@ rc@^1.0.1, rc@^1.1.6, rc@^1.1.7:
minimist "^1.2.0"
strip-json-comments "~2.0.1"

react-dom@^15.6.1:
version "15.6.2"
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-15.6.2.tgz#41cfadf693b757faf2708443a1d1fd5a02bef730"
react-dom@^16.4.0:
version "16.4.1"
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-16.4.1.tgz#7f8b0223b3a5fbe205116c56deb85de32685dad6"
dependencies:
fbjs "^0.8.9"
fbjs "^0.8.16"
loose-envify "^1.1.0"
object-assign "^4.1.0"
prop-types "^15.5.10"

react-jsdom@^2.0.5:
version "2.0.5"
resolved "https://registry.yarnpkg.com/react-jsdom/-/react-jsdom-2.0.5.tgz#4a1591c26b294209b5c1e39afdbd589c7d428f4b"
dependencies:
react-dom "^15.6.1"
window "^4.1.1"
object-assign "^4.1.1"
prop-types "^15.6.0"

react@^15.6.1:
version "15.6.2"
resolved "https://registry.yarnpkg.com/react/-/react-15.6.2.tgz#dba0434ab439cfe82f108f0f511663908179aa72"
react@^16.4.0:
version "16.4.1"
resolved "https://registry.yarnpkg.com/react/-/react-16.4.1.tgz#de51ba5764b5dbcd1f9079037b862bd26b82fe32"
dependencies:
create-react-class "^15.6.0"
fbjs "^0.8.9"
fbjs "^0.8.16"
loose-envify "^1.1.0"
object-assign "^4.1.0"
prop-types "^15.5.10"
object-assign "^4.1.1"
prop-types "^15.6.0"

read-pkg-up@^1.0.1:
version "1.0.1"
Expand Down Expand Up @@ -5513,12 +5496,6 @@ widest-line@^2.0.0:
dependencies:
string-width "^2.1.1"

window@^4.1.1:
version "4.2.5"
resolved "https://registry.yarnpkg.com/window/-/window-4.2.5.tgz#02b5c48daf462481d5dfc6d331fbfa4d27d78ee4"
dependencies:
jsdom "11.6.2"

wordwrap@~1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/wordwrap/-/wordwrap-1.0.0.tgz#27584810891456a4171c8d0226441ade90cbcaeb"
Expand Down

0 comments on commit 69c00d4

Please sign in to comment.