Skip to content

Commit

Permalink
Iframe: Silence style compat warnings when in a BlockPreview (#52627)
Browse files Browse the repository at this point in the history
  • Loading branch information
noisysocks committed Jul 14, 2023
1 parent f143f3f commit f91b4fb
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions packages/block-editor/src/components/iframe/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,14 @@ function Iframe( {
forwardedRef: ref,
...props
} ) {
const { styles = '', scripts = '' } = useSelect(
( select ) =>
select( blockEditorStore ).getSettings().__unstableResolvedAssets,
[]
);
const { resolvedAssets, isPreviewMode } = useSelect( ( select ) => {
const settings = select( blockEditorStore ).getSettings();
return {
resolvedAssets: settings.__unstableResolvedAssets,
isPreviewMode: settings.__unstableIsPreviewMode,
};
}, [] );
const { styles = '', scripts = '' } = resolvedAssets;
const [ iframeDocument, setIframeDocument ] = useState();
const [ bodyClasses, setBodyClasses ] = useState( [] );
const compatStyles = useCompatibilityStyles();
Expand Down Expand Up @@ -140,11 +143,13 @@ function Iframe( {
compatStyle.cloneNode( true )
);

// eslint-disable-next-line no-console
console.warn(
`${ compatStyle.id } was added to the iframe incorrectly. Please use block.json or enqueue_block_assets to add styles to the iframe.`,
compatStyle
);
if ( ! isPreviewMode ) {
// eslint-disable-next-line no-console
console.warn(
`${ compatStyle.id } was added to the iframe incorrectly. Please use block.json or enqueue_block_assets to add styles to the iframe.`,
compatStyle
);
}
}

iFrameDocument.addEventListener(
Expand Down

0 comments on commit f91b4fb

Please sign in to comment.