-
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
extract shuffle into js-utils and use it to randomize the themes on /start flow #57344
Conversation
Link to Calypso live: https://calypso.live?image=registry.a8c.com/calypso/app:build-17810 |
51364e1
to
c5fd682
Compare
401e974
to
bd08002
Compare
Here is how your PR affects size of JS and CSS bundles shipped to the user's browser: App Entrypoints (~33 bytes added 📈 [gzipped])
Common code that is always downloaded and parsed every time the app is loaded, no matter which route is used. Sections (~26 bytes added 📈 [gzipped])
Sections contain code specific for a given set of routes. Is downloaded and parsed only when a particular route is navigated to. Async-loaded Components (~58 bytes added 📈 [gzipped])
React components that are loaded lazily, when a certain part of UI is displayed for the first time. Legend What is parsed and gzip size?Parsed Size: Uncompressed size of the JS and CSS files. This much code needs to be parsed and stored in memory. Generated by performance advisor bot at iscalypsofastyet.com. |
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 for considering not using Lodash! I think shuffle
is a good candidate for @automattic/js-utils
now that we need to use it in multiple packages.
I can see this PR is still a draft, but I thought some early feedback could be helpful.
In a nutshell, @automattic/js-utils@0.1.0
was never released, so we should keep the version intact.
packages/js-utils/package.json
Outdated
@@ -1,6 +1,6 @@ | |||
{ | |||
"name": "@automattic/js-utils", | |||
"version": "0.1.0", | |||
"version": "0.2.0", |
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.
0.1.0
has never been released, so there's no need to bump the version here. Let's make sure to revert all the related changes to package.json
and yarn.lock
.
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.
good point!
@@ -1 +1,2 @@ | |||
export { default as uniqueBy } from './unique-by'; | |||
export { default as shuffle } from './shuffle'; |
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.
Nit: Should we keep the list alphabetically sorted?
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.
Maybe we should have a look at https://www.npmjs.com/package/eslint-plugin-sort-exports
thanks for the feedback @tyxla ! I've made those changes, hopefully the only thing left to do is get CI passing 🤞 |
@@ -32,6 +32,7 @@ | |||
}, | |||
"dependencies": { | |||
"@automattic/calypso-config": "^1.0.0-alpha.0", | |||
"@automattic/js-utils": "^0.1.0", |
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.
Let's also add js-utils
to the references list in tsconfig.json
of the design-picker
package.
That should resolve the Cannot find module '@automattic/js-utils' or its corresponding type declarations.
error.
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.
thank you!
packages/tsconfig.json
Outdated
@@ -6,6 +6,7 @@ | |||
|
|||
// Reference all TS packages | |||
"references": [ | |||
{ "path": "./js-utils" }, // define js-utils first so that it will be build before packages that depend on it |
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.
Small typo here:
{ "path": "./js-utils" }, // define js-utils first so that it will be build before packages that depend on it | |
{ "path": "./js-utils" }, // define js-utils first so that it will be built before packages that depend on it |
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.
I removed this, I think that this order was only relevant because I'd forgotten to add it to the tsconfig of design-picker as a dependency 😂
Thanks for finding that I had forgot to add the dependency to |
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.
Works well and looks good from my perspective 👍 🚢
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.
Well done!
Changes proposed in this Pull Request
Fixes #56832 by giving a random sort to themes presented in the design picker. This will prevent certain themes from being prioritized and will allow us to see which themes are the most often selected.
There was an existing
random
function used in the design-picker package, but we could not share this since we use the theme API to load designs instead of the design pickersgetAvailableDesigns
method. Since we're migrating away from lodash (p4TIVU-9Bf-p2) andshuffle
is a lodash function, I've migrated shuffleArray into ourjs-utils
library.Testing instructions
Test the design picker with
/start/design-setup-site?siteSlug=YOUR_SITE.wordpress.com Test the existing
/newflow by going to
/new` and navigating to the design picker step.