Skip to content

Commit

Permalink
Merge conflicting wp.editor objects into a single, non-conflicting …
Browse files Browse the repository at this point in the history
…module (#33228)
  • Loading branch information
adamziel authored Jul 9, 2021
1 parent d0a25e8 commit b403b97
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
14 changes: 14 additions & 0 deletions lib/client-assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'
);
}
}

/**
Expand Down
18 changes: 15 additions & 3 deletions packages/e2e-tests/specs/editor/plugins/wp-editor-meta-box.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,20 @@ describe( 'WP Editor Meta Boxes', () => {
( textarea ) => textarea.value
);

expect( content ).toMatchInlineSnapshot(
`"<p>Typing in a metabox</p>"`
);
/*
* `content` may or may not contain the <p> 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 <p> like <p>Typing in a metabox</p>, 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' );
} );
} );

0 comments on commit b403b97

Please sign in to comment.