Styled-components maintenance mode: A 40% faster fork
8 months ago
- #styled-components
- #React
- #performance
- 由于在React 18的useInsertionEffect中存在性能问题,styled-components不再推荐用于新项目。
- styled-components维护者宣布进入维护模式,表明在没有'use client'指令的情况下无法与React Server Components兼容。
- Sanity创建了styled-components的性能优化分支,实现了useInsertionEffect,渲染速度提升高达40%。
- 该分支还优化了其他方面,例如用原生方法替代用户层面的数组操作,并现代化构建输出。
- Linear报告称在切换到Sanity的分支后,初始组件渲染性能提升了40%。
- Sanity的分支通过消除对ServerStyleSheet的需求,简化了React 19中的流式SSR。
- 该分支旨在作为临时解决方案提升性能,同时团队规划彻底迁移脱离styled-components。
- Sanity建议采用三阶段方案:立即使用分支缓解问题、停止新增styled-components使用、规划完整迁移。
- 这些分支已开源,可供其他团队在过渡到现代样式方案时使用。