-
Notifications
You must be signed in to change notification settings - Fork 798
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
Conversation
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.
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
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. Jetpack plugin: The Jetpack plugin has different release cadences depending on the platform:
If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack. |
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.
Interested in more tips and information?
|
Build is failing because |
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 } />; |
There was a problem hiding this comment.
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?
"icon": "instagram", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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:
You'll need to address the failing Linter test (running I don't know enough about the apps to test or review that part of it myself though. |
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.
There was a problem hiding this 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:
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 ); |
jetpack/projects/plugins/jetpack/extensions/blocks/story/edit.native.js
Lines 175 to 176 in eebad7d
<MediaPlaceholder | |
icon={ icon } |
projects/js-packages/shared-extension-utils/src/get-block-icon-from-metadata.js
Outdated
Show resolved
Hide resolved
projects/plugins/jetpack/extensions/shared/register-jetpack-block.native.js
Show resolved
Hide resolved
projects/plugins/jetpack/extensions/shared/register-jetpack-block.native.js
Show resolved
Hide resolved
projects/plugins/jetpack/extensions/shared/register-jetpack-block.native.js
Show resolved
Hide resolved
This reverts commit 1fdc69a.
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)
@fluiddot, thank you for the thorough review here!
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. |
projects/js-packages/shared-extension-utils/src/get-block-icon-from-metadata.native.js
Outdated
Show resolved
Hide resolved
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.
There was a problem hiding this 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.
projects/js-packages/shared-extension-utils/src/get-block-icon-from-metadata.native.js
Outdated
Show resolved
Hide resolved
Co-authored-by: Carlos Garcia <fluiddot@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 🎊 !
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:
registerJetpackBlockFromMetadata
function has been taken from the web's register-jetpack-block.js file add added to register-jetpack-block.native.js for use in the apps.SvgXml
from the react-native-svg library) for compatibility with React Native.Other information:
Jetpack product discussion
N/A
Does this pull request change what data or activity we track or use?
No, it does not.
Testing instructions: