Skip to content
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

Component System: Upgrade FontSizePicker #27594

Merged
merged 7 commits into from
Jan 20, 2021

Conversation

ItsJonQ
Copy link

@ItsJonQ ItsJonQ commented Dec 8, 2020

This update adapts FontSizePicker from @wordpress/components with the new Component System setup.
It does this by adding the (current) external @wp-g2 component system packages as dependencies and using them directly.

This strategy was something @gziolo had suggested here:
#27484 (comment)

How has this been tested?

  • npm install
  • Run npm run dev
  • Fire up local Gutenberg
  • Edit or add a Paragraph block
  • Adjust the font-size
  • It should work like normal (and the controls may look slightly slightly different)

Screenshots

wp-g2-font-size-picker

Types of changes

  • Adding @wp-g2 dependencies
  • Add COMPONENT_SYSTEM_PHASE env flag
  • Created a context/adapter
  • Connected FontSizePicker to the component system context

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.
  • I've updated all React Native files affected by any refactorings/renamings in this PR.

@ItsJonQ ItsJonQ added the [Feature] Component System WordPress component system label Dec 8, 2020
@ItsJonQ ItsJonQ requested a review from gziolo December 8, 2020 21:13
@ItsJonQ ItsJonQ self-assigned this Dec 8, 2020
@github-actions
Copy link

github-actions bot commented Dec 8, 2020

Size Change: +122 kB (+10%) ⚠️

Total Size: 1.4 MB

Filename Size Change
build/a11y/index.js 1.14 kB +1 B (0%)
build/annotations/index.js 3.77 kB -27 B (-1%)
build/api-fetch/index.js 3.4 kB -16 B (0%)
build/autop/index.js 2.82 kB -14 B (0%)
build/block-directory/index.js 9.08 kB -3 B (0%)
build/block-editor/index.js 122 kB +828 B (+1%)
build/block-editor/style-rtl.css 11.9 kB +364 B (+3%)
build/block-editor/style.css 11.9 kB +366 B (+3%)
build/block-library/blocks/cover/style-rtl.css 1.3 kB +7 B (+1%)
build/block-library/blocks/cover/style.css 1.3 kB +6 B (0%)
build/block-library/blocks/gallery/editor-rtl.css 783 B +34 B (+5%) 🔍
build/block-library/blocks/gallery/editor.css 783 B +33 B (+4%)
build/block-library/blocks/navigation/editor-rtl.css 1.49 kB +106 B (+8%) 🔍
build/block-library/blocks/navigation/editor.css 1.48 kB +103 B (+7%) 🔍
build/block-library/blocks/paragraph/style-rtl.css 392 B +2 B (+1%)
build/block-library/blocks/paragraph/style.css 392 B +1 B (0%)
build/block-library/blocks/social-links/style-rtl.css 1.48 kB +43 B (+3%)
build/block-library/blocks/social-links/style.css 1.48 kB +43 B (+3%)
build/block-library/blocks/template-part/editor-rtl.css 794 B +80 B (+11%) ⚠️
build/block-library/blocks/template-part/editor.css 794 B +80 B (+11%) ⚠️
build/block-library/editor-rtl.css 9.2 kB +240 B (+3%)
build/block-library/editor.css 9.18 kB +223 B (+2%)
build/block-library/index.js 143 kB +1.26 kB (+1%)
build/block-library/style-rtl.css 8.65 kB +128 B (+2%)
build/block-library/style.css 8.66 kB +131 B (+2%)
build/block-serialization-default-parser/index.js 1.88 kB -9 B (0%)
build/blocks/index.js 48.2 kB +75 B (0%)
build/components/index.js 292 kB +119 kB (+69%) 🆘
build/components/style-rtl.css 15.5 kB +8 B (0%)
build/components/style.css 15.5 kB +5 B (0%)
build/compose/index.js 11.2 kB -86 B (-1%)
build/core-data/index.js 15.1 kB -75 B (0%)
build/data-controls/index.js 827 B -2 B (0%)
build/data/index.js 8.97 kB -14 B (0%)
build/date/index.js 31.8 kB +3 B (0%)
build/deprecated/index.js 769 B +1 B (0%)
build/dom/index.js 4.94 kB -13 B (0%)
build/edit-navigation/index.js 11.1 kB -79 B (-1%)
build/edit-post/index.js 306 kB -78 B (0%)
build/edit-post/style-rtl.css 6.51 kB -46 B (-1%)
build/edit-post/style.css 6.5 kB -46 B (-1%)
build/edit-site/index.js 24 kB -192 B (-1%)
build/edit-site/style-rtl.css 4.01 kB +10 B (0%)
build/edit-site/style.css 4.01 kB +10 B (0%)
build/edit-widgets/index.js 23.5 kB -69 B (0%)
build/edit-widgets/style-rtl.css 3.17 kB +10 B (0%)
build/edit-widgets/style.css 3.18 kB +12 B (0%)
build/editor/editor-styles-rtl.css 543 B +67 B (+14%) ⚠️
build/editor/editor-styles.css 545 B +67 B (+14%) ⚠️
build/editor/index.js 41.8 kB -124 B (0%)
build/element/index.js 4.61 kB -19 B (0%)
build/format-library/index.js 6.74 kB -19 B (0%)
build/html-entities/index.js 622 B -1 B (0%)
build/i18n/index.js 3.56 kB -3 B (0%)
build/is-shallow-equal/index.js 699 B +1 B (0%)
build/keyboard-shortcuts/index.js 2.53 kB -12 B (0%)
build/keycodes/index.js 1.93 kB -4 B (0%)
build/list-reusable-blocks/index.js 3.14 kB -10 B (0%)
build/media-utils/index.js 5.3 kB -11 B (0%)
build/notices/index.js 1.85 kB -2 B (0%)
build/nux/index.js 3.4 kB -21 B (-1%)
build/plugins/index.js 2.54 kB -2 B (0%)
build/primitives/index.js 1.42 kB -12 B (-1%)
build/priority-queue/index.js 791 B +2 B (0%)
build/redux-routine/index.js 2.84 kB -2 B (0%)
build/reusable-blocks/index.js 2.92 kB -5 B (0%)
build/rich-text/index.js 13.3 kB -147 B (-1%)
build/server-side-render/index.js 2.76 kB -4 B (0%)
build/shortcode/index.js 1.7 kB +1 B (0%)
build/token-list/index.js 1.27 kB +2 B (0%)
build/url/index.js 3.02 kB +1 B (0%)
build/viewport/index.js 1.86 kB +3 B (0%)
ℹ️ View Unchanged
Filename Size Change
build/blob/index.js 665 B 0 B
build/block-directory/style-rtl.css 1.01 kB 0 B
build/block-directory/style.css 1.01 kB 0 B
build/block-library/blocks/archives/editor-rtl.css 196 B 0 B
build/block-library/blocks/archives/editor.css 196 B 0 B
build/block-library/blocks/audio/editor-rtl.css 194 B 0 B
build/block-library/blocks/audio/editor.css 194 B 0 B
build/block-library/blocks/audio/style-rtl.css 225 B 0 B
build/block-library/blocks/audio/style.css 225 B 0 B
build/block-library/blocks/block/editor-rtl.css 283 B 0 B
build/block-library/blocks/block/editor.css 283 B 0 B
build/block-library/blocks/button/editor-rtl.css 576 B 0 B
build/block-library/blocks/button/editor.css 577 B 0 B
build/block-library/blocks/button/style-rtl.css 552 B 0 B
build/block-library/blocks/button/style.css 552 B 0 B
build/block-library/blocks/buttons/editor-rtl.css 345 B 0 B
build/block-library/blocks/buttons/editor.css 346 B 0 B
build/block-library/blocks/buttons/style-rtl.css 419 B 0 B
build/block-library/blocks/buttons/style.css 419 B 0 B
build/block-library/blocks/calendar/style-rtl.css 319 B 0 B
build/block-library/blocks/calendar/style.css 319 B 0 B
build/block-library/blocks/categories/editor-rtl.css 210 B 0 B
build/block-library/blocks/categories/editor.css 209 B 0 B
build/block-library/blocks/categories/style-rtl.css 208 B 0 B
build/block-library/blocks/categories/style.css 208 B 0 B
build/block-library/blocks/code/style-rtl.css 216 B 0 B
build/block-library/blocks/code/style.css 216 B 0 B
build/block-library/blocks/columns/editor-rtl.css 300 B 0 B
build/block-library/blocks/columns/editor.css 299 B 0 B
build/block-library/blocks/columns/style-rtl.css 529 B 0 B
build/block-library/blocks/columns/style.css 528 B 0 B
build/block-library/blocks/cover/editor-rtl.css 524 B 0 B
build/block-library/blocks/cover/editor.css 522 B 0 B
build/block-library/blocks/embed/editor-rtl.css 594 B 0 B
build/block-library/blocks/embed/editor.css 595 B 0 B
build/block-library/blocks/embed/style-rtl.css 489 B 0 B
build/block-library/blocks/embed/style.css 489 B 0 B
build/block-library/blocks/file/editor-rtl.css 314 B 0 B
build/block-library/blocks/file/editor.css 313 B 0 B
build/block-library/blocks/file/style-rtl.css 352 B 0 B
build/block-library/blocks/file/style.css 352 B 0 B
build/block-library/blocks/freeform/editor-rtl.css 2.55 kB 0 B
build/block-library/blocks/freeform/editor.css 2.55 kB 0 B
build/block-library/blocks/gallery/style-rtl.css 1.17 kB 0 B
build/block-library/blocks/gallery/style.css 1.17 kB 0 B
build/block-library/blocks/group/editor-rtl.css 433 B 0 B
build/block-library/blocks/group/editor.css 432 B 0 B
build/block-library/blocks/group/style-rtl.css 190 B 0 B
build/block-library/blocks/group/style.css 190 B 0 B
build/block-library/blocks/heading/editor-rtl.css 248 B 0 B
build/block-library/blocks/heading/editor.css 248 B 0 B
build/block-library/blocks/heading/style-rtl.css 212 B 0 B
build/block-library/blocks/heading/style.css 212 B 0 B
build/block-library/blocks/html/editor-rtl.css 384 B 0 B
build/block-library/blocks/html/editor.css 385 B 0 B
build/block-library/blocks/image/editor-rtl.css 801 B 0 B
build/block-library/blocks/image/editor.css 800 B 0 B
build/block-library/blocks/image/style-rtl.css 569 B 0 B
build/block-library/blocks/image/style.css 570 B 0 B
build/block-library/blocks/latest-comments/editor-rtl.css 277 B 0 B
build/block-library/blocks/latest-comments/editor.css 275 B 0 B
build/block-library/blocks/latest-comments/style-rtl.css 382 B 0 B
build/block-library/blocks/latest-comments/style.css 382 B 0 B
build/block-library/blocks/latest-posts/editor-rtl.css 254 B 0 B
build/block-library/blocks/latest-posts/editor.css 254 B 0 B
build/block-library/blocks/latest-posts/style-rtl.css 634 B 0 B
build/block-library/blocks/latest-posts/style.css 634 B 0 B
build/block-library/blocks/list/editor-rtl.css 203 B 0 B
build/block-library/blocks/list/editor.css 203 B 0 B
build/block-library/blocks/list/style-rtl.css 201 B 0 B
build/block-library/blocks/list/style.css 201 B 0 B
build/block-library/blocks/media-text/editor-rtl.css 311 B 0 B
build/block-library/blocks/media-text/editor.css 311 B 0 B
build/block-library/blocks/media-text/style-rtl.css 642 B 0 B
build/block-library/blocks/media-text/style.css 640 B 0 B
build/block-library/blocks/more/editor-rtl.css 545 B 0 B
build/block-library/blocks/more/editor.css 545 B 0 B
build/block-library/blocks/navigation-link/editor-rtl.css 503 B 0 B
build/block-library/blocks/navigation-link/editor.css 504 B 0 B
build/block-library/blocks/navigation-link/style-rtl.css 805 B 0 B
build/block-library/blocks/navigation-link/style.css 803 B 0 B
build/block-library/blocks/navigation/style-rtl.css 289 B 0 B
build/block-library/blocks/navigation/style.css 289 B 0 B
build/block-library/blocks/nextpage/editor-rtl.css 507 B 0 B
build/block-library/blocks/nextpage/editor.css 507 B 0 B
build/block-library/blocks/paragraph/editor-rtl.css 236 B 0 B
build/block-library/blocks/paragraph/editor.css 236 B 0 B
build/block-library/blocks/post-author/editor-rtl.css 329 B 0 B
build/block-library/blocks/post-author/editor.css 329 B 0 B
build/block-library/blocks/post-author/style-rtl.css 303 B 0 B
build/block-library/blocks/post-author/style.css 303 B 0 B
build/block-library/blocks/post-comments-form/style-rtl.css 358 B 0 B
build/block-library/blocks/post-comments-form/style.css 358 B 0 B
build/block-library/blocks/post-content/editor-rtl.css 262 B 0 B
build/block-library/blocks/post-content/editor.css 262 B 0 B
build/block-library/blocks/post-excerpt/editor-rtl.css 206 B 0 B
build/block-library/blocks/post-excerpt/editor.css 206 B 0 B
build/block-library/blocks/post-featured-image/editor-rtl.css 453 B 0 B
build/block-library/blocks/post-featured-image/editor.css 453 B 0 B
build/block-library/blocks/post-featured-image/style-rtl.css 223 B 0 B
build/block-library/blocks/post-featured-image/style.css 223 B 0 B
build/block-library/blocks/preformatted/style-rtl.css 193 B 0 B
build/block-library/blocks/preformatted/style.css 193 B 0 B
build/block-library/blocks/pullquote/editor-rtl.css 304 B 0 B
build/block-library/blocks/pullquote/editor.css 304 B 0 B
build/block-library/blocks/pullquote/style-rtl.css 428 B 0 B
build/block-library/blocks/pullquote/style.css 428 B 0 B
build/block-library/blocks/query-loop/editor-rtl.css 217 B 0 B
build/block-library/blocks/query-loop/editor.css 216 B 0 B
build/block-library/blocks/query-loop/style-rtl.css 427 B 0 B
build/block-library/blocks/query-loop/style.css 429 B 0 B
build/block-library/blocks/query-pagination-numbers/editor-rtl.css 243 B 0 B
build/block-library/blocks/query-pagination-numbers/editor.css 240 B 0 B
build/block-library/blocks/query-pagination/editor-rtl.css 390 B 0 B
build/block-library/blocks/query-pagination/editor.css 379 B 0 B
build/block-library/blocks/query-pagination/style-rtl.css 288 B 0 B
build/block-library/blocks/query-pagination/style.css 288 B 0 B
build/block-library/blocks/query/editor-rtl.css 279 B 0 B
build/block-library/blocks/query/editor.css 279 B 0 B
build/block-library/blocks/quote/editor-rtl.css 195 B 0 B
build/block-library/blocks/quote/editor.css 195 B 0 B
build/block-library/blocks/quote/style-rtl.css 284 B 0 B
build/block-library/blocks/quote/style.css 285 B 0 B
build/block-library/blocks/rss/editor-rtl.css 307 B 0 B
build/block-library/blocks/rss/editor.css 309 B 0 B
build/block-library/blocks/rss/style-rtl.css 394 B 0 B
build/block-library/blocks/rss/style.css 393 B 0 B
build/block-library/blocks/search/editor-rtl.css 285 B 0 B
build/block-library/blocks/search/editor.css 285 B 0 B
build/block-library/blocks/search/style-rtl.css 454 B 0 B
build/block-library/blocks/search/style.css 456 B 0 B
build/block-library/blocks/separator/editor-rtl.css 229 B 0 B
build/block-library/blocks/separator/editor.css 229 B 0 B
build/block-library/blocks/separator/style-rtl.css 352 B 0 B
build/block-library/blocks/separator/style.css 352 B 0 B
build/block-library/blocks/shortcode/editor-rtl.css 603 B 0 B
build/block-library/blocks/shortcode/editor.css 603 B 0 B
build/block-library/blocks/site-logo/editor-rtl.css 321 B 0 B
build/block-library/blocks/site-logo/editor.css 321 B 0 B
build/block-library/blocks/site-logo/style-rtl.css 238 B 0 B
build/block-library/blocks/site-logo/style.css 238 B 0 B
build/block-library/blocks/social-link/editor-rtl.css 283 B 0 B
build/block-library/blocks/social-link/editor.css 283 B 0 B
build/block-library/blocks/social-links/editor-rtl.css 811 B 0 B
build/block-library/blocks/social-links/editor.css 810 B 0 B
build/block-library/blocks/spacer/editor-rtl.css 416 B 0 B
build/block-library/blocks/spacer/editor.css 416 B 0 B
build/block-library/blocks/spacer/style-rtl.css 184 B 0 B
build/block-library/blocks/spacer/style.css 184 B 0 B
build/block-library/blocks/subhead/editor-rtl.css 223 B 0 B
build/block-library/blocks/subhead/editor.css 223 B 0 B
build/block-library/blocks/subhead/style-rtl.css 210 B 0 B
build/block-library/blocks/subhead/style.css 210 B 0 B
build/block-library/blocks/table/editor-rtl.css 593 B 0 B
build/block-library/blocks/table/editor.css 593 B 0 B
build/block-library/blocks/table/style-rtl.css 501 B 0 B
build/block-library/blocks/table/style.css 501 B 0 B
build/block-library/blocks/tag-cloud/editor-rtl.css 237 B 0 B
build/block-library/blocks/tag-cloud/editor.css 235 B 0 B
build/block-library/blocks/tag-cloud/style-rtl.css 221 B 0 B
build/block-library/blocks/tag-cloud/style.css 221 B 0 B
build/block-library/blocks/text-columns/editor-rtl.css 220 B 0 B
build/block-library/blocks/text-columns/editor.css 220 B 0 B
build/block-library/blocks/text-columns/style-rtl.css 283 B 0 B
build/block-library/blocks/text-columns/style.css 283 B 0 B
build/block-library/blocks/verse/editor-rtl.css 194 B 0 B
build/block-library/blocks/verse/editor.css 194 B 0 B
build/block-library/blocks/verse/style-rtl.css 215 B 0 B
build/block-library/blocks/verse/style.css 215 B 0 B
build/block-library/blocks/video/editor-rtl.css 617 B 0 B
build/block-library/blocks/video/editor.css 617 B 0 B
build/block-library/blocks/video/style-rtl.css 303 B 0 B
build/block-library/blocks/video/style.css 304 B 0 B
build/block-library/common-rtl.css 1.01 kB 0 B
build/block-library/common.css 1.01 kB 0 B
build/block-library/theme-rtl.css 860 B 0 B
build/block-library/theme.css 860 B 0 B
build/block-serialization-spec-parser/index.js 3.06 kB 0 B
build/dom-ready/index.js 571 B 0 B
build/edit-navigation/style-rtl.css 938 B 0 B
build/edit-navigation/style.css 944 B 0 B
build/editor/style-rtl.css 3.89 kB 0 B
build/editor/style.css 3.89 kB 0 B
build/escape-html/index.js 735 B 0 B
build/format-library/style-rtl.css 620 B 0 B
build/format-library/style.css 621 B 0 B
build/hooks/index.js 2.27 kB 0 B
build/list-reusable-blocks/style-rtl.css 629 B 0 B
build/list-reusable-blocks/style.css 628 B 0 B
build/nux/style-rtl.css 731 B 0 B
build/nux/style.css 727 B 0 B
build/warning/index.js 1.14 kB 0 B
build/wordcount/index.js 1.22 kB 0 B

compressed-size-action

@aristath
Copy link
Member

aristath commented Dec 9, 2020

Since we're doing this, would it be possible to account for other units as well and not limit this to just pixels? ❤️

@ItsJonQ
Copy link
Author

ItsJonQ commented Dec 9, 2020

would it be possible to account for other units as well and not limit this to just pixels?

Indeed! The underlying UnitInput supports it. The missing piece would be...

  • figuring out the control design to accommodate unit values (e.g. making sure the input is wide enough)
  • ensuring the value flows correctly from the hooks/styles data into the control

Copy link
Member

@jorgefilipecosta jorgefilipecosta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @ItsJonQ nice work on this PR.
It seems we have a good approach to enhance our components 👍
I think it would be nice to move the font size picker to the Gutenberg repository, e.g: if someone needs to debug the code to fix a bug the code of the component is not in this repository.

The component would then use other g2 components inside.

The prototype of g2 includes support for other units and even complex css calculations would it be possible to include the support for this or you prefer to do that in a follow-up PR?

/**
* External dependencies
*/
import { FontSizeControl } from '@wp-g2/components';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we bring the code of FontSizeControl to Gutenberg? Keeping the components used inside FontSizeControl on g2 for now?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we bring the code of FontSizeControl to Gutenberg

To do that, we would need (at minimum) all of the Components (and systems) that make up that control.
I've included a screenshot below of a high-level overview. Required components are in the yellow squares:

Screen Shot 2020-12-10 at 2 51 27 PM

Link to Miro board (source of screenshot)
https://miro.com/app/board/o9J_khVkF9A=/?moveToWidget=3074457351837142359&cot=14


Adding the systems and components to build up to FontSizeControl was the original proposal.
However, @gziolo suggested we could try consuming the @wp-g2/components package directly to expedite integration, which I think is a good idea (assuming important things like bundling aren't severely impacted)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we add FontSizeControl component (just this component) and use its dependencies from the package? The idea is that this will allow us to review the component properly in isolation and step by step we'd do the same for all its dependencies.

import { __unstableWithNext as withNext } from '../__next/context';

export function withNextComponent( current ) {
return withNext( current, FontSizeControl, 'WPComponentsFontSizePicker' );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if for something like a FontSizePicker we really need to keep two versions. I guess in this case would be ok if we just deleted the current component and used the new one?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's up to us really. It looks like FontSizePicker is only really used in one spot, that being the hooks typography tools.

The thing that is uncertain is if it's used by 3rd party blocks. In that case, I feel like it may be safer to...

  1. Start with having both
  2. Ensure it's stable
  3. Create some documentation for 3rd party devs regarding this migration (context/adapter). Announce this.
  4. See if there's any pushback
  5. If there are many people who want to keep the old FontSizePicker, provide 3rd party devs with the ability to "opt-out" (with maybe deprecation notices)
  6. Wait a bit
  7. Remove old implementation

☝️ Repeat for components as needed

const fontSizeValue =
fontSizeObject?.size || style?.typography?.fontSize || fontSize;

return <FontSizePicker onChange={ onChange } value={ fontSizeValue } />;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this mapping necessary here? Wouldn't it be something to put inside the adapter function?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this mapping necessary here?

@gziolo I believe so. style.typography.fontSize is very specific to the hooks/ part of the editor. After testing, it appears that fontSizeValue my change depending on values defined in the theme.json setup. If that's correct, the prop "remap" feels correct in this hooks/ area (vs. in the components package).

@gziolo
Copy link
Member

gziolo commented Dec 10, 2020

I already see some good impact with the latest changes applied to @wp-g2/components. It's currently at

Size Change: +104 kB (7%) 🔍

for @wordpress/components entry point in Gutenberg. It was 112 kB yesterday 😄

@gziolo gziolo force-pushed the try/next-font-size-picker-component branch from a33ff2d to 9b67597 Compare December 10, 2020 06:24
"supports-color": "^5.3.0"
}
},
"commander": {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's surprising to see commander, postcss and rtlcss on the list of dependencies. Is any of them used on the front-end?

@gziolo
Copy link
Member

gziolo commented Dec 10, 2020

This error is strange:

Screen Shot 2020-12-10 at 07 40 51

It's possible that one of the npm packages bundled with G2 components should be transpiled with Babel.

@gziolo
Copy link
Member

gziolo commented Dec 10, 2020

With 82535b6 we are now at and I only aligned versions for react-use-gesture:

Size Change: +99.5 kB (7%) 🔍

@ItsJonQ, we should upgrade all libraries that Gutenberg and G2 components share to the latest versions in Gutenberg in a separate PR. Do the same for G2 components. Regenerate the lock file and see how it looks. Maybe we can reduce the size of new code added to a reasonable size and do a more aggressive rollout :)

@gziolo gziolo force-pushed the try/next-font-size-picker-component branch from 4333452 to 2fea819 Compare December 10, 2020 07:27
@gziolo gziolo added [Type] Technical Prototype Offers a technical exploration into an idea as an example of what's possible [Package] Components /packages/components labels Dec 10, 2020
@@ -19,7 +19,8 @@
"npm": ">=6.9.0"
},
"config": {
"GUTENBERG_PHASE": 2
"GUTENBERG_PHASE": 2,
"COMPONENT_SYSTEM_PHASE": 0
Copy link
Contributor

@youknowriad youknowriad Dec 10, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this flag used for? Is't it redundunt with the "context" component provider?

Copy link
Member

@gziolo gziolo Dec 10, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We want to merge this PR with all the new code removed with Tree Shaking (100kb as of today according to the CI job) when running npm run build. This way we can integrate a few components, remove code duplication wherever possible and enable this flag (or remove completely) afterward.

So this is something that would be only enabled on demand. I think we can enable it by default on Storybook to have the place to preview migrated components.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the point of merging components and not really use them in the plugin?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can also confirm now that Tree Shaking works like a charm:
Screen Shot 2020-12-10 at 09 18 48

🎉

@gziolo
Copy link
Member

gziolo commented Dec 10, 2020

I'm happy to report that Tree Shaking is working perfectly fine 🎉

Screen Shot 2020-12-10 at 09 18 48

🎉

Now, I will enable the feature flag again. Locally, I see the following error with the flag enabled:

Screen Shot 2020-12-10 at 08 22 58

Let's see if it's confirmed on Travis. I was able to reproduce the same issue without my latest commits.

@gziolo
Copy link
Member

gziolo commented Dec 10, 2020

We are back at:

Screen Shot 2020-12-10 at 10 18 17

Some e2e tests are failing so it must be something with the recent changes to the G2 integration.

@ItsJonQ
Copy link
Author

ItsJonQ commented Dec 10, 2020

Some e2e tests are failing so it must be something with the recent changes to the G2 integration.

I think a dependency (somewhere) isn't providing an ES5 friendly module. Will investigate!

@ItsJonQ
Copy link
Author

ItsJonQ commented Dec 10, 2020

Took a look at the build file. From what I can tell, the const is coming from zustand (a dependency of @wp-g2/substate).

Screen Shot 2020-12-10 at 11 56 36 AM

It's really weird... because zustand has a .cjs.js export:

  "main": "index.cjs.js",

That one doesn't have const in it.

🤔

Not sure how to fix this one.

@gziolo
Copy link
Member

gziolo commented Dec 10, 2020

I think webpack defaults to module field rather than main with our setup. You probably can add an exception to include this package in Babel transpilation.

@ItsJonQ
Copy link
Author

ItsJonQ commented Dec 10, 2020

@gziolo Interesting!

You probably can add an exception to include this package in Babel transpilation.

How do I do that? 🙈 😂

@gziolo
Copy link
Member

gziolo commented Jan 20, 2021

@saramarcondes, did we miss any points from your feedback. Are there any blockers? I personally feel we can plan on merging this PR this week behind the feature flag or wait until we create the release branch that is going to be used for WordPress 5.7 beta. In the second case, we don't need the COMPONENT_SYSTEM_PHASE flag anymore, but we will have to work towards removing old functionalities to decrease the bundle size increase:

Screen Shot 2021-01-20 at 17 01 07

@ItsJonQ
Copy link
Author

ItsJonQ commented Jan 20, 2021

Oh boy! All green all around! Thanks for approving @saramarcondes !

@gziolo Looks like we may be ready to land this sometime this week :)

Copy link
Member

@gziolo gziolo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From my perspective you can merge it even today 😃

@sarayourfriend sarayourfriend mentioned this pull request Jan 20, 2021
6 tasks
@ItsJonQ
Copy link
Author

ItsJonQ commented Jan 20, 2021

From my perspective you can merge it even today 😃

In that case... I'm gonna do it! 🚀 🤞

@ItsJonQ ItsJonQ merged commit ec83961 into master Jan 20, 2021
@ItsJonQ ItsJonQ deleted the try/next-font-size-picker-component branch January 20, 2021 20:59
@github-actions github-actions bot added this to the Gutenberg 9.9 milestone Jan 20, 2021
@gziolo
Copy link
Member

gziolo commented Jan 20, 2021

Exciting 🎉✨🔥

@youknowriad
Copy link
Contributor

Thanks all. Nice work. We're just getting started

@gziolo
Copy link
Member

gziolo commented Jan 21, 2021

I was looking again at the code merged to idenfity all the G2 components used that we should work on porting next:

  • Button (imported 1 time)
  • ControlLabel (1)
  • Grid (2)
  • FormGroup (1)
  • SelectDropdown (1)
  • Slider (1)
  • TextInput (2)
  • View (2)
  • VisuallyHidden (1)
  • VStack (2)

@ItsJonQ, what would be your recommendation to tackle next based on the complexity. The lower the better I believe. Should we create a tracking issue to split the work between several people? It's something that we probably could help from other contributors.

There are also two imports from @wp-gw/utils that we could replace with either lodash or native JavaScript code:

  • is.defined (by the way, grouped imports prevent tree-shaking)
  • noop

We should also inline two another utils inside @wordpress/components for now:

  • createUnitValue
  • parseUnitValue

@ItsJonQ
Copy link
Author

ItsJonQ commented Jan 21, 2021

@gziolo Thank you for the follow up!

tackle next based on the complexity. The lower the better I believe.

I agree! I think we should port these components one at a time.

I created a new issue with details on how we can continue with this migration effort:
#28399

In it, I've listed the components we'll need to migrate in order of dependency and complexity.

There are also two imports from @wp-gw/utils that we could replace with either lodash or native JavaScript code:

Ah yes. We'll need to refactor the component code when we move things order to use the conventions of this codebase.

We should also inline two another utils inside @wordpress/components for now

That seems like something we can do when we move over the components that have unit parsing in them.

@gziolo
Copy link
Member

gziolo commented Jan 21, 2021

Tracking issue looks great, thanks 🙇‍♂️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Component System WordPress component system [Package] Components /packages/components [Type] Technical Prototype Offers a technical exploration into an idea as an example of what's possible
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants