Skip to content

Commit 163f798

Browse files
authored
Merge pull request #68 from cssinjs/feature/bug-67
fix for issue #67
2 parents a7d65aa + 51b3b20 commit 163f798

3 files changed

Lines changed: 25 additions & 0 deletions

File tree

src/styled.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ const styled = ({element, ownStyle, mountSheet, jss}: StyledArgs) => {
6666
class StyledElement extends Component<StyledElementPropsType, StateType> {
6767
static tagName: string = tagName
6868
static style: ComponentStyleType[] = elementStyle
69+
70+
// If the base component is a React component (and thus neither an intrinsic tag or a
71+
// styled element), make sure to keep a reference to the component around. Otherwise deeply
72+
// nested styled elements won't render the base component correctly.
73+
static reactComponent = reactComponent
74+
6975
static contextTypes = {
7076
[channel]: object
7177
}

src/tests/__snapshots__/index.spec.jsx.snap

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,3 +111,11 @@ exports[`base rendering tests renders correctly App with injectStyled 1`] = `
111111
</div>
112112
</div>
113113
`;
114+
115+
exports[`base rendering tests renders nested compositions correctly 1`] = `
116+
<div
117+
className="C1-23-0-1-25"
118+
>
119+
Test
120+
</div>
121+
`;

src/tests/index.spec.jsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,15 @@ describe('base rendering tests', () => {
4545

4646
expect(tree).toMatchSnapshot()
4747
})
48+
49+
it('renders nested compositions correctly', () => {
50+
const C1 = ({children, className}: { children: any, className?: string }) => (
51+
<div className={className}>{children}</div>
52+
)
53+
const C2 = styled(C1)({color: '#333'})
54+
const C3 = styled(C2)({padding: 3})
55+
const tree = renderer.create(<C3>Test</C3>).toJSON()
56+
57+
expect(tree).toMatchSnapshot()
58+
})
4859
})

0 commit comments

Comments
 (0)