-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Framework: Substitute crypto polyfill dependants with smaller stand-ins #17356
Conversation
I'm not sure if it's related but devdocs/blocks isn't loading for me on this branch. |
client/components/popover/index.jsx
Outdated
@@ -361,7 +361,7 @@ class Popover extends Component { | |||
} | |||
|
|||
setPopoverId( id ) { | |||
this.id = id || `pop__${ uid( 16 ) }`; | |||
this.id = id || `pop__${ uuid() }`; |
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.
This line is almost unneeded. If we think that it's better to get rid of it let's do it. I could do it in a next PR as well.
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.
A static incrementing number could work just as well, yeah. (Or nothing at all)
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.
Yeah, lodash/uniqueId
seems better (and simpler) for this case. It actually guarantees that it will be unique, while uuid
can't.
client/lib/wp/sync-handler/utils.js
Outdated
@@ -1,11 +1,10 @@ | |||
/** | |||
* External dependencies | |||
*/ | |||
import sha1 from 'js-sha1'; | |||
import sha1 from 'hash.js/lib/hash/sha/1'; |
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.
in fact, we could get rid of sync-handler as well. In this way, we could clean this module completely.
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.
in fact, we could get rid of sync-handler as well. In this way, we could clean this module completely.
Yeah, I figured sync handler is on its way out. Most of the pieces are already there with the newer custom post type screen (i.e. caching post responses for future use). I think the remaining issue is whether we need to preserve existing UIs (especially with newer features like re-Publicize) and how we extend CPT components to support those cases. Regardless, it's a bigger issue than one I want to address here, and I think it'll be good to keep the sync handler around until a full replacement can be made.
@aduth This PR needs a rebase |
2569696
to
7722dd2
Compare
😲 |
@aduth This PR needs a rebase |
7722dd2
to
1558328
Compare
I did some testing of this and couldn't find any regressions to areas mentioned 👍 |
1558328
to
5dde395
Compare
Rebased and replaced the Popover's |
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.
Thanks @aduth this tests well for me
Thanks for catching the overlap @gwwar |
A few of our dependencies, namely
component-uid
andjs-sha1
, themselves have dependencies oncrypto
:https://github.com/emn178/js-sha1/blob/c724643/src/sha1.js#L52-L53
https://github.com/component/uid/blob/2d912b8/index.js#L45 (It appears they try to avoid the polyfill, but it is included in a Webpack build)
crypto
is a Node built-in module which is polyfilled in the browser by crypto-browserify. This polyfill is quite substantial in size.The changes here seek to find suitable replacements for each:
(Lodash'suuid
uniqueId
) andhash.js
respectively, which are very reasonable in size.Aside: I first suspected
uuid
to also requirecrypto
, but it turns out they bundle a browser-specific variant without the dependency.The difference is pretty noticeable: 472kb smaller minified (112kb gzipped) in the main
build.js
.Before:
After:
Testing instructions:
Verify against regressions for the two modules affected:
Ensure unit tests pass: