Skip to content

Commit

Permalink
Revert "Fix JSXStyle renders styles too late (#484)"
Browse files Browse the repository at this point in the history
This reverts commit 5ddef29.
  • Loading branch information
giuseppeg committed Sep 17, 2018
1 parent 03af155 commit 58f2825
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 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,32 +23,23 @@ export default class JSXStyle extends Component {
.join(' ')
}

// probably faster than PureComponent (shallowEqual)
shouldComponentUpdate(nextProps) {
return (
this.props.styleId !== nextProps.styleId ||
// We do this check because `dynamic` is an array of strings or undefined.
// These are the computed values for dynamic styles.
String(this.props.dynamic) !== String(nextProps.dynamic)
)
componentDidMount() {
styleSheetRegistry.add(this.props)
}

// Remove styles in advance.
getSnapshotBeforeUpdate(prevProps) {
styleSheetRegistry.remove(prevProps)
return null
shouldComponentUpdate(nextProps) {
return this.props.css !== nextProps.css
}

// Including this otherwise React complains that getSnapshotBeforeUpdate
// is used without componentDidMount.
componentDidUpdate() {}
componentDidUpdate(prevProps) {
styleSheetRegistry.update(prevProps, this.props)
}

componentWillUnmount() {
styleSheetRegistry.remove(this.props)
}

render() {
styleSheetRegistry.add(this.props)
return null
}
}
Expand Down

0 comments on commit 58f2825

Please sign in to comment.