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

[ETK][GB 13.x] Fix loading of A8C-specific patterns in WPCOM #62745

Merged
merged 10 commits into from
Apr 15, 2022

Conversation

fullofcaffeine
Copy link
Contributor

@fullofcaffeine fullofcaffeine commented Apr 13, 2022

Changes proposed in this Pull Request

For full context, see: p1649463981925889-slack-C7YPUHBB2.

GB 13.0.0 loads block patterns asynchronously through a new endpoint introduced in #. This is not compatible with the current_screen hook for two reasons: execution order (which means we can't use that hook anymore) and the fact that even if we use another hook/filter, the data about the current screen is not available (though we are discussing ways to provide that data, here). The workaround for now (for shipping GB 13.0.0 to WPCOM) is to just load all patterns regardless of the screen (site editor or regular editor).

Testing instructions

  • Activate Gutenberg 13.0.0-rc.3 (or stable if available) in your WPCOM simple site by applying the gutenberg-edge sticker to it
  • Sandbox public-api.wordpress.com
  • Build ETK in this branch and sync to your sandbox using yarn dev --sync
  • Now load the editor, bring up the block inspector and wait for the "Patterns" tab to render. Click it and you should see a relatively big list of categories. It may vary per theme, but it should be much more than 3, for example. See the video below for the ones that should load for TT2.
  • Repeat the same for the Site Editor (make sure to use a theme that supports it, like TT2), You should see the same block pattern categories.
  • cd to the ETK directory (apps/editing-toolkit) in Calypso and run tests: yarn run test:php. All tests should pass.
Peek.2022-04-13.21-48.mp4

TODO

  • Test that the fix works in AT, make the necessary changes if needed
  • Ensure back compatibility with at least one gutenberg release

@github-actions
Copy link

github-actions bot commented Apr 13, 2022

@matticbot
Copy link
Contributor

This PR does not affect the size of JS and CSS bundles shipped to the user's browser.

Generated by performance advisor bot at iscalypsofastyet.com.

@fullofcaffeine fullofcaffeine force-pushed the fix/load-a8c-patterns-from-api-gb-13 branch 2 times, most recently from 736786e to ba2c624 Compare April 14, 2022 02:19
@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 fix/load-a8c-patterns-from-api-gb-13 on your sandbox.

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

@fullofcaffeine fullofcaffeine force-pushed the fix/load-a8c-patterns-from-api-gb-13 branch from ba2c624 to 493e692 Compare April 14, 2022 02:39
@fullofcaffeine fullofcaffeine marked this pull request as ready for review April 14, 2022 02:44
@fullofcaffeine fullofcaffeine requested a review from a team as a code owner April 14, 2022 02:44
@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 Apr 14, 2022
@fullofcaffeine fullofcaffeine requested review from a team and jsnajdr April 14, 2022 02:44
@fullofcaffeine fullofcaffeine changed the title [ETK][GB 13.x] Fix loading of A8C-specific patterns [ETK][GB 13.x] Fix loading of A8C-specific patterns in WPCOM simple Apr 14, 2022
@fullofcaffeine fullofcaffeine added the caused-by-gutenberg-upgrade Labels an issue (or PR) as caused by or related to a Gutenberg upgrade on WPCOM. label Apr 14, 2022
@fullofcaffeine fullofcaffeine changed the title [ETK][GB 13.x] Fix loading of A8C-specific patterns in WPCOM simple [ETK][GB 13.x] Fix loading of A8C-specific patterns in WPCOM Apr 14, 2022
@noahtallen noahtallen force-pushed the fix/load-a8c-patterns-from-api-gb-13 branch from 3f16eb2 to 06f8501 Compare April 14, 2022 22:41
@noahtallen
Copy link
Contributor

noahtallen commented Apr 14, 2022

I moved the unit tests to the existing class-block-patterns-from-api-test.php file, since it is testing similar functionality :)

@noahtallen noahtallen force-pushed the fix/load-a8c-patterns-from-api-gb-13 branch from ab1e4cc to 835aa48 Compare April 15, 2022 21:40
@noahtallen
Copy link
Contributor

noahtallen commented Apr 15, 2022

I did an extensive amount of smoke testing on the following types of sites:

  • Simple Gutenberg v12.9 post editor
  • Simple Gutenberg v12.9 site editor
  • Simple Gutenberg v13.0 post editor
  • Simple Gutenberg v13.0 site editor
  • Atomic WP 5.9 (no gutenberg) post editor
  • Atomic Gutenberg v12.9 post editor
  • Atomic Gutenberg v13.0 post editor

And I think this is good to go!

The main thing I added today was backwards compatibility with older Gutenberg versions. This is important because Atomic users are able to disable the Gutenberg plugin, so we cannot rely on the new approach being available until it's in core WordPress. (This is not really a concern for simple sites, but the same code runs on both Atomic and Simple, so we have to add it anyways.)

I did that by checking class_exists( 'WP_REST_Block_Pattern_Categories_Controller' ), in which case the back-compat code does not run. Another approach could be to check the Gutenberg plugin version, but that may not always be defined if the user deactivates the plugin. Unless the name of the class changes, this approach should be safe.

@noahtallen noahtallen merged commit 9b70cf3 into trunk Apr 15, 2022
@noahtallen noahtallen deleted the fix/load-a8c-patterns-from-api-gb-13 branch April 15, 2022 22:51
@github-actions github-actions bot removed the [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. label Apr 15, 2022
'rest_dispatch_request',
register_patterns_on_api_request(
function () {
require_once __DIR__ . '/block-patterns/class-block-patterns-from-api.php';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍🏻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
caused-by-gutenberg-upgrade Labels an issue (or PR) as caused by or related to a Gutenberg upgrade on WPCOM.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants