-
Notifications
You must be signed in to change notification settings - Fork 585
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
Create a reusable alias for each forwardRef'd component #479
base: master
Are you sure you want to change the base?
Create a reusable alias for each forwardRef'd component #479
Conversation
54b5f56
to
c6fc4eb
Compare
@afc163 @zombieJ @John60676 any chance I can get a review on this PR? I expect it'll have a great downstream effect for you and your users! |
/rebase |
c6fc4eb
to
4b7ecc8
Compare
CI failed, could you fix it?
|
I've pushed the changes, but I don't seem to be getting a full CI run. |
@afc163 just checking in - is there an easy way to kick off the CI? |
Pinging @tangjinzhou @zombieJ @afc163 @hullis, this is an old PR but will likely speed up load time, check time, and memory usage for everyone using ant-design |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Must fix CI firstly, I'll do that asap |
@DanielRosenwasser could you please rebase master? |
8839fdf
to
7baf55b
Compare
@vagusX thanks for following up - I was on vacation back then. I've rebased the commits. |
Conflicting |
This is a slightly experimental PR since I'm not that familiar with the codebase; however, an investigation on compiling ant-design uncovered that a lot of string literal type syntax nodes were being created during parsing. We found that many of them came directly from the
.d.ts
files of@ant-design/icons
.This is because
React.forwardRef
creates several anonymous intermediate types and TypeScript's declaration emit ends up having to write those types inline. Those types each contain over 360 string literals which are all the same!However, if we create a type alias (here called
ForwardRefComponentBase
) and annotate every component with that type, the declaration emit will reuse that type instead.This brings the size down of each component from 5.98KB to 165 byes. This cumulatively brings down the size of your declaration files from 4.66MB to 189KB.
That's a substantial reduction of the size of your published packages. It will also reduce the amount of code that TypeScript needs to parse and keep in memory for all users, meaning faster builds for all your consumers.
It's not highly scientific, but here's a before/after of just doing type-checking
@ant-design/icons
: