From ddc5d1e1b83ad6c36aa2be7487d1abbace41eda9 Mon Sep 17 00:00:00 2001 From: Glen Davies Date: Mon, 6 Dec 2021 15:36:08 +1300 Subject: [PATCH] Gallery block: enable the new gallery block by default if running in core (#37134) * Enable the new gallery block by default if running in core and not plugin * Add explanatory comment Co-authored-by: Glen Davies --- packages/block-library/src/gallery/shared.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/packages/block-library/src/gallery/shared.js b/packages/block-library/src/gallery/shared.js index e2c2e717d0f707..6dbbcc40222fab 100644 --- a/packages/block-library/src/gallery/shared.js +++ b/packages/block-library/src/gallery/shared.js @@ -29,11 +29,19 @@ export const pickRelevantMediaFiles = ( image, sizeSlug = 'large' ) => { * can be removed when minimum supported WP version >=5.9. */ export function isGalleryV2Enabled() { - // We want to fail early here, at least during beta testing phase, to ensure - // there aren't instances where undefined values cause false negatives. - if ( ! window.wp || typeof window.wp.galleryBlockV2Enabled !== 'boolean' ) { - throw 'window.wp.galleryBlockV2Enabled is not defined'; + // Only run the Gallery version compat check if the plugin is running, otherwise + // assume we are in 5.9 core and enable by default. + if ( process.env.GUTENBERG_PHASE === 2 ) { + // We want to fail early here, at least during beta testing phase, to ensure + // there aren't instances where undefined values cause false negatives. + if ( + ! window.wp || + typeof window.wp.galleryBlockV2Enabled !== 'boolean' + ) { + throw 'window.wp.galleryBlockV2Enabled is not defined'; + } + return window.wp.galleryBlockV2Enabled; } - return window.wp.galleryBlockV2Enabled; + return true; }