-
Notifications
You must be signed in to change notification settings - Fork 57
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
Fix crash when registering non-core blocks #5982
Conversation
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! Nice approach to fix this regression 🚀 The Gutenberg side of changes were approved in WordPress/gutenberg#52791 (review)
I tested different blocks and it's working as expected on both iOS and Android using the host apps.
Wanna run full suite of Android and iOS UI tests? Click here and 'Approve' CI job! |
# Conflicts: # gutenberg
For some reason, all jobs are shown here as "waiting", however, they are running in CircleCI and Buildkite 🤔. UPDATE: I ended up pushing an empty commit just to trigger CI jobs. |
Issue
With WordPress/gutenberg#52417, now blocks are memoized in
useEntityBlockEditor
hook. This hook is used in theEditorProvider
component, so the first call is made right after the editor is initialized. When the initial content is parsed here, it processes the blocks based on the block types registered at that time.The Jetpack blocks are registered on the root component's
componentDidMount
handler, which is executed after theuseEntityBlockEditor
hook is invoked the first time. Therefore, when parsing the initial content Jetpack blocks are marked as missing blocks, as they haven't been registered yet by that time.gutenberg-mobile/src/jetpack-editor-setup.js
Lines 149 to 152 in 25c8620
Example content parsed:
When the
Missing
blocks are rendered, this line, which calculates the label for the block, produces the crash. Seems that by that time, the proper Jetpack block is fetched for theoriginalBlockType
variable. However, those don't have thesettings
attribute defined.WordPress/gutenberg#52417 actually uncovered an issue regarding how we register Jetpack blocks, as we were registering them probably too late in the initialization cycle.
Solution
The workaround for this is to add a new WP hook that allows Gutenberg Mobile to register non-core blocks, like Jetpack blocks, right after the core blocks are registered. This way we ensure that all blocks are registered sequentially (first core blocks, then non-core blocks) before any other calculations are made within the editor.
To test
PR submission checklist: