提交 f4184cee 编写于 作者: R Ryan Schwers

Fix static caching of dynamic attrs

上级 e99bc6a8
......@@ -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]
......@@ -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
}
......@@ -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} {}` : ''
......
......@@ -223,6 +223,7 @@ export default (ComponentStyle: Function, constructWithOptions: Function) => {
const componentStyle = new ComponentStyle(
extendingRules === undefined ? rules : extendingRules.concat(rules),
attrs,
styledComponentId,
)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册