Skip to content
New issue

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

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

Already on GitHub? # to your account

feat: tansform jsx to html #1304

Merged
merged 5 commits into from
Aug 30, 2019
Merged

feat: tansform jsx to html #1304

merged 5 commits into from
Aug 30, 2019

Conversation

chenjun1011
Copy link
Collaborator

@chenjun1011 chenjun1011 commented Aug 29, 2019

pre tansform jsx to html for better ssr performance.

input

<div className="container" style={style} onClick={onClick}>
  <div>a {props.index}</div>
</div>

output

[{
  __html: "<div class=\\"container\\""
}, {
  __attrs: {
    style: style,
    onClick: onClick
  }
}, {
  __html: ">"
}, [{
  __html: "<div>"
}, "a ", props.index, {
  __html: "</div>"
}], {
  __html: "</div>"
}]

benchmark (use inline style, about 1000 nodes)

mean:0.883ms
React#renderToString x 1,132 ops/sec ±2.17% (84 runs sampled)
mean:0.315ms
Rax#renderToString x 3,173 ops/sec ±1.64% (86 runs sampled)

benchmark (use className, about 1000 nodes))

mean:0.626ms
React#renderToString x 1,598 ops/sec ±3.11% (82 runs sampled)
mean:0.099ms
Rax#renderToString x 10,101 ops/sec ±1.85% (83 runs sampled)
mean:0.075ms
Marko#renderToString x 13,332 ops/sec ±2.45% (85 runs sampled)
mean:0.090ms
Xtpl#renderFile x 11,065 ops/sec ±5.92% (67 runs sampled)

@wssgcg1213
Copy link
Collaborator

再测一下 JSXSpreadAttribute 试试: <div {...props} />

Copy link
Collaborator

@wssgcg1213 wssgcg1213 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed

@chenjun1011
Copy link
Collaborator Author

after merge sibling string

benchmark (use className, about 1000 nodes)

mean:0.634ms
React#renderToString x 1,578 ops/sec ±5.26% (82 runs sampled)
mean:0.070ms
Rax#renderToString x 14,249 ops/sec ±1.54% (83 runs sampled)
mean:0.187ms
Inferno#renderToString x 5,357 ops/sec ±1.56% (83 runs sampled)
mean:0.073ms
Marko#renderToString x 13,758 ops/sec ±1.81% (84 runs sampled)
mean:0.095ms
Xtpl#renderFile x 10,551 ops/sec ±9.05% (66 runs sampled)

__html: "<div>"
}, "a ", props.index, {
__html: "</div>"
}], {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

README 可以更新下

{
"name": "babel-plugin-transform-jsx-to-html",
"version": "0.1.0",
"description": "Transform JSX to Html.",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Html -> HTML

}], [{
__html: "<div>b</div>"
}]);`);
});
Copy link
Collaborator

@yuanyan yuanyan Aug 29, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[{ __html: "<div>a</div>" }], [{ __html: "<div>b</div>" }] 优化为 [{ __html: "<div>a</div>" }, { __html: "<div>b</div>" }] 是不是更好?

@yuanyan yuanyan merged commit 431ecc3 into master Aug 30, 2019
@delete-merged-branch delete-merged-branch bot deleted the feat-jsx-to-html branch August 30, 2019 16:55
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants