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

Try #2: Upgrade @wordpress packages to pre-React 18 #73890

Merged
merged 56 commits into from
Mar 13, 2023

Conversation

tyxla
Copy link
Member

@tyxla tyxla commented Feb 28, 2023

This PR aims to upgrade the @wordpress packages to versions before upgrading to React 18.

The second take of #73155.

Does a lot of dependency and TS changes. There are some dependency compromises and specific pinning, but this PR aims to make a step forward towards updating the @wordpress packages to the latest version and restarting their regular periodic upgrades.

I think it requires thorough testing of all major flows.

@tyxla tyxla added [Status] In Progress DO NOT MERGE dependencies Pull requests that update a dependency file labels Feb 28, 2023
@tyxla tyxla self-assigned this Feb 28, 2023
@matticbot
Copy link
Contributor

matticbot commented Feb 28, 2023

@matticbot
Copy link
Contributor

This PR modifies the release build for editing-toolkit

To test your changes on WordPress.com, run install-plugin.sh editing-toolkit try/upgrade-wordpress-packages-pre-react18-2 on your sandbox.

To deploy your changes after merging, see the documentation: PCYsg-mMA-p2

@tyxla tyxla force-pushed the try/upgrade-wordpress-packages-pre-react18-2 branch 2 times, most recently from 88adc7e to 152c838 Compare February 28, 2023 18:00
@tyxla tyxla force-pushed the try/upgrade-wordpress-packages-pre-react18-2 branch from 24ec7c2 to 2a2ed8d Compare March 2, 2023 09:50
@tyxla tyxla force-pushed the try/upgrade-wordpress-packages-pre-react18-2 branch 4 times, most recently from 3713c7d to 5f6357c Compare March 8, 2023 09:35
@matticbot
Copy link
Contributor

matticbot commented Mar 8, 2023

Here is how your PR affects size of JS and CSS bundles shipped to the user's browser:

App Entrypoints (~22292 bytes added 📈 [gzipped])

name                   parsed_size           gzip_size
entry-stepper            +142425 B  (+5.8%)   +44729 B  (+6.5%)
entry-gutenboarding       +64727 B  (+2.9%)   +17403 B  (+2.7%)
entry-main                 +8550 B  (+0.6%)    +2111 B  (+0.5%)
entry-login                +5630 B  (+0.5%)    +2578 B  (+0.8%)
entry-domains-landing       -863 B  (-0.2%)      -84 B  (-0.1%)
entry-browsehappy           -717 B  (-0.7%)     -104 B  (-0.3%)

Common code that is always downloaded and parsed every time the app is loaded, no matter which route is used.

Sections (~4880 bytes removed 📉 [gzipped])

name                               parsed_size            gzip_size
settings                             +167214 B  (+24.3%)   +53608 B  (+26.2%)
account                              +166809 B  (+18.8%)   +52792 B  (+21.1%)
media                                +165309 B   (+8.6%)   +52400 B  (+10.7%)
plugins                              +164521 B   (+6.8%)   +52021 B   (+8.4%)
help                                 +149071 B  (+15.7%)   +47816 B  (+18.2%)
plans                                +148949 B  (+13.8%)   +47010 B  (+15.1%)
marketing                            +148587 B  (+24.2%)   +46575 B  (+26.6%)
settings-writing                     +148435 B  (+24.4%)   +46953 B  (+27.1%)
notification-settings                +148201 B  (+17.4%)   +47264 B  (+20.0%)
purchases                            +147924 B   (+7.8%)   +47785 B   (+9.4%)
jetpack-cloud-plugin-management      +147772 B  (+16.6%)   +46268 B  (+17.5%)
domains                              +147673 B   (+8.8%)   +46488 B  (+10.6%)
earn                                 +147387 B  (+31.6%)   +45341 B  (+32.6%)
settings-security                    +147273 B  (+37.9%)   +46508 B  (+38.8%)
settings-reading                     +147273 B  (+49.5%)   +46512 B  (+49.4%)
jetpack-cloud-agency-dashboard       +147196 B  (+23.7%)   +46856 B  (+26.0%)
jetpack-cloud-pricing                +147153 B  (+22.7%)   +46446 B  (+23.8%)
site-purchases                       +147078 B  (+10.6%)   +47044 B  (+12.7%)
settings-performance                 +147022 B  (+28.5%)   +46472 B  (+29.7%)
settings-discussion                  +147022 B  (+43.7%)   +46485 B  (+44.7%)
email                                +146870 B  (+23.2%)   +46428 B  (+25.1%)
hosting                              +145952 B  (+21.0%)   +45468 B  (+22.2%)
jetpack-connect                      +145744 B  (+13.0%)   +46189 B  (+15.3%)
sites-dashboard                      +145103 B  (+38.0%)   +47414 B  (+39.3%)
checkout                             +142385 B   (+8.7%)   +46045 B  (+10.2%)
home                                 +141071 B  (+12.5%)   +45465 B  (+14.3%)
people                               +140848 B  (+27.0%)   +44883 B  (+29.3%)
posts                                +140519 B  (+24.0%)   +44621 B  (+25.0%)
posts-custom                         +140299 B  (+23.9%)   +44696 B  (+25.0%)
reader                               +140279 B  (+22.5%)   +44759 B  (+24.5%)
themes                               +139881 B  (+18.0%)   +44385 B  (+19.2%)
preview                              +139736 B  (+51.5%)   +44505 B  (+50.1%)
customize                            +139701 B  (+50.0%)   +44488 B  (+49.9%)
comments                             +139700 B  (+18.4%)   +44896 B  (+21.8%)
theme                                +139546 B  (+28.0%)   +44315 B  (+29.6%)
pages                                +139442 B  (+27.5%)   +43966 B  (+27.7%)
stats                                +139358 B  (+20.6%)   +44767 B  (+22.9%)
backup                               +138834 B  (+15.8%)   +44605 B  (+18.4%)
activity                             +138396 B  (+20.3%)   +44045 B  (+23.1%)
jetpack-cloud-settings               +138379 B  (+26.4%)   +43930 B  (+28.5%)
scan                                 +138279 B  (+19.0%)   +44662 B  (+21.8%)
woocommerce                          +138246 B  (+52.1%)   +43945 B  (+50.6%)
settings-jetpack                     +138246 B  (+28.2%)   +43905 B  (+30.2%)
jetpack-social                       +138246 B  (+38.0%)   +44011 B  (+39.7%)
jetpack-search                       +138246 B  (+32.9%)   +43945 B  (+35.3%)
jetpack-cloud-features-comparison    +138246 B  (+24.6%)   +43903 B  (+25.9%)
jetpack-cloud                        +138246 B  (+56.1%)   +43918 B  (+54.0%)
migrate                              +138240 B  (+41.5%)   +44015 B  (+43.0%)
export                               +138141 B  (+49.0%)   +43996 B  (+48.5%)
concierge                            +138106 B  (+30.6%)   +43979 B  (+34.2%)
woocommerce-installation             +138103 B  (+47.5%)   +43926 B  (+45.9%)
google-my-business                   +138038 B  (+30.2%)   +43785 B  (+30.9%)
import                               +137933 B  (+35.8%)   +43588 B  (+35.9%)
gutenberg-editor                     +137629 B  (+26.4%)   +43530 B  (+26.7%)
add-ons                              +136760 B  (+47.8%)   +43499 B  (+46.4%)
marketplace                          +132942 B  (+20.3%)   +42400 B  (+21.2%)
promote-post                         +131331 B  (+34.4%)   +41547 B  (+34.4%)
pattern-assembler-step                -56565 B   (-4.9%)   -23707 B   (-7.0%)
import-flow                           -56197 B   (-2.0%)   -23559 B   (-3.3%)
site-blocks                           +12704 B   (+1.7%)    +4174 B   (+2.0%)
security                              +12307 B   (+1.4%)    +3457 B   (+1.4%)
privacy                               +11939 B   (+1.7%)    +4003 B   (+2.1%)
me                                    +11939 B   (+1.8%)    +4062 B   (+2.1%)
happychat                             +11933 B   (+1.7%)    +3953 B   (+2.0%)
account-close                         +11933 B   (+1.7%)    +3901 B   (+2.0%)
site-setup-flow                        +5238 B   (+0.3%)     +857 B   (+0.2%)
plugin-bundle-flow                     +4121 B   (+4.6%)     +475 B   (+1.6%)
newsletter-post-setup-flow             +3694 B   (+1.9%)     +227 B   (+0.4%)
newsletter-flow                        +2689 B   (+0.6%)     +237 B   (+0.2%)
purchase-product                       +2578 B   (+1.6%)    +1055 B   (+2.5%)
jetpack-cloud-partner-portal           +1305 B   (+0.3%)     +328 B   (+0.2%)
build-flow                             -1022 B   (-0.4%)      -25 B   (-0.1%)
write-flow                             -1019 B   (-0.4%)      -21 B   (-0.0%)
link-in-bio-tld-flow                    -971 B   (-0.1%)     -294 B   (-0.2%)
link-in-bio-flow                        -971 B   (-0.1%)     -294 B   (-0.2%)
free-flow                               -968 B   (-0.3%)      -18 B   (-0.0%)
videopress-flow                         -858 B   (-0.2%)     -309 B   (-0.3%)
signup                                  -726 B   (-0.2%)     -124 B   (-0.2%)
accept-invite                           -726 B   (-0.2%)     -122 B   (-0.1%)
devdocs                                 +382 B   (+0.2%)      +59 B   (+0.1%)
sensei-flow                             +141 B   (+0.1%)     -294 B   (-0.4%)
podcasts-flow                            +59 B   (+0.0%)     -321 B   (-0.6%)
link-in-bio-post-setup-flow              +36 B   (+0.1%)      +18 B   (+0.1%)
free-post-setup-flow                     +36 B   (+0.1%)      +18 B   (+0.1%)
trial-wooexpress-flow                    +33 B   (+0.1%)       +2 B   (+0.0%)
tailored-ecommerce-flow                  +30 B   (+0.0%)     -294 B   (-0.3%)
with-theme-assembler-flow                +23 B   (+0.7%)      +13 B   (+1.1%)
copy-site-flow                           +13 B   (+0.0%)     -319 B   (-0.4%)

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 (~14342 bytes added 📈 [gzipped])

name                                                                 parsed_size             gzip_size
async-load-design                                                      +167657 B    (+8.1%)   +53705 B   (+10.6%)
async-load-design-blocks                                               +166867 B    (+7.2%)   +52998 B    (+8.9%)
async-load-design-playground                                           +165640 B    (+9.2%)   +52342 B   (+12.1%)
async-load-calypso-lib-account-settings-helper                         +161180 B   (+55.7%)   +51000 B   (+57.1%)
async-load-quick-language-switcher                                     +159856 B  (+131.5%)   +51089 B  (+128.6%)
async-load-signup-steps-woocommerce-install-step-business-info         +139085 B  (+105.1%)   +44118 B  (+105.2%)
async-load-signup-steps-woocommerce-install-confirm                    +139065 B  (+134.7%)   +45113 B  (+138.9%)
async-load-signup-steps-clone-point                                    +139039 B   (+63.6%)   +45082 B   (+77.1%)
async-load-calypso-components-sites-popover                            +138339 B   (+82.8%)   +44466 B   (+82.1%)
async-load-signup-steps-site-picker                                    +137572 B   (+70.6%)   +43828 B   (+70.3%)
async-load-signup-steps-difm-site-picker                               +137572 B   (+68.6%)   +43840 B   (+68.0%)
async-load-signup-steps-website-content                                +137086 B  (+101.5%)   +44328 B  (+101.1%)
async-load-signup-steps-p2-complete-profile                            +136973 B   (+89.1%)   +44338 B   (+94.5%)
async-load-signup-steps-plans-pm                                       +136843 B   (+47.2%)   +44294 B   (+53.8%)
async-load-signup-steps-plans-atomic-store                             +136843 B   (+62.6%)   +44307 B   (+75.4%)
async-load-signup-steps-plans                                          +136843 B   (+38.5%)   +44324 B   (+43.5%)
async-load-signup-steps-theme-selection                                +136837 B   (+79.3%)   +44310 B   (+89.7%)
async-load-signup-steps-design-picker                                  +136729 B  (+121.8%)   +44285 B  (+128.9%)
async-load-signup-steps-woocommerce-install-transfer                   +136683 B  (+172.7%)   +44263 B  (+182.0%)
async-load-signup-steps-woocommerce-install                            +136683 B  (+257.2%)   +44234 B  (+262.9%)
async-load-signup-steps-user                                           +136683 B   (+75.0%)   +44289 B   (+83.5%)
async-load-signup-steps-test-step                                      +136683 B  (+198.1%)   +44269 B  (+207.4%)
async-load-signup-steps-store-features                                 +136683 B  (+149.1%)   +44269 B  (+154.2%)
async-load-signup-steps-starting-point                                 +136683 B  (+161.9%)   +44269 B  (+166.2%)
async-load-signup-steps-social-profiles                                +136683 B  (+182.8%)   +44271 B  (+192.7%)
async-load-signup-steps-site-type                                      +136683 B  (+187.3%)   +44267 B  (+197.7%)
async-load-signup-steps-site-title                                     +136683 B  (+189.8%)   +44273 B  (+200.7%)
async-load-signup-steps-site-or-domain                                 +136683 B  (+156.5%)   +44267 B  (+167.4%)
async-load-signup-steps-site-options                                   +136683 B  (+152.2%)   +44271 B  (+162.7%)
async-load-signup-steps-site                                           +136683 B  (+149.2%)   +44290 B  (+162.2%)
async-load-signup-steps-rewind-were-backing                            +136683 B  (+193.8%)   +44268 B  (+202.8%)
async-load-signup-steps-rewind-migrate                                 +136683 B  (+146.8%)   +44265 B  (+152.2%)
async-load-signup-steps-rewind-form-creds                              +136683 B  (+123.1%)   +44265 B  (+126.2%)
async-load-signup-steps-reader-landing                                 +136683 B  (+185.2%)   +44270 B  (+197.2%)
async-load-signup-steps-page-picker                                    +136683 B  (+132.4%)   +44266 B  (+139.7%)
async-load-signup-steps-p2-site                                        +136683 B  (+135.4%)   +44289 B  (+144.1%)
async-load-signup-steps-p2-join-workspace                              +136683 B  (+173.1%)   +44245 B  (+177.4%)
async-load-signup-steps-p2-get-started                                 +136683 B  (+187.4%)   +44237 B  (+191.3%)
async-load-signup-steps-p2-details                                     +136683 B  (+187.4%)   +44240 B  (+191.1%)
async-load-signup-steps-p2-confirm-email                               +136683 B  (+182.8%)   +44231 B  (+186.1%)
async-load-signup-steps-new-or-existing-site                           +136683 B  (+152.6%)   +44269 B  (+156.8%)
async-load-signup-steps-intent                                         +136683 B  (+156.9%)   +44269 B  (+160.9%)
async-load-signup-steps-emails                                         +136683 B  (+126.0%)   +44268 B  (+132.4%)
async-load-signup-steps-creds-permission                               +136683 B  (+143.4%)   +44266 B  (+144.2%)
async-load-signup-steps-creds-confirm                                  +136683 B  (+143.6%)   +44264 B  (+144.6%)
async-load-signup-steps-creds-complete                                 +136683 B  (+193.9%)   +44269 B  (+202.6%)
async-load-signup-steps-courses                                        +136683 B  (+172.4%)   +44269 B  (+180.2%)
async-load-signup-steps-clone-start                                    +136683 B  (+180.5%)   +44264 B  (+189.4%)
async-load-signup-steps-clone-ready                                    +136683 B  (+141.8%)   +44264 B  (+147.7%)
async-load-signup-steps-clone-jetpack                                  +136683 B  (+189.2%)   +44265 B  (+200.3%)
async-load-signup-steps-clone-destination                              +136683 B  (+166.3%)   +44270 B  (+179.3%)
async-load-signup-steps-clone-credentials                              +136683 B  (+119.0%)   +44268 B  (+122.9%)
async-load-signup-steps-clone-cloning                                  +136683 B  (+181.6%)   +44264 B  (+190.4%)
async-load-calypso-blocks-inline-help-popover                          +135748 B   (+20.0%)   +43347 B   (+22.5%)
async-load-calypso-blocks-jitm-templates-modal                         +135486 B  (+228.5%)   +43879 B  (+230.3%)
async-load-signup-steps-woocommerce-install-step-store-address         +135437 B  (+104.1%)   +43359 B  (+103.0%)
async-load-signup-steps-domains                                        +135417 B   (+29.7%)   +43353 B   (+33.6%)
async-load-signup-steps-add-ons                                        +133681 B  (+117.0%)   +43170 B  (+115.8%)
async-load-automattic-help-center                                      +132827 B   (+21.8%)   +42140 B   (+24.5%)
async-load-automattic-design-preview-src-components-style-variation     -58503 B    (-5.0%)   -25404 B    (-7.3%)
async-load-automattic-design-preview                                    -50609 B    (-4.6%)   -22843 B    (-6.9%)
async-load-calypso-post-editor-editor-media-modal                       +25622 B    (+1.5%)    +7283 B    (+1.7%)
async-load-calypso-post-editor-media-modal                              +19679 B    (+1.2%)    +5565 B    (+1.4%)
async-load-calypso-reader-search-stream                                  +9034 B    (+7.8%)    +2527 B    (+7.7%)
async-load-calypso-reader-following-manage                               +9034 B    (+6.5%)    +2527 B    (+6.4%)
async-load-calypso-reader-site-stream                                    +8901 B   (+14.9%)    +2495 B   (+13.1%)
async-load-calypso-reader-feed-stream                                    +8901 B   (+14.9%)    +2495 B   (+13.1%)
async-load-calypso-components-web-preview-component                      -6102 B    (-1.2%)    -2614 B    (-1.7%)
async-load-calypso-my-sites-site-settings-seo-settings-form              -3639 B    (-1.3%)     -108 B    (-0.1%)
async-load-calypso-my-sites-checkout-modal                               +2682 B    (+0.2%)     +950 B    (+0.3%)
async-load-calypso-blocks-editor-checkout-modal                          +2568 B    (+0.2%)    +1185 B    (+0.4%)
async-load-calypso-layout-masterbar-drafts-popover                       +2249 B    (+6.0%)     +788 B    (+6.1%)
async-load-design-wordpress-components-gallery                           -2210 B    (-0.3%)   +14176 B    (+7.0%)
async-load-calypso-layout-masterbar-checkout                             +1988 B    (+2.9%)     +790 B    (+3.7%)
async-load-masterbar-help-center                                         +1985 B    (+7.2%)     +790 B    (+9.4%)
async-load-publish                                                       +1462 B    (+2.9%)     +286 B    (+1.8%)
async-load-calypso-layout-masterbar-checkout-tsx                          -738 B    (-0.6%)     +144 B    (+0.4%)
async-load-calypso-blocks-support-article-dialog-dialog                   +545 B    (+0.2%)     +686 B    (+0.9%)
async-load-calypso-lib-preferences-helper                                 +464 B    (+0.4%)     +139 B    (+0.4%)
async-load-calypso-my-sites-stats-wordads                                 +299 B    (+1.2%)     -685 B    (-8.1%)
async-load-calypso-layout-guided-tours-component                          +239 B    (+0.3%)      +17 B    (+0.1%)
async-load-calypso-blocks-app-banner                                      -156 B    (-0.1%)      -24 B    (-0.0%)
async-load-calypso-blocks-inline-help                                     -146 B    (-1.1%)      -12 B    (-0.3%)
async-load-store-app-store-stats-listview                                 +140 B    (+0.2%)      +23 B    (+0.1%)
async-load-store-app-store-stats                                          +140 B    (+0.1%)      +21 B    (+0.0%)
async-load-calypso-blocks-support-article-dialog                          +108 B    (+3.2%)      +29 B    (+2.3%)
async-load-calypso-my-sites-plan-features-2023-grid                        -65 B    (-0.1%)      -20 B    (-0.2%)
async-load-signup-steps-website-content-section-types                      -36 B    (-0.1%)     -212 B    (-1.1%)
async-load-calypso-my-sites-stats-stats-post-detail                        +35 B    (+0.1%)      +10 B    (+0.1%)

React components that are loaded lazily, when a certain part of UI is displayed for the first time.

Moment.js Locales (~3055 bytes added 📈 [gzipped])

name                   parsed_size            gzip_size
moment-locale-bn-bd        +2795 B     (new)    +1170 B     (new)
moment-locale-es-mx        +2386 B     (new)    +1055 B     (new)
moment-locale-hi           +2016 B  (+80.9%)     +273 B  (+23.6%)
moment-locale-sr-cyrl       +296 B  (+11.2%)      +68 B   (+5.8%)
moment-locale-sr            +224 B  (+10.4%)      +67 B   (+6.5%)
moment-locale-tg            +187 B   (+8.6%)      +43 B   (+4.0%)
moment-locale-pl            +171 B   (+7.8%)      +60 B   (+5.6%)
moment-locale-cs            +127 B   (+4.2%)      +47 B   (+3.8%)
moment-locale-ru             +66 B   (+1.4%)      +17 B   (+1.0%)
moment-locale-th             +58 B   (+2.6%)      +17 B   (+1.8%)
moment-locale-ro             +43 B   (+3.2%)      +22 B   (+2.8%)
moment-locale-bg             +42 B   (+2.3%)      +16 B   (+1.6%)
moment-locale-it             +36 B   (+2.1%)      +15 B   (+1.9%)
moment-locale-hu             +34 B   (+1.6%)      +19 B   (+1.9%)
moment-locale-fr             +33 B   (+1.6%)      +15 B   (+1.6%)
moment-locale-vi             +32 B   (+1.9%)      +11 B   (+1.3%)
moment-locale-es             +32 B   (+1.4%)      +19 B   (+1.8%)
moment-locale-pt             +31 B   (+2.2%)      +15 B   (+1.9%)
moment-locale-es-us          +31 B   (+1.3%)      +13 B   (+1.3%)
moment-locale-es-do          +31 B   (+1.3%)      +15 B   (+1.5%)
moment-locale-pt-br          +29 B   (+2.0%)      +24 B   (+3.1%)
moment-locale-nl             +29 B   (+1.4%)      +11 B   (+1.1%)
moment-locale-tr             +28 B   (+1.6%)      +16 B   (+1.7%)
moment-locale-nn             +26 B   (+1.9%)       +8 B   (+1.1%)
moment-locale-nb             +24 B   (+1.8%)      +13 B   (+1.8%)
moment-locale-zh-cn          +22 B   (+1.1%)       +6 B   (+0.6%)

Locale data for moment.js. Unless you are upgrading the moment.js library, changes in these chunks are suspicious.

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.
Gzip Size: Compressed size of the JS and CSS files. This much data needs to be downloaded over network.

Generated by performance advisor bot at iscalypsofastyet.com.

@tyxla tyxla force-pushed the try/upgrade-wordpress-packages-pre-react18-2 branch 2 times, most recently from 400d12e to 4c40d8e Compare March 8, 2023 15:52
@Automattic Automattic deleted a comment from github-actions bot Mar 8, 2023
@noahtallen
Copy link
Contributor

The e2e issue happens in this context:

  1. Create a new account on calypso.live
  2. Start creating a site. Go through the domain step and choose the free plan.
  3. After the domain step, change the URL path to /setup/site-setup/intent?siteSlug=, and then keep the slug that was added in the domain step (can be autogenerated)
  4. Observe that import site is disabled.

Screenshot 2023-03-08 at 10 35 44 AM

This does not happen in production, and it also doesn't happen when I'm logged into my main account in calypso.live.

@noahtallen
Copy link
Contributor

The fix was pretty straightforward:

https://github.com/Automattic/wp-calypso/blob/608c1624d8460f036acd6d9856fe1ee78369c3cd/client/landing/stepper/hooks/use-site.ts#L10-L21

In this code, siteId isn't immediately available -- it updates after a second or so. As a result, siteId needs to be in the dependency array for the useSelect call which retrieves the site. The formerly empty dependency array meant that the site object was never retrieved (because siteId is initially undefined), which meant the "import site capability check" didn't work, which disabled the import site button, which failed the e2e test.

The main concern I have from this is whether there are other instances of useSelect calls which now have empty dependency arrays, but actually do depend on some data changing

Copy link
Contributor

@noahtallen noahtallen left a comment

Choose a reason for hiding this comment

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

Amazing work here @tyxla! This is a huge amount of changes for the upgrade 😅 Hopefully the next round is easier!

With the e2e bug fix, I realized that this PR adds empty dependency arrays ([]) to a lot of useSelect calls without necessarily adding dependencies. I went through the PR and commented on each missing dependency I could find in each useSelect call where we're adding the dependency array. (I think this should be as extensive as possible with human eyes 😅)

Some of these might not be functionally needed, but I think it's worth fixing just in case they would introduce bugs. I decided to comment first, and then I'll work on updating all of them.

Edit: updated all of these in 5955722

@noahtallen noahtallen force-pushed the try/upgrade-wordpress-packages-pre-react18-2 branch from 87108f1 to 5955722 Compare March 8, 2023 23:50
Copy link
Member Author

@tyxla tyxla left a comment

Choose a reason for hiding this comment

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

Thank you for your help addressing the last bits, @noahtallen! 🙌

I've spent quite some time verifying that these are all correct and I've made some observations about a few that we could further polish. This took a while: 😅

Screenshot 2023-03-09 at 12 35 59

I'll take care of them immediately, and do some smoke testing before marking this as ready to review.

"@wordpress/dom-ready": "^3.22.0",
"@wordpress/edit-post": "^6.19.0",
"@wordpress/editor": "^12.21.0",
"@wordpress/element": "^4.20.0",
"@wordpress/env": "^4.7.0",
Copy link
Member Author

Choose a reason for hiding this comment

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

Noting that we intentionally didn't change this dependency, because:

  • The @wordpress/env package isn't a dependency of any other package and doesn't have any other packages as dependencies. Therefore, it can be updated separately and independently.
  • There's a breaking change in the way the PHPUnit tests are set up. Ideally, we should take care of that in a separate PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

Good observation, that matches my experience with wp-env updates. (I also have a WIP PR somewhere for this phpunit change, which I should resurrect!)

@@ -164,8 +163,7 @@ const mapDispatchToProps = ( dispatch, ownProps ) => {
};
};

export default compose(
Copy link
Member Author

Choose a reason for hiding this comment

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

Necessary because compose types aren't very friendly, but dealing with them is work for another time and another PR.

@@ -167,23 +167,21 @@
"@types/validator": "^13.7.1",
"@types/webpack-env": "^1.16.3",
"@types/wordpress__api-fetch": "^3.2.4",
"@types/wordpress__block-editor": "^6.0.5",
Copy link
Member Author

Choose a reason for hiding this comment

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

We are removing some of those type packages because they augment or redeclare the @wordpress/data types, which is in direct conflict with the new way we're consuming @wordpress/data types - directly from the package.

"@wordpress/interface@^4.8.0": "patch:@wordpress/interface@npm%3A4.8.0#./.yarn/patches/@wordpress-interface-npm-4.8.0-8a39ad37cf.patch"
"@wordpress/base-styles": "4.13.0",
"@wordpress/interface@^4.8.0": "patch:@wordpress/interface@npm%3A4.8.0#./.yarn/patches/@wordpress-interface-npm-4.8.0-8a39ad37cf.patch",
"@wordpress/data-controls": "2.22.0",
Copy link
Member Author

Choose a reason for hiding this comment

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

Pinning to avoid type conflicts and a waterfall of unwanted dependencies.

"@wordpress/base-styles": "4.13.0",
"@wordpress/interface@^4.8.0": "patch:@wordpress/interface@npm%3A4.8.0#./.yarn/patches/@wordpress-interface-npm-4.8.0-8a39ad37cf.patch",
"@wordpress/data-controls": "2.22.0",
"@wordpress/element": "4.20.0"
Copy link
Member Author

Choose a reason for hiding this comment

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

This package has been a bit merciless with breaking changes sneaking into minor versions, so we need to pin it down to avoid them inadvertently sneaking into the code.

packages/help-center/src/components/help-center.tsx Outdated Show resolved Hide resolved
export type Status = 'error' | 'info' | 'success' | 'warning';
}

declare module '@wordpress/rich-text' {
Copy link
Member Author

Choose a reason for hiding this comment

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

These two are a classic example of types we needed to specifically declare because those packages also attempted to declare the @wordpress/data module, which directly entered in conflict with the new package-provided @wordpres/data types. Ideally, each of those packages should provide types directly.

Copy link
Contributor

Choose a reason for hiding this comment

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

Do you think it'd be worth trying to fix the DT defs? (https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/wordpress__rich-text/index.d.ts)

Technically, I guess those are broken for everyone with new wordpress data versions.

@@ -70,6 +70,8 @@ const Guide: React.FC< Props > = ( { children, className, onFinish } ) => {
<div className="guide__buttons">
{ currentPage > 0 && (
<Button className="guide__back-button" isTertiary onClick={ goBack }>
{ /* eslint-disable-next-line @typescript-eslint/ban-ts-comment */ }
{ /* @ts-ignore This is declared as a global variable and provided by webpack. */ }
Copy link
Member Author

Choose a reason for hiding this comment

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

Necessary because multiple packages are attempting to declare this global.

@tyxla tyxla force-pushed the try/upgrade-wordpress-packages-pre-react18-2 branch 2 times, most recently from 1641572 to d8da603 Compare March 9, 2023 11:49
@tyxla
Copy link
Member Author

tyxla commented Mar 9, 2023

The failing e2e tests are flaky and seem to be failing in other branches.

I think this one is ready for review 👀

@tyxla tyxla marked this pull request as ready for review March 9, 2023 13:12
@tyxla tyxla requested a review from a team as a code owner March 9, 2023 13:12
@tyxla tyxla force-pushed the try/upgrade-wordpress-packages-pre-react18-2 branch from 012518d to b8a0f10 Compare March 13, 2023 08:06
@tyxla
Copy link
Member Author

tyxla commented Mar 13, 2023

Given that most of the changes are TS changes and I have a green light, in light of how quickly this can get stale, I'm inclined to ship it now. I already did extensive testing and I'm going to do so on staging, too.

Thanks everyone 🙌

@tyxla tyxla merged commit 9651d4a into trunk Mar 13, 2023
@tyxla tyxla deleted the try/upgrade-wordpress-packages-pre-react18-2 branch March 13, 2023 09:26
@tyxla
Copy link
Member Author

tyxla commented Mar 13, 2023

The latest commit is causing a maximum update depth exceeded error in React. 🙃 This happened when I added a dependency on extraOptions here:

https://github.com/Automattic/wp-calypso/blob/fa4359eb5aadc44f5c8b0ced4d3a0e7d6135aeed/packages/domain-picker/src/hooks/use-domain-suggestions.ts#L66

It's an interesting case to be aware of!

// Say you have this function:
function useFoo( options ) {
  return useSelect( select => select( 'foo' ).getFoo( options ), [ options ] )
}

// And you use it like this:
function FooComponent() {
  const foo = useFoo( { option: 'test' } );
  return <span>{ foo }</span>;
}

You're passing the object { option: 'test' } to the selector's dependencies. Even though the object value never changes, a new object is created on every render of the component. This causes the selector to be re-executed on every render, which (as I understand) causes another render, which can ultimately cause an infinite loop, which crashes the application when React detects it.

cc @jsnajdr - could this be something we could detect and prevent within @wordpress/data?

@jsnajdr
Copy link
Member

jsnajdr commented Mar 13, 2023

This causes the selector to be re-executed on every render, which (as I understand) causes another render

Yes, with ever-changing extraOptions, the selector will be called on every render. That in itself is not that bad, it's like if the useSelect didn't specify any dependencies, and that's quite common.

The bad thing is that the selector returns a different value on each call, although the inputs are, at least semantically, the same. So, the main question is why getDomainSuggestions() returns a new object each time. That's the actual reason for triggering a re-render, and, in turn, an infinite loop.

The getDomainSuggestions selector calls the __internalGetDomainSuggestions selector, which has one argument, a query object. When @wordpress/data tracks resolution status for the selector with various args, it stores the args in equivalent-key-map, which should treat deeply equal query objects as equal. I'd check if this really happens for getDomainSuggestions query: does equivalent-key-map really consider equal query objects as equal?

A second place where query object equality is checked is the reducer that stores the query results. Here the query object is serialized to a string with the stringifyDomainQueryObject helper. This is another thing to check: are equal query objects serialized to the same string?

could this be something we could detect and prevent within @wordpress/data?

If it turns out that equivalent-keys-map could do its deep equality check better, then yes, we could improve it.

Other than that, this is more like a typical React issue with immutability and effect dependencies, not something @wordpress/data specific.

@noahtallen
Copy link
Contributor

Nice clarification!

@a8ci18n
Copy link

a8ci18n commented Apr 4, 2023

Translation for this Pull Request has now been finished.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependencies Pull requests that update a dependency file [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. [Type] Tooling Related to tools, scripts, automation, DevX, etc.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants