Skip to content

Instantly share code, notes, and snippets.

@renatonascalves
Forked from KevinBatdorf/gutenberg-helpers.js
Created December 19, 2023 17:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save renatonascalves/96be4548ad07edd5a914cadc5c572c64 to your computer and use it in GitHub Desktop.
Save renatonascalves/96be4548ad07edd5a914cadc5c572c64 to your computer and use it in GitHub Desktop.
WordPress check Gutenberg editor is ready
import { select, subscribe } from '@wordpress/data'
export function whenEditorIsReady() {
return new Promise((resolve) => {
const unsubscribe = subscribe(() => {
// This will trigger after the initial render blocking, before the window load event
// This seems currently more reliable than using __unstableIsEditorReady
if (select('core/editor').isCleanNewPost() || select('core/block-editor').getBlockCount() > 0) {
unsubscribe()
resolve()
}
})
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment