From df71e18b99ac1abf9a9ea32646620830a13fa701 Mon Sep 17 00:00:00 2001 From: Jeremy Herve Date: Tue, 1 Dec 2020 18:31:50 +0100 Subject: [PATCH 1/4] Calypso editor: do not set Calypsoify on Jetpack 9.2 Calypsoify is currently broken in Jetpack 9.2: https://github.com/Automattic/jetpack/pull/17939 Until a point release is available, this may avoid creating Fatal errors on sites that do not have Calypsoify enabled yet. --- .../selectors/get-gutenberg-editor-url.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/client/state/selectors/get-gutenberg-editor-url.js b/client/state/selectors/get-gutenberg-editor-url.js index fe7aa9828c000..1f8abdf80221e 100644 --- a/client/state/selectors/get-gutenberg-editor-url.js +++ b/client/state/selectors/get-gutenberg-editor-url.js @@ -2,10 +2,13 @@ * Internal dependencies */ import { isEligibleForGutenframe } from 'calypso/state/gutenberg-iframe-eligible/is-eligible-for-gutenframe'; +import isAtomicSite from 'calypso/state/selectors/is-site-automated-transfer'; import { getSelectedEditor } from 'calypso/state/selectors/get-selected-editor'; import { getSiteAdminUrl, getSiteSlug } from 'calypso/state/sites/selectors'; +import getSiteOption from 'calypso/state/sites/selectors/get-site-option'; import { getEditorPath } from 'calypso/state/editor/selectors'; import { addQueryArgs } from 'calypso/lib/route'; +import versionCompare from 'calypso/lib/version-compare'; export const getGutenbergEditorUrl = ( state, siteId, postId = null, postType = 'post' ) => { if ( ! isEligibleForGutenframe( state, siteId ) ) { @@ -16,8 +19,22 @@ export const getGutenbergEditorUrl = ( state, siteId, postId = null, postType = url = `${ siteAdminUrl }post.php?post=${ postId }&action=edit`; } - if ( 'gutenberg-redirect-and-style' === getSelectedEditor( state, siteId ) ) { + // On some Jetpack sites (9.2+, not Atomic), + // Calypsoify is currently broken. + // Let's not enable it for them. + // Reference: https://github.com/Automattic/jetpack/pull/17939 + const jetpackVersion = getSiteOption( state, siteId, 'jetpack_version' ); + const isBrokenJetpack = + jetpackVersion && + versionCompare( jetpackVersion, '9.2-alpha', '>=' ) && + ! isAtomicSite( state, siteId ); + if ( + 'gutenberg-redirect-and-style' === getSelectedEditor( state, siteId ) && + ! isBrokenJetpack + ) { url = addQueryArgs( { calypsoify: '1' }, url ); + } else { + url = addQueryArgs( { calypsoify: '0' }, url ); } return url; From a39c6cf9ea3f16ce3ac8819881b453e5691debac Mon Sep 17 00:00:00 2001 From: Jeremy Herve Date: Tue, 1 Dec 2020 18:57:37 +0100 Subject: [PATCH 2/4] Check against broken Jetpack version earlier --- .../selectors/get-gutenberg-editor-url.js | 28 ++++++++----------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/client/state/selectors/get-gutenberg-editor-url.js b/client/state/selectors/get-gutenberg-editor-url.js index 1f8abdf80221e..1a639b7b58eb2 100644 --- a/client/state/selectors/get-gutenberg-editor-url.js +++ b/client/state/selectors/get-gutenberg-editor-url.js @@ -11,7 +11,17 @@ import { addQueryArgs } from 'calypso/lib/route'; import versionCompare from 'calypso/lib/version-compare'; export const getGutenbergEditorUrl = ( state, siteId, postId = null, postType = 'post' ) => { - if ( ! isEligibleForGutenframe( state, siteId ) ) { + // On some Jetpack sites (9.2+, not Atomic), + // Calypsoify is currently broken. + // Let's not enable it for them. + // Reference: https://github.com/Automattic/jetpack/pull/17939 + const jetpackVersion = getSiteOption( state, siteId, 'jetpack_version' ); + const isBrokenJetpack = + jetpackVersion && + versionCompare( jetpackVersion, '9.2-alpha', '>=' ) && + ! isAtomicSite( state, siteId ); + + if ( ! isEligibleForGutenframe( state, siteId ) && ! isBrokenJetpack ) { const siteAdminUrl = getSiteAdminUrl( state, siteId ); let url = `${ siteAdminUrl }post-new.php?post_type=${ postType }`; @@ -19,22 +29,8 @@ export const getGutenbergEditorUrl = ( state, siteId, postId = null, postType = url = `${ siteAdminUrl }post.php?post=${ postId }&action=edit`; } - // On some Jetpack sites (9.2+, not Atomic), - // Calypsoify is currently broken. - // Let's not enable it for them. - // Reference: https://github.com/Automattic/jetpack/pull/17939 - const jetpackVersion = getSiteOption( state, siteId, 'jetpack_version' ); - const isBrokenJetpack = - jetpackVersion && - versionCompare( jetpackVersion, '9.2-alpha', '>=' ) && - ! isAtomicSite( state, siteId ); - if ( - 'gutenberg-redirect-and-style' === getSelectedEditor( state, siteId ) && - ! isBrokenJetpack - ) { + if ( 'gutenberg-redirect-and-style' === getSelectedEditor( state, siteId ) ) { url = addQueryArgs( { calypsoify: '1' }, url ); - } else { - url = addQueryArgs( { calypsoify: '0' }, url ); } return url; From 4bdd2290cbca29235d044852f0f7ede5b733e17c Mon Sep 17 00:00:00 2001 From: Jeremy Herve Date: Tue, 1 Dec 2020 19:08:30 +0100 Subject: [PATCH 3/4] Try removing the parameter from the iFrame directly --- client/gutenberg/editor/calypsoify-iframe.tsx | 15 +++++++++++++++ .../state/selectors/get-gutenberg-editor-url.js | 15 +-------------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/client/gutenberg/editor/calypsoify-iframe.tsx b/client/gutenberg/editor/calypsoify-iframe.tsx index 0258b795e2c9e..22210f1d6b842 100644 --- a/client/gutenberg/editor/calypsoify-iframe.tsx +++ b/client/gutenberg/editor/calypsoify-iframe.tsx @@ -44,6 +44,7 @@ import WebPreview from 'calypso/components/web-preview'; import { editPost, trashPost } from 'calypso/state/posts/actions'; import { getEditorPostId } from 'calypso/state/editor/selectors'; import { protectForm, ProtectedFormProps } from 'calypso/lib/protect-form'; +import isAtomicSite from 'calypso/state/selectors/is-site-automated-transfer'; import isSiteWPForTeams from 'calypso/state/selectors/is-site-wpforteams'; import getSiteUrl from 'calypso/state/selectors/get-site-url'; import PageViewTracker from 'calypso/lib/analytics/page-view-tracker'; @@ -59,6 +60,7 @@ import { setMediaLibrarySelectedItems } from 'calypso/state/media/actions'; import { fetchMediaItem, getMediaItem } from 'calypso/state/media/thunks'; import Iframe from './iframe'; import type { RequestCart } from '@automattic/shopping-cart'; +import versionCompare from 'calypso/lib/version-compare'; /** * Types @@ -803,6 +805,19 @@ const mapStateToProps = ( ...( !! stripeConnectSuccess && { stripe_connect_success: stripeConnectSuccess } ), } ); + // On some Jetpack sites (9.2+, not Atomic), + // Calypsoify is currently broken. + // Let's not enable it for them. + // Reference: https://github.com/Automattic/jetpack/pull/17939 + const jetpackVersion = getSiteOption( state, siteId, 'jetpack_version' ); + const isBrokenJetpack = + jetpackVersion && + versionCompare( jetpackVersion, '9.2-alpha', '>=' ) && + ! isAtomicSite( state, siteId ); + if ( isBrokenJetpack ) { + queryArgs[ 'calypsoify' ] = 0; + } + // needed for loading the editor in SU sessions if ( wpcom.addSupportParams ) { queryArgs = wpcom.addSupportParams( queryArgs ); diff --git a/client/state/selectors/get-gutenberg-editor-url.js b/client/state/selectors/get-gutenberg-editor-url.js index 1a639b7b58eb2..fe7aa9828c000 100644 --- a/client/state/selectors/get-gutenberg-editor-url.js +++ b/client/state/selectors/get-gutenberg-editor-url.js @@ -2,26 +2,13 @@ * Internal dependencies */ import { isEligibleForGutenframe } from 'calypso/state/gutenberg-iframe-eligible/is-eligible-for-gutenframe'; -import isAtomicSite from 'calypso/state/selectors/is-site-automated-transfer'; import { getSelectedEditor } from 'calypso/state/selectors/get-selected-editor'; import { getSiteAdminUrl, getSiteSlug } from 'calypso/state/sites/selectors'; -import getSiteOption from 'calypso/state/sites/selectors/get-site-option'; import { getEditorPath } from 'calypso/state/editor/selectors'; import { addQueryArgs } from 'calypso/lib/route'; -import versionCompare from 'calypso/lib/version-compare'; export const getGutenbergEditorUrl = ( state, siteId, postId = null, postType = 'post' ) => { - // On some Jetpack sites (9.2+, not Atomic), - // Calypsoify is currently broken. - // Let's not enable it for them. - // Reference: https://github.com/Automattic/jetpack/pull/17939 - const jetpackVersion = getSiteOption( state, siteId, 'jetpack_version' ); - const isBrokenJetpack = - jetpackVersion && - versionCompare( jetpackVersion, '9.2-alpha', '>=' ) && - ! isAtomicSite( state, siteId ); - - if ( ! isEligibleForGutenframe( state, siteId ) && ! isBrokenJetpack ) { + if ( ! isEligibleForGutenframe( state, siteId ) ) { const siteAdminUrl = getSiteAdminUrl( state, siteId ); let url = `${ siteAdminUrl }post-new.php?post_type=${ postType }`; From 03f4e71e8f50f787c6ff1574d5e6bf359aa62426 Mon Sep 17 00:00:00 2001 From: Jeremy Herve Date: Tue, 1 Dec 2020 19:38:07 +0100 Subject: [PATCH 4/4] Move checking for Jetpack version in iFrame legibility check --- client/gutenberg/editor/calypsoify-iframe.tsx | 15 --------------- .../is-eligible-for-gutenframe.js | 17 +++++++++++++++-- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/client/gutenberg/editor/calypsoify-iframe.tsx b/client/gutenberg/editor/calypsoify-iframe.tsx index 22210f1d6b842..0258b795e2c9e 100644 --- a/client/gutenberg/editor/calypsoify-iframe.tsx +++ b/client/gutenberg/editor/calypsoify-iframe.tsx @@ -44,7 +44,6 @@ import WebPreview from 'calypso/components/web-preview'; import { editPost, trashPost } from 'calypso/state/posts/actions'; import { getEditorPostId } from 'calypso/state/editor/selectors'; import { protectForm, ProtectedFormProps } from 'calypso/lib/protect-form'; -import isAtomicSite from 'calypso/state/selectors/is-site-automated-transfer'; import isSiteWPForTeams from 'calypso/state/selectors/is-site-wpforteams'; import getSiteUrl from 'calypso/state/selectors/get-site-url'; import PageViewTracker from 'calypso/lib/analytics/page-view-tracker'; @@ -60,7 +59,6 @@ import { setMediaLibrarySelectedItems } from 'calypso/state/media/actions'; import { fetchMediaItem, getMediaItem } from 'calypso/state/media/thunks'; import Iframe from './iframe'; import type { RequestCart } from '@automattic/shopping-cart'; -import versionCompare from 'calypso/lib/version-compare'; /** * Types @@ -805,19 +803,6 @@ const mapStateToProps = ( ...( !! stripeConnectSuccess && { stripe_connect_success: stripeConnectSuccess } ), } ); - // On some Jetpack sites (9.2+, not Atomic), - // Calypsoify is currently broken. - // Let's not enable it for them. - // Reference: https://github.com/Automattic/jetpack/pull/17939 - const jetpackVersion = getSiteOption( state, siteId, 'jetpack_version' ); - const isBrokenJetpack = - jetpackVersion && - versionCompare( jetpackVersion, '9.2-alpha', '>=' ) && - ! isAtomicSite( state, siteId ); - if ( isBrokenJetpack ) { - queryArgs[ 'calypsoify' ] = 0; - } - // needed for loading the editor in SU sessions if ( wpcom.addSupportParams ) { queryArgs = wpcom.addSupportParams( queryArgs ); diff --git a/client/state/gutenberg-iframe-eligible/is-eligible-for-gutenframe.js b/client/state/gutenberg-iframe-eligible/is-eligible-for-gutenframe.js index e6669054dc913..6b4ea41db084c 100644 --- a/client/state/gutenberg-iframe-eligible/is-eligible-for-gutenframe.js +++ b/client/state/gutenberg-iframe-eligible/is-eligible-for-gutenframe.js @@ -7,8 +7,21 @@ import { get } from 'lodash'; * Internal dependencies */ import 'calypso/state/gutenberg-iframe-eligible/init'; +import isAtomicSite from 'calypso/state/selectors/is-site-automated-transfer'; +import { getSiteOption } from 'calypso/state/sites/selectors'; +import versionCompare from 'calypso/lib/version-compare'; -export const isEligibleForGutenframe = ( state, siteId ) => - get( state, [ 'gutenbergIframeEligible', siteId ], true ); +export const isEligibleForGutenframe = ( state, siteId ) => { + // On some Jetpack sites (9.2+, not Atomic), + // Calypsoify is currently broken. + // Let's not enable it for them. + // Reference: https://github.com/Automattic/jetpack/pull/17939 + const jetpackVersion = getSiteOption( state, siteId, 'jetpack_version' ); + const isBrokenJetpack = + jetpackVersion && + versionCompare( jetpackVersion, '9.2-alpha', '>=' ) && + ! isAtomicSite( state, siteId ); + return ! isBrokenJetpack && get( state, [ 'gutenbergIframeEligible', siteId ], true ); +}; export default isEligibleForGutenframe;