Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't add the data-jsx attribute to components instances (patch) #71

Merged
merged 1 commit into from
Jan 5, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,14 @@ export default function ({types: t}) {
}

const el = path.node

if (el.name &&
(el.name.name !== 'style' && el.name.name !== STYLE_COMPONENT)) {
const {name} = el.name || {}

if (
name &&
name !== 'style' &&
name !== STYLE_COMPONENT &&
name.charAt(0) !== name.charAt(0).toUpperCase()
) {
for (const attr of el.attributes) {
if (attr.name === MARKUP_ATTRIBUTE) {
// avoid double attributes
Expand Down
11 changes: 11 additions & 0 deletions test/fixtures/component-attribute.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const Test = () => (
<div>
<span>test</span>
<Component />
<style jsx>{`
span {
color: red;
}
`}</style>
</div>
)
6 changes: 6 additions & 0 deletions test/fixtures/component-attribute.out.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import _JSXStyle from "styled-jsx/style";
const Test = () => <div data-jsx={1535297024}>
<span data-jsx={1535297024}>test</span>
<Component />
<_JSXStyle styleId={1535297024} css={"span[data-jsx=\"1535297024\"] {color: red;}"} />
</div>;
2 changes: 1 addition & 1 deletion test/fixtures/multiple-jsx.out.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import _JSXStyle from "styled-jsx/style";
const Test1 = () => <div data-jsx={1535297024}>
<span data-jsx={1535297024}>test</span>
<Component data-jsx={1535297024} />
<Component />
<_JSXStyle styleId={1535297024} css={"span[data-jsx=\"1535297024\"] {color: red;}"} />
</div>;

Expand Down
6 changes: 6 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ test('works with multiple jsx blocks', async t => {
t.is(code, out.trim())
})

test('should not add the data-jsx attribute to components instances', async t => {
const {code} = await transform('./fixtures/component-attribute.js')
const out = await read('./fixtures/component-attribute.out.js')
t.is(code, out.trim())
})

test('server rendering', t => {
function App() {
return React.createElement('div', null,
Expand Down