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

[RNMobile] Fix broken block registration #33890

Merged
merged 20 commits into from
Nov 7, 2023

Conversation

SiobhyB
Copy link

@SiobhyB SiobhyB commented Oct 31, 2023

Fixes a regression in the Jetpack app that followed the changes in #32697. With this fix, it's possible to add Jetpack blocks within the apps again.

Gutenberg Mobile PR: wordpress-mobile/gutenberg-mobile#6342

Proposed changes:

Other information:

  • Have you written new tests for your changes, if applicable?
  • Have you checked the E2E test CI results, and verified that your changes do not break them?
  • Have you tested your changes on WordPress.com, if applicable (if so, you'll see a generated comment below with a script to run)?

Jetpack product discussion

N/A

Does this pull request change what data or activity we track or use?

No, it does not.

Testing instructions:

  • With these changes checked out, navigate to the editor in the iOS or Android app.
  • Select + to insert a new block, verify that the following Jetpack blocks are visible:
    • Contact Info
    • Story
    • Tiled Gallery (dev-environments only)
  • Verify that it's possible to add each block and that any edits are saved as expected.
Before After

Siobhan added 6 commits October 31, 2023 16:36
Following #32697, 'registerJetpackBlockFromMetadata' is now used to register some Jetpack blocks from metadata. As such, we need to support that functionality on native.

With this commit, the function has been copied/pasted to the native file for use registering Jetpack blocks in the app.
@SiobhyB SiobhyB added [Type] Bug When a feature is broken and / or not performing as intended [Pri] High labels Oct 31, 2023
@github-actions github-actions bot added [JS Package] Shared Extension Utils [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Status] In Progress RNA labels Oct 31, 2023
Copy link
Contributor

github-actions bot commented Oct 31, 2023

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • ✅ Add a "[Status]" label (In Progress, Needs Team Review, ...).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖


The e2e test report can be found here. Please note that it can take a few minutes after the e2e tests checks are complete for the report to be available.


Once your PR is ready for review, check one last time that all required checks appearing at the bottom of this PR are passing or skipped.
Then, add the "[Status] Needs Team Review" label and ask someone from your team review the code. Once reviewed, it can then be merged.
If you need an extra review from someone familiar with the codebase, you can update the labels from "[Status] Needs Team Review" to "[Status] Needs Review", and in that case Jetpack Approvers will do a final review of your PR.


Jetpack plugin:

The Jetpack plugin has different release cadences depending on the platform:

  • WordPress.com Simple releases happen daily.
  • WoA releases happen weekly.
  • Releases to self-hosted sites happen monthly. The next release is scheduled for December 5, 2023 (scheduled code freeze on November 28, 2023).

If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack.

Copy link
Contributor

github-actions bot commented Oct 31, 2023

Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.

  • To test on WoA, go to the Plugins menu on a WordPress.com Simple site. Click on the "Upload" button and follow the upgrade flow to be able to upload, install, and activate the Jetpack Beta plugin. Once the plugin is active, go to Jetpack > Jetpack Beta, select your plugin, and enable the rnmobile/fix-broken-block-registration branch.

  • To test on Simple, run the following command on your sandbox:

    bin/jetpack-downloader test jetpack rnmobile/fix-broken-block-registration
    

Interested in more tips and information?

  • In your local development environment, use the jetpack rsync command to sync your changes to a WoA dev blog.
  • Read more about our development workflow here: PCYsg-eg0-p2
  • Figure out when your changes will be shipped to customers here: PCYsg-eg5-p2

@SiobhyB SiobhyB added [Status] Needs Review To request a review from Crew. Label will be renamed soon. and removed [Status] In Progress labels Oct 31, 2023
@SiobhyB SiobhyB marked this pull request as ready for review October 31, 2023 17:31
@SiobhyB SiobhyB requested a review from fluiddot October 31, 2023 18:44
@anomiex anomiex added [Status] Needs Author Reply We would need you to make some changes or provide some more details about your PR. Thank you! and removed [Status] Needs Review To request a review from Crew. Label will be renamed soon. labels Nov 1, 2023
@anomiex
Copy link
Contributor

anomiex commented Nov 1, 2023

Build is failing because react-native-svg does not resolve in the non-native build. You may need to add a .native.js copy of the file or something.

Siobhan added 2 commits November 2, 2023 11:45
With this PR, a version of the get-block-icon-from-metadata.js file has been added. This initial version is simply a copy/paste of the web file but will be iterated on for the native use-case.

A separate native file is needed for a couple of reasons:

1. DOM parsing is unavailable with native, so the default web functionality doesn't work as expected in the app.
2. It's not possible to import React Native libraries to the main web files, as per the following comment: #33890 (comment)
As we don't have access to the DOM in React Native, we need to adjust this function. The `SvgXml` function that comes with `react-native-svg` has been used for this purpose.
* @returns {JSX.Element} Icon component
*/
export function getBlockIconComponent( metadata ) {
return <SvgXml xml={ metadata.icon } />;
Copy link
Contributor

Choose a reason for hiding this comment

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

What happens if the block has no metadata.icon, or has it set to a non-svg like instagram-gallery currently does?

Copy link
Author

Choose a reason for hiding this comment

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

@anomiex, good point! @fluiddot has suggested another approach via Slack that I'm planning to follow instead of this. I'll work on this and set as ready for review again when it's ready. (Just juggling a few tasks today, sorry for not being super responsive!)

Copy link
Author

Choose a reason for hiding this comment

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

Noting that, to address this, in WordPress/gutenberg#55742, a change has been made directly to components/block-icon/index.native.js so that the parsing is handled on the Gutenberg side.

Copy link
Author

Choose a reason for hiding this comment

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

Following the discovery that the icon can be passed to components other than <BlockIcon/>, I reverted the aforementioned change, so we're back to parsing the icon in get-block-icon-from-metadata.native.js.

To account for cases where there may not be a block icon, or it may not be an svg string, I made some changes in 1a12767. I believe these changes bring us in alignment to how the logic works in the web file.

I used the instagram example to test that this works locally:

Screenshot_20231106_172034

@anomiex
Copy link
Contributor

anomiex commented Nov 2, 2023

You'll need to address the failing Linter test (running tools/fixup-project-versions.sh should make the necessary changes). All the E2E test failures look like known issues, you can ignore them.

I don't know enough about the apps to test or review that part of it myself though.

@SiobhyB SiobhyB marked this pull request as draft November 2, 2023 15:57
Siobhan added 3 commits November 3, 2023 08:39
For native, we're updating the logic for parsing a block icon if it's a string. See: WordPress/gutenberg#55742

Given those changes, we can now pass the "metadata.icon" string directly when registering a block on native.
@SiobhyB SiobhyB marked this pull request as ready for review November 3, 2023 10:10
Copy link
Contributor

@fluiddot fluiddot left a comment

Choose a reason for hiding this comment

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

@SiobhyB I encountered an error when adding a Story block:

Screenshot 2023-11-03 at 15 50 41

Seems we'd need to support SVG XML string sources directly in the Icon component, as the block icon might be used in more places apart from the BlockIcon component:

const icon = getBlockIconComponent( metadata );

<MediaPlaceholder
icon={ icon }

Siobhan added 2 commits November 6, 2023 16:12
Following on from these comments, logic has been added to check whether an icon is present or not, and also allow it to not be a string: #33890 (comment)
@SiobhyB
Copy link
Author

SiobhyB commented Nov 6, 2023

@fluiddot, thank you for the thorough review here!

Seems we'd need to support SVG XML string sources directly in the Icon component, as the block icon might be used in more places apart from the BlockIcon component:

I have a sense we should stick to parsing the icon in get-block-icon-from-metadata.native.js in the Jetpack codebase. The reason behind my thinking is that there could be a number of places where the icon could be passed, and the equivalent web components haven't been updated to account for this in Gutenberg. Do you think that seems sound? I've made some changes that appear to work for our use case, and also seem tweaks in 1a12767 to account for other potential issues mentioned in this review. Looking forward to hearing what you think.

Siobhan added 2 commits November 7, 2023 10:12
As per the conversation here, we want to avoid importing SvgXml directly as it's not a dependency in the Jetpack codebase: #33890 (comment)

As discussed, we'll instead import from Gutenberg directly.
fluiddot
fluiddot previously approved these changes Nov 7, 2023
Copy link
Contributor

@fluiddot fluiddot left a comment

Choose a reason for hiding this comment

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

LGTM 🎊 ! Thanks @SiobhyB for addressing this issue 🙇 !

I noticed that one of the E2E tests failed (Jetpack blocks e2e tests), the failure seems unrelated to these changes so I went ahead and restart it.

Co-authored-by: Carlos Garcia <fluiddot@gmail.com>
Copy link
Contributor

@fluiddot fluiddot left a comment

Choose a reason for hiding this comment

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

LGTM 🎊 !

@SiobhyB SiobhyB merged commit 3c38ce3 into trunk Nov 7, 2023
64 of 65 checks passed
@SiobhyB SiobhyB deleted the rnmobile/fix-broken-block-registration branch November 7, 2023 14:51
@github-actions github-actions bot removed [Status] Needs Author Reply We would need you to make some changes or provide some more details about your PR. Thank you! [Status] In Progress labels Nov 7, 2023
@github-actions github-actions bot added this to the jetpack/12.9 milestone Nov 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[JS Package] Shared Extension Utils [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Pri] High RNA [Type] Bug When a feature is broken and / or not performing as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants