Skip to content

Commit

Permalink
fix static styles wrapping dynamic styles being wrongly identified as…
Browse files Browse the repository at this point in the history
… static (#3250)
  • Loading branch information
willheslam committed Sep 2, 2020
1 parent df65868 commit 792e41d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/styled-components/src/models/ComponentStyle.js
Expand Up @@ -28,7 +28,9 @@ export default class ComponentStyle {
constructor(rules: RuleSet, componentId: string, baseStyle?: ComponentStyle) {
this.rules = rules;
this.staticRulesId = '';
this.isStatic = process.env.NODE_ENV === 'production' && isStaticRules(rules);
this.isStatic = process.env.NODE_ENV === 'production' &&
(baseStyle === undefined || baseStyle.isStatic) &&
isStaticRules(rules);
this.componentId = componentId;

// SC_VERSION gives us isolation between multiple runtimes on the page at once
Expand Down
24 changes: 24 additions & 0 deletions packages/styled-components/src/test/staticCaching.test.js
Expand Up @@ -42,6 +42,18 @@ describe('static style caching', () => {

expect(Comp.componentStyle.isStatic).toEqual(false);
});

it('should mark a static style wrapping a dynamic style as not static', () => {
const Inner = styled.div`
color: ${props => props.color};
`;

const Outer = styled(Inner)`
padding: 5px;
`;

expect(Outer.componentStyle.isStatic).toEqual(false);
});
});

describe('production mode', () => {
Expand Down Expand Up @@ -82,5 +94,17 @@ describe('static style caching', () => {

expect(Comp.componentStyle.isStatic).toEqual(false);
});

it('should mark a static style wrapping a dynamic style as not static', () => {
const Inner = styled.div`
color: ${props => props.color};
`;

const Outer = styled(Inner)`
padding: 5px;
`;

expect(Outer.componentStyle.isStatic).toEqual(false);
});
});
});

0 comments on commit 792e41d

Please sign in to comment.