Skip to content

Commit

Permalink
Fix static caching of dynamic attrs
Browse files Browse the repository at this point in the history
  • Loading branch information
schwers committed Oct 9, 2017
1 parent e99bc6a commit f4184ce
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/models/ComponentStyle.js
Expand Up @@ -5,7 +5,7 @@ import type { RuleSet, NameGenerator, Flattener, Stringifier } from '../types'
import StyleSheet from './StyleSheet'
import isStyledComponent from '../utils/isStyledComponent'

const isStaticRules = (rules: RuleSet): boolean => {
const isStaticRules = (rules: RuleSet, attrs?: Object): boolean => {
for (let i = 0; i < rules.length; i += 1) {
const rule = rules[i]

Expand All @@ -19,6 +19,16 @@ const isStaticRules = (rules: RuleSet): boolean => {
}
}

if (attrs !== undefined) {
// eslint-disable-next-line guard-for-in, no-restricted-syntax
for (const key in attrs) {
const value = attrs[key]
if (typeof value === 'function') {
return false
}
}
}

return true
}

Expand All @@ -34,9 +44,9 @@ export default (nameGenerator: NameGenerator, flatten: Flattener, stringifyRules
lastClassName: ?string


constructor(rules: RuleSet, componentId: string) {
constructor(rules: RuleSet, attrs?: Object, componentId: string) {
this.rules = rules
this.isStatic = isStaticRules(rules)
this.isStatic = isStaticRules(rules, attrs)
this.componentId = componentId
if (!StyleSheet.instance.hasInjectedComponent(this.componentId)) {
const placeholder = process.env.NODE_ENV !== 'production' ? `.${componentId} {}` : ''
Expand Down
1 change: 1 addition & 0 deletions src/models/StyledComponent.js
Expand Up @@ -223,6 +223,7 @@ export default (ComponentStyle: Function, constructWithOptions: Function) => {

const componentStyle = new ComponentStyle(
extendingRules === undefined ? rules : extendingRules.concat(rules),
attrs,
styledComponentId,
)

Expand Down

0 comments on commit f4184ce

Please sign in to comment.