Skip to content

Commit af6bf95

Browse files
authored
Merge pull request #27 from cssinjs/feature/fix-styles-remount
Fix #26
2 parents 877f1ae + 4f5aacb commit af6bf95

3 files changed

Lines changed: 32 additions & 3 deletions

File tree

src/styled.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ const styled = ({tagName, elementStyle, mountSheet}: StyledArgs) => {
5656
this.sheet.addRule(this.dynamicTagName, dynamicStyle)
5757
}
5858

59-
classMap[this.dynamicTagName] = rulesIndex.slice(rulesTotal)
59+
classMap[this.dynamicTagName] = classMap[this.dynamicTagName] || rulesIndex.slice(rulesTotal)
6060
this.updateSheet(this.props)
6161
}
6262

@@ -83,8 +83,8 @@ const styled = ({tagName, elementStyle, mountSheet}: StyledArgs) => {
8383

8484
const props = filterProps(attrs)
8585
const tagClass = composeClasses([
86-
this.sheet.classes[staticTagName],
87-
this.sheet.classes[this.dynamicTagName],
86+
staticTagName && this.sheet.classes[staticTagName],
87+
this.dynamicTagName && this.sheet.classes[this.dynamicTagName],
8888
className
8989
])
9090

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,15 @@ exports[`functional tests should update props and unmount 2`] = `
7575
color: yellow;
7676
}"
7777
`;
78+
79+
exports[`functional tests should use props on remount 1`] = `
80+
".button-1-id {
81+
color: black;
82+
}"
83+
`;
84+
85+
exports[`functional tests should use props on remount 2`] = `
86+
".button-1-id {
87+
color: red;
88+
}"
89+
`;

src/tests/functional.spec.jsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,21 @@ describe('functional tests', () => {
9393
assertSheet(sheet)
9494
wrapper.unmount()
9595
})
96+
97+
it('should use props on remount', () => {
98+
const Button = styled('button')({
99+
color: props => (props.primary ? 'red' : 'black')
100+
})
101+
102+
const wrapper = mount(<Button />)
103+
const sheet = styled.mountSheet()
104+
105+
assertSheet(sheet)
106+
wrapper
107+
.unmount()
108+
.mount()
109+
.setProps({primary: true})
110+
assertSheet(sheet)
111+
wrapper.unmount()
112+
})
96113
})

0 commit comments

Comments
 (0)