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

babel-plugin-transform-jsx-stylesheet 存在性能问题 #345

Closed
DremyGit opened this issue Jun 9, 2020 · 1 comment
Closed

babel-plugin-transform-jsx-stylesheet 存在性能问题 #345

DremyGit opened this issue Jun 9, 2020 · 1 comment

Comments

@DremyGit
Copy link

DremyGit commented Jun 9, 2020

一个 Component 同时配置 className 与 style 字段时,会编译成如下:

<Component style={Object.assign({}, _styleSheet[className], style)} />

来自:
https://github.com/raxjs/rax-scripts/blob/c4565b0ef73d5a76aa77910952cb4e3f864aa487/packages/babel-plugin-transform-jsx-stylesheet/src/tests/index.js#L254-L269

这样会直接导致通过 memo 和 PureComponent 进行优化的 Component 优化无效。

react-perf/jsx-no-new-object-as-prop

是否可能将 className 与 style 的合并结果进行缓存,从而不影响 memo 和 PureComponent 的组件优化呢?

@SoloJiang
Copy link
Contributor

内联方案的取舍问题,在将 className 转换到内联的时候,本质从浏览器渲染的角度来说会提升性能,但是会造成你所提到的 PureComponent or memo 失效的问题,由于涉及到 ast 解析以及侵犯过多的业务代码,框架本身难以去内置这部分优化,而且从 memo 处理的角度,可以从业务代码层面加入一些处理来避免复杂组件的 rerender

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants