diff --git a/packages/block-editor/src/components/iframe/index.js b/packages/block-editor/src/components/iframe/index.js index 8ec4b24106ebf3..cc99464f9bb1a8 100644 --- a/packages/block-editor/src/components/iframe/index.js +++ b/packages/block-editor/src/components/iframe/index.js @@ -131,8 +131,23 @@ function Iframe( { function preventFileDropDefault( event ) { event.preventDefault(); } + + const { ownerDocument } = node; + + // Ideally ALL classes that are added through get_body_class should + // be added in the editor too, which we'll somehow have to get from + // the server in the future (which will run the PHP filters). + setBodyClasses( + Array.from( ownerDocument.body.classList ).filter( + ( name ) => + name.startsWith( 'admin-color-' ) || + name.startsWith( 'post-type-' ) || + name === 'wp-embed-responsive' + ) + ); + function onLoad() { - const { contentDocument, ownerDocument } = node; + const { contentDocument } = node; const { documentElement } = contentDocument; iFrameDocument = contentDocument; @@ -140,18 +155,6 @@ function Iframe( { clearerRef( documentElement ); - // Ideally ALL classes that are added through get_body_class should - // be added in the editor too, which we'll somehow have to get from - // the server in the future (which will run the PHP filters). - setBodyClasses( - Array.from( ownerDocument.body.classList ).filter( - ( name ) => - name.startsWith( 'admin-color-' ) || - name.startsWith( 'post-type-' ) || - name === 'wp-embed-responsive' - ) - ); - contentDocument.dir = ownerDocument.dir; for ( const compatStyle of getCompatibilityStyles() ) {