Skip to content

Commit

Permalink
Fix component inspector error in React Native (#32628)
Browse files Browse the repository at this point in the history
An issue cropped up where the inspector (Debug Menu > Show Inspector) showed a red screen when loading. This happens because on loading the inspector, a hook is called which checks the editor capabilities. If the reusable block capability is `false`, the reusable block type is then unregistered.

What seems to happen when opening the inspector is that the editor does not fully reload, so the reusable block is already unregistered and the app tries to unregister it again, causing a red screen.

The fix here is to only unregister the block if it's currently registered. An alternative approach might be to put the code that unregisters the block in a hook that's only called when the editor is first loaded, not when it's only partially reloaded by the inspector.
  • Loading branch information
guarani authored Jun 15, 2021
1 parent 994cdcc commit b33794d
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions packages/react-native-editor/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
validateThemeColors,
validateThemeGradients,
} from '@wordpress/block-editor';
import { unregisterBlockType } from '@wordpress/blocks';
import { unregisterBlockType, getBlockType } from '@wordpress/blocks';

const reactNativeSetup = () => {
// Disable warnings as they disrupt the user experience in dev mode
Expand Down Expand Up @@ -58,7 +58,10 @@ const setupInitHooks = () => {
setupLocale( props.locale, props.translations );

const capabilities = props.capabilities ?? {};
if ( capabilities.reusableBlock !== true ) {
if (
getBlockType( 'core/block' ) !== undefined &&
capabilities.reusableBlock !== true
) {
unregisterBlockType( 'core/block' );
}
}
Expand Down

0 comments on commit b33794d

Please sign in to comment.