Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Iframe: use src instead of srcDoc #50875

Merged
merged 1 commit into from
May 24, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions packages/block-editor/src/components/iframe/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
useMemo,
useReducer,
renderToString,
useEffect,
} from '@wordpress/element';
import { __ } from '@wordpress/i18n';
import {
Expand Down Expand Up @@ -243,10 +244,16 @@ function Iframe( {
// Correct doctype is required to enable rendering in standards
// mode. Also preload the styles to avoid a flash of unstyled
// content.
const srcDoc = useMemo( () => {
return '<!doctype html>' + renderToString( styleAssets );
const src = useMemo( () => {
const html = '<!doctype html>' + renderToString( styleAssets );
const blob = new window.Blob( [ html ], { type: 'text/html' } );
return URL.createObjectURL( blob );
}, [] );

useEffect( () => () => {
URL.revokeObjectURL( src );
} );

// We need to counter the margin created by scaling the iframe. If the scale
// is e.g. 0.45, then the top + bottom margin is 0.55 (1 - scale). Just the
// top or bottom margin is 0.55 / 2 ((1 - scale) / 2).
Expand Down Expand Up @@ -279,7 +286,7 @@ function Iframe( {
// Correct doctype is required to enable rendering in standards
// mode. Also preload the styles to avoid a flash of unstyled
// content.
srcDoc={ srcDoc }
src={ src }
title={ __( 'Editor canvas' ) }
>
{ iframeDocument &&
Expand Down