File tree Expand file tree Collapse file tree 1 file changed +9
-6
lines changed
projects/plugins/jetpack/extensions/shared Expand file tree Collapse file tree 1 file changed +9
-6
lines changed Original file line number Diff line number Diff line change @@ -7,23 +7,26 @@ import { select, subscribe } from '@wordpress/data';
7
7
*/
8
8
export const waitForEditor = async ( ) =>
9
9
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' ) ;
12
16
resolve ( ) ;
13
17
return ;
14
18
}
15
19
16
- // Otherwise wait for either condition
20
+ // Otherwise wait for blocks to appear
17
21
const timeoutId = setTimeout ( ( ) => {
18
22
unsubscribe ( ) ;
19
23
resolve ( ) ;
20
24
} , 2000 ) ;
21
25
22
26
const unsubscribe = subscribe ( ( ) => {
23
- const isCleanNewPost = select ( 'core/editor' ) . isCleanNewPost ( ) ;
27
+ console . log ( 'Checking blocks' ) ;
24
28
const blocks = select ( 'core/block-editor' ) . getBlocks ( ) ;
25
-
26
- if ( isCleanNewPost || blocks . length > 0 ) {
29
+ if ( blocks . length > 0 ) {
27
30
clearTimeout ( timeoutId ) ;
28
31
unsubscribe ( ) ;
29
32
resolve ( ) ;
You can’t perform that action at this time.
0 commit comments