From 896f8cf5a8b993dd409469af249a70fdc97c0467 Mon Sep 17 00:00:00 2001 From: Marin Atanasov Date: Tue, 13 Jun 2023 14:12:06 +0300 Subject: [PATCH] Use a query argument instead of a cookie --- lib/client-assets.php | 2 +- lib/experimental/assets/tinymce-proxy.js | 6 +++--- lib/experimental/disable-tinymce.php | 4 ++-- packages/block-library/src/index.js | 9 ++++----- 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/lib/client-assets.php b/lib/client-assets.php index 380d116f64805c..b9e385be5eb876 100644 --- a/lib/client-assets.php +++ b/lib/client-assets.php @@ -205,7 +205,7 @@ function gutenberg_register_packages_scripts( $scripts ) { case 'wp-block-library': if ( ! gutenberg_is_experiment_enabled( 'gutenberg-no-tinymce' ) || - isset( $_COOKIE['requiresTinymce'] ) || + ! empty( $_GET['requiresTinymce'] ) || gutenberg_current_content_contains_classic_block() ) { array_push( $dependencies, 'editor' ); diff --git a/lib/experimental/assets/tinymce-proxy.js b/lib/experimental/assets/tinymce-proxy.js index e8044b8abafd6c..f66ab6b435c931 100644 --- a/lib/experimental/assets/tinymce-proxy.js +++ b/lib/experimental/assets/tinymce-proxy.js @@ -1,7 +1,7 @@ async function markAsRequiringTinymce() { - const expiration = new Date( 'Dec 31, 2099 23:59:59' ); - document.cookie = `requiresTinymce=1; expires=${ expiration }; path=/`; - window.location.reload(); + const currentUrl = new URL( window.location.href ); + currentUrl.searchParams.set( 'requiresTinymce', '1' ); + window.location.href = currentUrl; } window.tinymce = new Proxy( diff --git a/lib/experimental/disable-tinymce.php b/lib/experimental/disable-tinymce.php index 45f684fdca71d7..428d97371e505f 100644 --- a/lib/experimental/disable-tinymce.php +++ b/lib/experimental/disable-tinymce.php @@ -19,7 +19,7 @@ function gutenberg_declare_classic_block_necessary() { add_action( 'admin_footer', 'gutenberg_declare_classic_block_necessary' ); // If user has already requested TinyMCE, we're ending the experiment. -if ( isset( $_COOKIE['requiresTinymce'] ) || gutenberg_current_content_contains_classic_block() ) { +if ( ! empty( $_GET['requiresTinymce'] ) || gutenberg_current_content_contains_classic_block() ) { return; } @@ -35,7 +35,7 @@ function gutenberg_disable_tinymce() { /** * Enqueue TinyMCE proxy script. - * Detects TinyMCE usage and sets the `requiresTinymce` cookie to stop disabling TinyMCE loading. + * Detects TinyMCE usage and sets the `requiresTinymce` query argument to stop disabling TinyMCE loading. */ function gutenberg_enqueue_tinymce_proxy() { wp_enqueue_script( 'gutenberg-tinymce-proxy', plugins_url( 'assets/tinymce-proxy.js', __FILE__ ) ); diff --git a/packages/block-library/src/index.js b/packages/block-library/src/index.js index b16071a549560c..6361ed020566b1 100644 --- a/packages/block-library/src/index.js +++ b/packages/block-library/src/index.js @@ -231,15 +231,14 @@ const getAllBlocks = () => { // and when either of the following is true: // - TinyMCE experiment is disabled; // - there is a classic block in the current post's content; - // - the cookie to require TinyMCE is set. + // - the query argument to require TinyMCE is set. if ( window?.wp?.oldEditor && ( window?.wp?.needsClassicBlock || ! window?.__experimentalDisableTinymce || - ( '; ' + document.cookie ) - .split( '; requiresTinymce=' ) - .pop() - .split( ';' )[ 0 ] ) + !! new URLSearchParams( window?.location?.search ).get( + 'requiresTinymce' + ) ) ) { blocks.push( classic ); }