Product Editor: Disable description full editor when using an incompatible version of Gutenberg (#45650)
* Check Gutenberg version and prevent full editor use if using a version that causes crash * Changelog
This commit is contained in:
parent
3873bac561
commit
52d300f2a9
|
@ -0,0 +1,4 @@
|
|||
Significance: patch
|
||||
Type: fix
|
||||
|
||||
Product Editor: Prevent description full editor usage if a version of Gutenberg plugin is installed that causes crashes.
|
|
@ -14,6 +14,26 @@ import { parse, rawHandler } from '@wordpress/blocks';
|
|||
*/
|
||||
import { store } from '../../../../store/product-editor-ui';
|
||||
import { getContentFromFreeform } from '../edit';
|
||||
import { getGutenbergVersion } from '../../../../utils/get-gutenberg-version';
|
||||
|
||||
// There is a bug in Gutenberg 17.9 that causes a crash in the full editor.
|
||||
// This should be fixed in Gutenberg 18.0 (see https://github.com/WordPress/gutenberg/pull/59800).
|
||||
// Once we only support Gutenberg 18.0 and above, we can remove this check.
|
||||
function isGutenbergVersionWithCrashInFullEditor() {
|
||||
const gutenbergVersion = getGutenbergVersion();
|
||||
return gutenbergVersion >= 17.9 && gutenbergVersion < 18.0;
|
||||
}
|
||||
|
||||
function shouldForceFullEditor() {
|
||||
return (
|
||||
localStorage
|
||||
.getItem(
|
||||
'__unsupported_force_product_editor_description_full_editor'
|
||||
)
|
||||
?.trim()
|
||||
.toLowerCase() === 'true'
|
||||
);
|
||||
}
|
||||
|
||||
export default function FullEditorToolbarButton( {
|
||||
label = __( 'Edit Product description', 'woocommerce' ),
|
||||
|
@ -30,6 +50,27 @@ export default function FullEditorToolbarButton( {
|
|||
<ToolbarButton
|
||||
label={ label }
|
||||
onClick={ () => {
|
||||
if ( isGutenbergVersionWithCrashInFullEditor() ) {
|
||||
if ( shouldForceFullEditor() ) {
|
||||
// eslint-disable-next-line no-alert
|
||||
alert(
|
||||
__(
|
||||
'The version of the Gutenberg plugin installed causes a crash in the full editor. You are proceeding at your own risk and may experience crashes.',
|
||||
'woocommerce'
|
||||
)
|
||||
);
|
||||
} else {
|
||||
// eslint-disable-next-line no-alert
|
||||
alert(
|
||||
__(
|
||||
'The version of the Gutenberg plugin installed causes a crash in the full editor. To prevent this, the full editor has been disabled.',
|
||||
'woocommerce'
|
||||
)
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
let parsedBlocks = parse( description );
|
||||
const freeformContent = getContentFromFreeform( parsedBlocks );
|
||||
|
||||
|
|
Loading…
Reference in New Issue