Skip to content

Commit f308f5c

Browse files
author
Max Stoiber
authored
Merge pull request #227 from styled-components/fix-ssr-object-style
fix ssr with styled HOC + object styles
2 parents aa44d5a + 0d16a72 commit f308f5c

File tree

3 files changed

+36
-8
lines changed

3 files changed

+36
-8
lines changed

src/visitors/displayNameAndId.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,18 @@ export default t => (path, state) => {
137137
if (
138138
path.node.tag
139139
? isStyled(t)(path.node.tag, state)
140-
: isStyled(t)(path.node.callee, state) &&
141-
path.node.callee.property &&
142-
path.node.callee.property.name !== 'withConfig'
140+
: /* styled()`` */ (isStyled(t)(path.node.callee, state) &&
141+
path.node.callee.property &&
142+
path.node.callee.property.name !== 'withConfig') ||
143+
// styled(x)({})
144+
(isStyled(t)(path.node.callee, state) &&
145+
!t.isMemberExpression(path.node.callee.callee)) ||
146+
// styled(x).attrs()({})
147+
(isStyled(t)(path.node.callee, state) &&
148+
t.isMemberExpression(path.node.callee.callee) &&
149+
path.node.callee.callee.property &&
150+
path.node.callee.callee.property.name &&
151+
path.node.callee.callee.property.name !== 'withConfig')
143152
) {
144153
const displayName =
145154
useDisplayName(state) &&
Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1-
const Test = styled.div`width: 100%;`;
2-
const Test2 = true ? styled.div`` : styled.div``;
1+
const Test = styled.div`
2+
width: 100%;
3+
`
4+
const Test2 = true ? styled.div`` : styled.div``
35
const styles = { One: styled.div`` }
4-
let Component;
5-
Component = styled.div``;
6-
const WrappedComponent = styled(Inner)``;
6+
let Component
7+
Component = styled.div``
8+
const WrappedComponent = styled(Inner)``
9+
const WrappedComponent2 = styled.div({})
10+
const WrappedComponent3 = styled(Inner)({})
11+
const WrappedComponent4 = styled(Inner).attrs(() => ({ something: 'else' }))({})

test/fixtures/add-identifier-and-display-name/output.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,17 @@ const WrappedComponent = styled(Inner).withConfig({
2424
displayName: "WrappedComponent",
2525
componentId: "sc-1cza72q-5"
2626
})``;
27+
const WrappedComponent2 = styled.div.withConfig({
28+
displayName: "WrappedComponent2",
29+
componentId: "sc-1cza72q-6"
30+
})({});
31+
const WrappedComponent3 = styled(Inner).withConfig({
32+
displayName: "WrappedComponent3",
33+
componentId: "sc-1cza72q-7"
34+
})({});
35+
const WrappedComponent4 = styled(Inner).attrs(() => ({
36+
something: 'else'
37+
})).withConfig({
38+
displayName: "WrappedComponent4",
39+
componentId: "sc-1cza72q-8"
40+
})({});

0 commit comments

Comments
 (0)