Skip to content

Commit

Permalink
Iframe: skip scoping styles
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed Dec 22, 2022
1 parent beb80db commit 870ec59
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
13 changes: 5 additions & 8 deletions packages/block-editor/src/components/editor-styles/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@ import { useCallback, useMemo } from '@wordpress/element';
*/
import transformStyles from '../../utils/transform-styles';

const EDITOR_STYLES_SELECTOR = '.editor-styles-wrapper';
extend( [ namesPlugin, a11yPlugin ] );

function useDarkThemeBodyClassName( styles ) {
function useDarkThemeBodyClassName( styles, scope ) {
return useCallback(
( node ) => {
if ( ! node ) {
Expand All @@ -27,9 +26,7 @@ function useDarkThemeBodyClassName( styles ) {

const { ownerDocument } = node;
const { defaultView, body } = ownerDocument;
const canvas = ownerDocument.querySelector(
EDITOR_STYLES_SELECTOR
);
const canvas = scope ? ownerDocument.querySelector( scope ) : body;

let backgroundColor;

Expand Down Expand Up @@ -66,17 +63,17 @@ function useDarkThemeBodyClassName( styles ) {
);
}

export default function EditorStyles( { styles } ) {
export default function EditorStyles( { styles, scope } ) {
const transformedStyles = useMemo(
() => transformStyles( styles, EDITOR_STYLES_SELECTOR ),
() => transformStyles( styles, scope ),
[ styles ]
);

return (
<>
{ /* Use an empty style element to have a document reference,
but this could be any element. */ }
<style ref={ useDarkThemeBodyClassName( styles ) } />
<style ref={ useDarkThemeBodyClassName( styles, scope ) } />
{ transformedStyles.map( ( css, index ) => (
<style key={ index }>{ css }</style>
) ) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,10 @@ export default function SidebarBlockEditor( {

<CopyHandler>
<BlockTools>
<EditorStyles styles={ settings.defaultEditorStyles } />
<EditorStyles
styles={ settings.defaultEditorStyles }
scope=".editor-styles-wrapper"
/>
<BlockSelectionClearer>
<WritingFlow className="editor-styles-wrapper">
<ObserveTyping>
Expand Down
5 changes: 4 additions & 1 deletion packages/edit-post/src/components/visual-editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ function MaybeIframe( {
if ( ! shouldIframe ) {
return (
<>
<EditorStyles styles={ styles } />
<EditorStyles
styles={ styles }
scope=".editor-styles-wrapper"
/>
<WritingFlow
ref={ contentRef }
className="editor-styles-wrapper"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ export default function WidgetAreasBlockEditorContent( {
<Notices />
<BlockTools>
<KeyboardShortcuts />
<EditorStyles styles={ styles } />
<EditorStyles
styles={ styles }
scope=".editor-styles-wrapper"
/>
<BlockSelectionClearer>
<WritingFlow>
<ObserveTyping>
Expand Down

1 comment on commit 870ec59

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/3760409506
📝 Reported issues:

Please sign in to comment.