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

Editor: Introduce Gutenberg in Calypso behind feature flag #44801

Closed
wants to merge 13 commits into from

Conversation

sarayourfriend
Copy link
Contributor

@sarayourfriend sarayourfriend commented Aug 10, 2020

Changes proposed in this Pull Request

  • Add a new editor path that displays Gutenberg without an iframe - this only appears when a new AB test is in the "on" variant.

This will allow us to more easily test ongoing work to fix Calypso's global styles. By checking for specific things that need to be fixed, we may be able to better prioritize somethings over others (like Buttons may not be necessary to fix immediately as they seem to be okay, but the FormRadio and FormCheckbox do need to be fixed).

Ongoing discussion here p9oQ9f-iN-p2.

AB test

The AB test will always bucket people into the "off" variant. This is correct and desired because we want to be able to easily test Gutenberg in Calypso as we make new style changes without introducing changes to the front-end.

Testing instructions

  • Ensure that by default you are bucketed into the "off" variant of the new AB test
  • When in the off variant, ensure that you cannot reach the new editor through navigation (i.e., ensure that the "write" button and post lists all navigate you to the iframed editor)
  • When in the "on" variant, ensure that you are directed towards Gutenberg in Calypso

Fixes #

@matticbot
Copy link
Contributor

@matticbot matticbot added the [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. label Aug 10, 2020
@sarayourfriend sarayourfriend marked this pull request as draft August 10, 2020 15:03
@matticbot
Copy link
Contributor

matticbot commented Aug 10, 2020

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

Webpack Runtime (~156 bytes added 📈 [gzipped])

name      parsed_size           gzip_size
manifest       +818 B  (+1.2%)     +156 B  (+1.0%)

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

name                   parsed_size            gzip_size
entry-gutenboarding      +177991 B  (+10.4%)   +42433 B  (+9.4%)
entry-main                 +4279 B   (+0.3%)     +280 B  (+0.1%)
entry-login                 +105 B   (+0.0%)      +10 B  (+0.0%)
entry-domains-landing       +105 B   (+0.0%)      +10 B  (+0.0%)

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

Sections (~1042822 bytes added 📈 [gzipped])

name                    parsed_size            gzip_size
gutenberg-in-calypso     +3270012 B    (new)  +1177660 B    (new)
gutenberg-editor            +3533 B  (+0.9%)      +851 B  (+0.7%)
jetpack-connect             +3126 B  (+0.4%)      -345 B  (-0.2%)
plans                       +2974 B  (+0.4%)      +256 B  (+0.1%)
woocommerce                 +2860 B  (+0.1%)      +179 B  (+0.0%)
settings                    +2860 B  (+0.5%)      +202 B  (+0.1%)
hosting                     +2860 B  (+1.0%)      +200 B  (+0.2%)
jetpack-cloud-pricing       +2844 B  (+0.7%)       +64 B  (+0.1%)
reader                      +2610 B  (+0.5%)     +2006 B  (+1.4%)
account                     +2491 B  (+0.5%)      +170 B  (+0.1%)
pages                        +446 B  (+0.2%)      +109 B  (+0.1%)
domains                      +433 B  (+0.0%)       +26 B  (+0.0%)
purchases                    +430 B  (+0.0%)      -361 B  (-0.1%)
site-purchases               +410 B  (+0.0%)      +500 B  (+0.2%)
zoninator                    +369 B  (+0.2%)       +30 B  (+0.1%)
themes                       +369 B  (+0.1%)       +31 B  (+0.0%)
theme                        +369 B  (+0.1%)       +31 B  (+0.0%)
stats                        +369 B  (+0.1%)       +30 B  (+0.0%)
sites                        +369 B  (+0.4%)       +30 B  (+0.1%)
settings-writing             +369 B  (+0.1%)       +34 B  (+0.0%)
settings-security            +369 B  (+0.1%)       +31 B  (+0.0%)
settings-performance         +369 B  (+0.1%)       +31 B  (+0.0%)
settings-jetpack             +369 B  (+0.1%)       +31 B  (+0.0%)
settings-discussion          +369 B  (+0.1%)       +31 B  (+0.0%)
sensei                       +369 B  (+0.3%)       +30 B  (+0.1%)
scan                         +369 B  (+0.1%)       +31 B  (+0.0%)
preview                      +369 B  (+0.2%)       +30 B  (+0.1%)
plugins                      +369 B  (+0.1%)       +30 B  (+0.0%)
migrate                      +369 B  (+0.2%)       +30 B  (+0.1%)
marketing                    +369 B  (+0.1%)       +31 B  (+0.0%)
jetpack-search               +369 B  (+0.2%)       +31 B  (+0.1%)
jetpack-cloud-settings       +369 B  (+0.2%)       +30 B  (+0.1%)
jetpack-cloud                +369 B  (+0.3%)       +30 B  (+0.1%)
import                       +369 B  (+0.1%)       +30 B  (+0.0%)
home                         +369 B  (+0.1%)       +32 B  (+0.0%)
hello-dolly                  +369 B  (+0.3%)       +30 B  (+0.1%)
google-my-business           +369 B  (+0.1%)       +30 B  (+0.0%)
export                       +369 B  (+0.2%)       +31 B  (+0.0%)
customize                    +369 B  (+0.2%)       +31 B  (+0.0%)
concierge                    +369 B  (+0.1%)       +31 B  (+0.0%)
comments                     +369 B  (+0.1%)       +14 B  (+0.0%)
backup                       +369 B  (+0.1%)       +33 B  (+0.0%)
activity                     +369 B  (+0.1%)       +32 B  (+0.0%)
checkout                     +367 B  (+0.0%)      -124 B  (-0.0%)
wp-super-cache               +320 B  (+0.1%)        +3 B  (+0.0%)
people                       +320 B  (+0.1%)        -2 B  (-0.0%)
media                        +320 B  (+0.1%)        +5 B  (+0.0%)
earn                         +320 B  (+0.1%)        +5 B  (+0.0%)
signup                       +309 B  (+0.1%)       +63 B  (+0.1%)
email                        +303 B  (+0.1%)      -179 B  (-0.2%)
posts-custom                 +215 B  (+0.1%)       +14 B  (+0.0%)
posts                        +215 B  (+0.1%)       +14 B  (+0.0%)

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

name                                                      parsed_size           gzip_size
async-load-design-wordpress-components-gallery                +6021 B  (+0.9%)     +515 B  (+0.3%)
async-load-calypso-blocks-editor-launch-modal                 +4022 B  (+1.8%)     +482 B  (+0.8%)
async-load-calypso-components-web-preview-component           +3547 B  (+0.6%)     +511 B  (+0.3%)
async-load-calypso-blocks-editor-checkout-modal               +3251 B  (+0.3%)     +437 B  (+0.2%)
async-load-design-blocks                                      +2552 B  (+0.1%)     -225 B  (-0.0%)
async-load-quick-language-switcher                            +2491 B  (+1.8%)     +170 B  (+0.4%)
async-load-design-playground                                  +2491 B  (+0.1%)     -216 B  (-0.0%)
async-load-design                                             +2491 B  (+0.1%)     -215 B  (-0.0%)
async-load-calypso-my-sites-current-site-domain-warnings        +28 B  (+0.0%)       +9 B  (+0.1%)
async-load-signup-steps-plans                                   -16 B  (-0.0%)      -43 B  (-0.1%)
async-load-calypso-my-sites-sidebar-unified                     +14 B  (+0.0%)       +8 B  (+0.0%)
async-load-calypso-my-sites-sidebar                             +14 B  (+0.0%)       +8 B  (+0.0%)
async-load-calypso-components-jetpack-sidebar                   +14 B  (+0.0%)       +8 B  (+0.1%)

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.
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.

Copy link
Collaborator

@wp-desktop wp-desktop left a comment

Choose a reason for hiding this comment

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

WordPress Desktop CI Failure for job "wp-desktop-source".

@saramarcondes please inspect this job's build steps for breaking changes at this link. For temporal failures, you may try to "Rerun Workflow from Failed".

Please also ensure this branch is rebased off latest Calypso.

@nsakaimbo
Copy link
Contributor

nsakaimbo commented Aug 10, 2020

👋 Hi, @saramarcondes! Could you rebase this PR on latest Calypso master? We merged some fixes into master that should mitigate the out-of-memory ENOMEM build errors we've been experiencing more frequently over the last couple weeks. That should get the source building more reliably again.

@wp-desktop wp-desktop dismissed their stale review August 10, 2020 16:06

wp-desktop ci passing, closing review

@ockham
Copy link
Contributor

ockham commented Aug 10, 2020

FWIW, I have some notes lying around locally on how to get a server-less Gutenberg (Site Editor) to work which I hope to put in writing later this week 🙂 (Specifically related to wp/data / REST API stuff.)

@sarayourfriend sarayourfriend force-pushed the add/gutenberg-in-calypso-poc branch 3 times, most recently from 307b8f0 to f772f94 Compare August 11, 2020 01:59
@dmsnell
Copy link
Contributor

dmsnell commented Aug 12, 2020

Lovely work! I might borrow from it to improve the Gutenberg playground waiting for some unrelated fixes in #44153

Copy link
Contributor

@diegohaz diegohaz left a comment

Choose a reason for hiding this comment

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

Very nice work! Styles will be a great challenge! But other than that the editor is running pretty smoothly and the experience feels much better than with the iframe.

<BlockEditorProvider
value={ blocks }
onInput={ updateBlocks }
onChange={ updateBlocks }
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems that the inserter crash is happening because the block editor is expecting some settings to exist, but they don't exist in Calypso. I don't know if it makes sense having those settings in Calypso, but an easy solution is just passing them to the BlockEditorProvider component:

Suggested change
onChange={ updateBlocks }
onChange={ updateBlocks }
settings={ {
__experimentalBlockPatternCategories: [],
__experimentalBlockPatterns: [],
} }

But it looks like a bug on Gutenberg. It shouldn't be expecting those settings to be set, especially since they're experimental settings. I'll propose a change there.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks @diegohaz! That fixed it perfectly!

function Gutenberg( props ) {
const { postId, siteId, postType } = props;

setCurrentSiteId( siteId );
Copy link
Contributor Author

Choose a reason for hiding this comment

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

/cc @ockham

Copy link
Collaborator

@wp-desktop wp-desktop left a comment

Choose a reason for hiding this comment

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

WordPress Desktop CI Failure for job "wp-desktop-mac".

@saramarcondes please inspect this job's build steps for breaking changes at this link. For temporal failures, you may try to "Rerun Workflow from Failed".

Please also ensure this branch is rebased off latest Calypso.

@sarayourfriend sarayourfriend changed the title WIP: Gutenberg in Calypso Editor: Introduce Gutenberg in Calypso behind never-on AB test Sep 3, 2020
@wp-desktop wp-desktop dismissed their stale review September 3, 2020 22:04

wp-desktop ci passing, closing review

@sarayourfriend sarayourfriend marked this pull request as ready for review September 4, 2020 14:25
@sarayourfriend
Copy link
Contributor Author

@sgomes ccing you on this PR, if you have time I'd love some insight into the performance aspect of what I'm doing here. Is there anything else I should take into consideration that I haven't already?

@sarayourfriend sarayourfriend changed the title Editor: Introduce Gutenberg in Calypso behind never-on AB test Editor: Introduce Gutenberg in Calypso behind feature flag Sep 8, 2020
@sarayourfriend
Copy link
Contributor Author

@sgomes Thanks for the help. I'm very confused why Gutenboarding is affected at all, I haven't done anything in that area. Is it because I'm importing new @wordpress packages?

@sgomes
Copy link
Contributor

sgomes commented Sep 21, 2020

Sorry for the late reply, @saramarcondes! I've been AFK for the past week.

I'm very confused why Gutenboarding is affected at all, I haven't done anything in that area. Is it because I'm importing new @WordPress packages?

Interesting. At first glance, I'd say this is likely either due to webpack heuristics or some newly-added package duplication. I'll investigate 👍

@jsnajdr
Copy link
Member

jsnajdr commented Sep 21, 2020

At first glance, I'd say this is likely either due to webpack heuristics or some newly-added package duplication.

@sgomes The answer here is probably the same as in a similar issue in PR that adds WordPress Components Gallery to devdocs: the modules shipped in Gutenboarding are still exactly the same, but as many of them are now used in multiple chunks, opportunities for module concatenation optimization disappeared: #45523 (comment)

@sgomes
Copy link
Contributor

sgomes commented Sep 21, 2020

Thanks, @jsnajdr, that makes sense and is a very likely cause! 👍

I'll give this a quick look-over to see if I can make sure that's the case.

@sgomes
Copy link
Contributor

sgomes commented Sep 21, 2020

Looking at yark.lock I see some weird duplicates, which match both the requested and resolved version. I don't think I've seen those before, and I'm not sure what they'll do to the bundle. E.g.:

"@wordpress/components@^10.0.5":
  version "10.0.5"
  resolved "https://registry.yarnpkg.com/@wordpress/components/-/components-10.0.5.tgz#00b72751dc928e554e77b44408cf18f938ef3a88"
  integrity sha512-kR6LqSwvOh2yzZuAips8DjFbBEaSlDifIw65x7FwQgwCpHS9LlzOuqljmOCSieBgrlbnCaBOFeXFeKuvog7seA==
  dependencies:
    "@babel/runtime" "^7.9.2"
    "@emotion/core" "^10.0.22"
    "@emotion/css" "^10.0.22"
    "@emotion/native" "^10.0.22"
    "@emotion/styled" "^10.0.23"
    "@wordpress/a11y" "^2.11.0"
    "@wordpress/compose" "^3.19.3"
    "@wordpress/deprecated" "^2.9.0"
    "@wordpress/dom" "^2.13.1"
    "@wordpress/element" "^2.16.0"
    "@wordpress/hooks" "^2.9.0"
    "@wordpress/i18n" "^3.14.0"
    "@wordpress/icons" "^2.4.0"
    "@wordpress/is-shallow-equal" "^2.1.0"
    "@wordpress/keycodes" "^2.14.0"
    "@wordpress/primitives" "^1.7.0"
    "@wordpress/rich-text" "^3.20.4"
    "@wordpress/warning" "^1.2.0"
    classnames "^2.2.5"
    dom-scroll-into-view "^1.2.1"
    downshift "^5.4.0"
    gradient-parser "^0.1.5"
    lodash "^4.17.15"
    memize "^1.1.0"
    moment "^2.22.1"
    re-resizable "^6.4.0"
    react-dates "^17.1.1"
    react-resize-aware "^3.0.1"
    react-spring "^8.0.20"
    react-use-gesture "^7.0.15"
    reakit "^1.1.0"
    rememo "^3.0.0"
    tinycolor2 "^1.4.1"
    uuid "^7.0.2"

"@wordpress/components@^10.0.5":
  version "10.0.5"
  resolved "https://registry.yarnpkg.com/@wordpress/components/-/components-10.0.5.tgz#00b72751dc928e554e77b44408cf18f938ef3a88"
  integrity sha512-kR6LqSwvOh2yzZuAips8DjFbBEaSlDifIw65x7FwQgwCpHS9LlzOuqljmOCSieBgrlbnCaBOFeXFeKuvog7seA==
  dependencies:
    "@babel/runtime" "^7.9.2"
    "@emotion/core" "^10.0.22"
    "@emotion/css" "^10.0.22"
    "@emotion/native" "^10.0.22"
    "@emotion/styled" "^10.0.23"
    "@wordpress/a11y" "^2.11.0"
    "@wordpress/compose" "^3.19.3"
    "@wordpress/deprecated" "^2.9.0"
    "@wordpress/dom" "^2.13.1"
    "@wordpress/element" "^2.16.0"
    "@wordpress/hooks" "^2.9.0"
    "@wordpress/i18n" "^3.14.0"
    "@wordpress/icons" "^2.4.0"
    "@wordpress/is-shallow-equal" "^2.1.0"
    "@wordpress/keycodes" "^2.14.0"
    "@wordpress/primitives" "^1.7.0"
    "@wordpress/rich-text" "^3.20.4"
    "@wordpress/warning" "^1.2.0"
    classnames "^2.2.5"
    dom-scroll-into-view "^1.2.1"
    downshift "^5.4.0"
    gradient-parser "^0.1.5"
    lodash "^4.17.15"
    memize "^1.1.0"
    moment "^2.22.1"
    re-resizable "^6.4.0"
    react-dates "^17.1.1"
    react-resize-aware "^3.0.1"
    react-spring "^8.0.20"
    react-use-gesture "^7.0.15"
    reakit "^1.1.0"
    rememo "^3.0.0"
    tinycolor2 "^1.4.1"
    uuid "^7.0.2"

@scinos Any idea what this could mean?

@jsnajdr
Copy link
Member

jsnajdr commented Sep 21, 2020

I'll give this a quick look-over to see if I can make sure that's the case.

On the other hand, 12% size increase is big. The component gallery PR caused increase only on 1% scale. Maybe there are other issues there.

@sgomes
Copy link
Contributor

sgomes commented Sep 21, 2020

There are definitely duplicates going on here. For example, a lot of space seems to be taken up by two copies of components/welcome-guide/images.js, which appears to be an extremely ill-advised collection of SVG-in-JS 🤦 :

image

@sgomes
Copy link
Contributor

sgomes commented Sep 21, 2020

I just pushed a change that deduplicates @wordpress packages. Let's wait for ICFY to see if it gets rid of the duplicates.

@scinos
Copy link
Contributor

scinos commented Sep 21, 2020

Looking at yark.lock I see some weird duplicates, which match both the requested and resolved version

I would guess that's the result of a bad merge. In theory that shouldn't affect bundling.

@sgomes
Copy link
Contributor

sgomes commented Sep 21, 2020

Deduplicating @wordpress packages doesn't seem to have had much of an effect.

@sgomes
Copy link
Contributor

sgomes commented Sep 21, 2020

Right, I think I understand what's going on. This appears to be down to the definition of a module, and the fact that across a build, it can only have a single definition.

In essence, the issue is due to tree-shaking. Previously, Gutenboarding was able to tree-shake some things in @wordpress packages away, since it was not using them. However, since these things are now being used in the new section, they can't be tree-shaken away.

To be clear, this is ordinarily not an issue, with each thing ending up in its own section, as needed; leaf modules get moved to where they're needed. However, due to the way these particular @wordpress modules are set up (with heavy use of re-exports) and their sideEffects package.json configuration, that becomes impossible, since the re-exporting module becomes locked with all of its imports. So for these modules, everything that actually gets used anywhere in Calypso must be defined at any point that anything is. That is, it's all-or-nothing.

This could possibly be fixed or at least mitigated with some more aggressive side-effect handling on @wordpress packages, but that's proven difficult in the past.

@sgomes
Copy link
Contributor

sgomes commented Sep 21, 2020

At this point, I'd consider trying out the new Gutenberg-in-Calypso section not as a separate entrypoint, but rather as a separate application / build altogether. It will definitely be larger, by not sharing anything with the Calypso builds, but the tradeoff of keeping unnecessary stuff out of Gutenboarding could be worth it.

The other option, of course, is to just accept the increase and live with it. In the context of an unproven experiment, though, that becomes a bit harder to justify 😕

@sarayourfriend sarayourfriend changed the base branch from master to trunk November 20, 2020 16:12
@matticbot matticbot removed the [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. label Mar 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

10 participants