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:
Matt Sherman 2024-03-18 02:23:08 -04:00 committed by GitHub
parent 3873bac561
commit 52d300f2a9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 45 additions and 0 deletions

View File

@ -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.

View File

@ -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 );