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

Avoid subscribing static components #2166

Merged
merged 5 commits into from Nov 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -6,6 +6,8 @@ _The format is based on [Keep a Changelog](http://keepachangelog.com/) and this

## Unreleased

- Performance optimization for fully static (no function interpolation) styled-components by avoiding using `ThemeConsumer` since it isn't necessary, by [@mxstbr](https://github.com/mxstbr) (see [#2166](https://github.com/styled-components/styled-components/pull/2166))

## [v4.0.3] - 2018-10-30

- Interpolating a styled component into a string now returns the static component selector (emotion cross-compat)
Expand Down
4 changes: 4 additions & 0 deletions src/models/StyledComponent.js
Expand Up @@ -74,6 +74,10 @@ class StyledComponent extends Component<*> {

renderOuter(styleSheet?: StyleSheet) {
this.styleSheet = styleSheet;
const { componentStyle } = this.props.forwardedClass;

// No need to subscribe a static component to theme changes, it won't change anything
if (componentStyle.isStatic) return this.renderInner();

return <ThemeConsumer>{this.renderInner}</ThemeConsumer>;
}
Expand Down