Open
Description
Describe the bug
Using wp.data.select('core/editor').getBlocks()
or other methods of core/editor
in the wp.data.subscribe()
ends up in a white screen, when opening the editor. typeof wp.data.select('core/editor')
returns at some point of the startup undefined
.
To Reproduce
Steps to reproduce the behavior:
- Activate the following plugin:
plugin.php:
<?php
/**
* Plugin Name: Test
*/
add_action('enqueue_block_editor_assets', 'test_script');
function test_script() {
wp_enqueue_script(
'script',
plugins_url( '/script.js', __FILE__ ),
array( 'wp-data' )
);
}
script.js:
wp.data.subscribe(
() => {
console.log(wp.data.select('core/editor').getBlocks().length);
}
);
- open editor
- see white screen.
Expected behavior
The editor should show up and the number of blocks should be printed correctly in the console.
Desktop (please complete the following information):
- OS: Ubuntu 14.04
- Browser Chrome / Firefox
Additional context
- WordPress 5.0.3