Skip to content

Commit d73f75a

Browse files
committed
Try another waitForEditor approach, with logging.
1 parent 8f72785 commit d73f75a

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

projects/plugins/jetpack/extensions/shared/wait-for-editor.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,26 @@ import { select, subscribe } from '@wordpress/data';
77
*/
88
export const waitForEditor = async () =>
99
new Promise( resolve => {
10-
// If we already have blocks, editor is ready
11-
if ( select( 'core/block-editor' ).getBlocks().length > 0 ) {
10+
// Resolve immediately if it's a clean new post or has blocks
11+
if (
12+
select( 'core/editor' ).isCleanNewPost() ||
13+
select( 'core/block-editor' ).getBlocks().length > 0
14+
) {
15+
console.log( 'Resolved immediately' );
1216
resolve();
1317
return;
1418
}
1519

16-
// Otherwise wait for either condition
20+
// Otherwise wait for blocks to appear
1721
const timeoutId = setTimeout( () => {
1822
unsubscribe();
1923
resolve();
2024
}, 2000 );
2125

2226
const unsubscribe = subscribe( () => {
23-
const isCleanNewPost = select( 'core/editor' ).isCleanNewPost();
27+
console.log( 'Checking blocks' );
2428
const blocks = select( 'core/block-editor' ).getBlocks();
25-
26-
if ( isCleanNewPost || blocks.length > 0 ) {
29+
if ( blocks.length > 0 ) {
2730
clearTimeout( timeoutId );
2831
unsubscribe();
2932
resolve();

0 commit comments

Comments
 (0)