-
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
Add Muriel TextControl to calypso-ui #34277
Conversation
This is a terrible hacky work-around for an issue in @wordpress/components. @wordpress/components relies on @wordpress/priority-queue, which tries to use things on window directly. This breaks when it gets pulled into our build/bundle by the server webpack build, the build cannot start. By adding text-control to index, this transitively pulls in @wordpress/components, which pulls in priority-queue, which breaks. Work around it by going after screen-reader-text directly. This is not a long term solution. Ideally wordpress components would work from within a node process.
Here is how your PR affects size of JS and CSS bundles shipped to the user's browser: Webpack Runtime (~225 bytes removed 📉 [gzipped])
Webpack runtime for loading modules. It is included in the HTML page as an inline script. Is downloaded and parsed every time the app is loaded. App Entrypoints (~895 bytes removed 📉 [gzipped])
Common code that is always downloaded and parsed every time the app is loaded, no matter which route is used. Sections (~22060 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 (~304634 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. |
webpack.config.js
Outdated
@@ -2,6 +2,7 @@ | |||
**** WARNING: No ES6 modules here. Not transpiled! **** | |||
*/ | |||
/* eslint-disable import/no-nodejs-modules */ | |||
/* eslint-disable import/no-extraneous-dependencies */ |
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.
what was this tripping?
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 had was getting errors for duplicate-package-checker-webpack-plugin
, webpack
, but I've backed this change out for now.
11:17 error 'webpack' should be listed in the project's dependencies. Run 'npm i -S webpack' to add it import/no-extraneous-dependencies
15:39 error 'duplicate-package-checker-webpack-plugin' should be listed in the project's dependencies. Run 'npm i -S duplicate-package-checker-webpack-plugin' to add it import/no-extraneous-dependencies
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.
ah, those are real errors. we're getting away with not having them in the root package.json because of how npm is current hoisting dependencies from packages/calypso-build
. If we require
or import
them, they should be in the closest package.json
.
…, and fix failing tests
Thanks for the feedback and tip @blowery. I've pushed some changes here, including an adjustment to the |
/** | ||
* Internal dependencies | ||
*/ | ||
import { default as ProgressBar } from '@automattic/calypso-ui/dist/esm/progress-bar'; |
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.
Why don't we just import { ProgressBar } from
@automattic/calypso-ui? The
dist/esm` directory structure should be an encapsulated implementation detail of the package, not a commonly used part of public interface.
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.
See p1560968242000900-slack-components
the tl;dr is that ScreenReader
breaks SSR and ProgressBar
breaks in tests because of window
being undefined, if we pull in all of calypso-ui
here (@wordpress/components loads some dependencies that use window
).
There is a Gutenberg PR open to guard against the usage breaking this: WordPress/gutenberg#16227 -- so this is meant to be temporary.
The 149kb increase in design and playground is a bit concerning. I assume that's because we can't tree-shake |
I found WordPress/gutenberg#13910, so it looks like this hasn't been done yet. |
149kB compressed JS is quite substantial; that's 88% of the total recommended JS budget for an entire web application, and it'll take a long time to run and execute in a slow device on a slow network. I realise this is just devdocs for now, but if the goal is to use these in Calypso, we definitely need to address the tree-shaking situation first, or risk making Calypso around 25% slower to load than it is now. |
I might need some guidance on what to do here. This is the only component that we need like this on the Calypso side for our project. If #34138 doesn't help here, should I instead build these styles/behavior on top of the Calypso component and revisit making an exportable copy in the future? |
I'd recommend to do it the way that's desirable from the long term view. If the bundle size increases now, we can accept that for some time. We've made a lot of performance and bundle size improvements over the last months and years, and we can take a short-term loan against these savings 🙂 It's good to be aware of the issue (we are) and have a plan to solve it (we do). It doesn't need to be a blocker. |
This PR introduces a Muriel styled
TextControl
component to thecalypso-ui
package. The styles are implemented on top of@wordpress/components
. This component has been lifted from https://github.com/Automattic/newspack-plugin. This PR also fixes the issues outlined in Automattic/newspack-plugin#75.This will be used in WooCommerce onboarding, and it's related connection piece in Calypso, so that these styles match inputs on both sides of the flow.
Please note: if you look at the Muriel components Figma, not all of the various modes for the Muriel inputs have been implemented. Only the "contained" style that both Newspack and wc-admin are currently using. This is meant to be a start, that can be immediately consumed by these packages, and we can continue adding the alternatives in the future.
Screenshots
Testing instructions
npm run distclean && npm ci
npm start
http://calypso.localhost:3000/devdocs/design/text-control
and look at / test the TextControl component.