Skip to content

Commit

Permalink
Only load Gutenberg Polyfill in Gutenberg pages (#6849)
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad committed May 21, 2018
1 parent 3122002 commit 6453eb5
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
20 changes: 18 additions & 2 deletions lib/client-assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -1093,9 +1093,25 @@ function gutenberg_editor_scripts_and_styles( $hook ) {
* Remove this in Gutenberg 3.1
*/
function polyfill_blocks_module_in_scripts() {
if ( is_admin() ) {
wp_enqueue_script( 'wp-editor' );
global $post;

if ( ! is_admin() ) {
return;
}

if ( get_current_screen()->base !== 'post' ) {
return;
}

if ( isset( $_GET['classic-editor'] ) ) {
return;
}

if ( ! gutenberg_can_edit_post( $post ) ) {
return;
}

wp_enqueue_script( 'wp-editor' );
}

add_action( 'enqueue_block_editor_assets', 'polyfill_blocks_module_in_scripts', 9 );
Expand Down
27 changes: 27 additions & 0 deletions test/e2e/specs/classic-editor.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* Internal dependencies
*/
import '../support/bootstrap';
import { visitAdmin, newDesktopBrowserPage } from '../support/utils';

describe( 'classic editor', () => {
beforeAll( async () => {
await newDesktopBrowserPage();
await visitAdmin( 'post-new.php', 'classic-editor' );
} );

it( 'Should work properly', async () => {
// Click visual editor
await page.click( '#content-tmce' );
await page.click( '#content_ifr' );

// type some random text
await page.keyboard.type( 'Typing in classic editor' );

// Swtich to HTML mode
await page.click( '#content-html' );

const textEditorContent = await page.$eval( '.wp-editor-area', ( element ) => element.value );
expect( textEditorContent ).toEqual( 'Typing in classic editor' );
} );
} );

0 comments on commit 6453eb5

Please sign in to comment.