diff --git a/lib/client-assets.php b/lib/client-assets.php index fa1832d2f23729..4adc79fc689042 100644 --- a/lib/client-assets.php +++ b/lib/client-assets.php @@ -102,6 +102,20 @@ function gutenberg_override_script( $scripts, $handle, $src, $deps = array(), $v $output = sprintf( "wp.i18n.setLocaleData( { 'text direction\u0004ltr': [ '%s' ] }, 'default' );", $ltr ); $scripts->add_inline_script( 'wp-i18n', $output, 'after' ); } + + /* + * Wp-editor module is exposed as window.wp.editor. + * Problem: there is quite some code expecting window.wp.oldEditor object available under window.wp.editor. + * Solution: fuse the two objects together to maintain backward compatibility. + * For more context, see https://github.com/WordPress/gutenberg/issues/33203 + */ + if ( 'wp-editor' === $handle ) { + $scripts->add_inline_script( + 'wp-editor', + 'Object.assign( window.wp.editor, window.wp.oldEditor );', + 'after' + ); + } } /** diff --git a/packages/e2e-tests/specs/editor/plugins/wp-editor-meta-box.test.js b/packages/e2e-tests/specs/editor/plugins/wp-editor-meta-box.test.js index 3045575ff15f5d..867c3cf7b40138 100644 --- a/packages/e2e-tests/specs/editor/plugins/wp-editor-meta-box.test.js +++ b/packages/e2e-tests/specs/editor/plugins/wp-editor-meta-box.test.js @@ -39,8 +39,20 @@ describe( 'WP Editor Meta Boxes', () => { ( textarea ) => textarea.value ); - expect( content ).toMatchInlineSnapshot( - `"

Typing in a metabox

"` - ); + /* + * `content` may or may not contain the

tags depending on hasWpautop value in this line: + * https://github.com/WordPress/wordpress-develop/blob/2382765afa36e10bf3c74420024ad4e85763a47c/src/js/_enqueues/vendor/tinymce/plugins/wordpress/plugin.js#L15 + * + * Now, for the purposes of this e2e test we explicitly set wpautop to true in the test plugin: + * https://github.com/WordPress/gutenberg/blob/3da717b8d0ac7d7821fc6d0475695ccf3ae2829f/packages/e2e-tests/plugins/wp-editor-metabox.php#L36 + * + * If this test randomly fails because of the actual value being wrapped in

like

Typing in a metabox

, it means that + * hasWpautop has been errorneously set to false in the line above. You may want to check: + * * Is window.wp.editor.autop a function? It should be one since https://github.com/WordPress/gutenberg/pull/33228 + * * Is wpautop still true in the second link mentioned in this comment? + * + * For more context, see https://github.com/WordPress/gutenberg/pull/33228/files#r666897885 + */ + expect( content ).toBe( 'Typing in a metabox' ); } ); } );