Fix crash when registering non-core blocks #5982
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Issue
With WordPress/gutenberg#52417, now blocks are memoized in
useEntityBlockEditorhook. This hook is used in theEditorProvidercomponent, 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
componentDidMounthandler, which is executed after theuseEntityBlockEditorhook 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
Missingblocks 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 theoriginalBlockTypevariable. However, those don't have thesettingsattribute 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: