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

Fix: Editor width when using an iframe #645

Closed
wants to merge 2 commits into from

Conversation

tomusborne
Copy link
Owner

This fixes a bug where our editor width value doesn't apply to the editor when it's using an iframe.

@tomusborne tomusborne added the bug Bugs, unexpected and weird behaviors label Oct 23, 2024
@tomusborne tomusborne added this to the 3.5.2 milestone Oct 23, 2024
@tomusborne tomusborne requested a review from iansvo October 23, 2024 17:52
@@ -40,12 +40,13 @@ function getContentWidth( layout, contentContainer = '' ) {
const ContentWidth = () => {
const [ sidebarLayout, setSidebarLayout ] = useState( generatepressBlockEditor.sidebarLayout );
const [ fullWidth, setFullWidth ] = useState( generatepressBlockEditor.contentAreaType );
const editorWrapperStyles = document.querySelector( '.editor-styles-wrapper' )?.style;
const queryDocument = document.querySelector( 'iframe[name="editor-canvas"]' )?.contentDocument || document;
const editorWrapperStyles = queryDocument.querySelector( '.editor-styles-wrapper' )?.style;

// We use editorWrapperStyles to update the content width when changing devices or code editor to visual editor.
// See https://github.com/tomusborne/generatepress/issues/493.
useEffect( () => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

We'll want to test this, but we may end up wanting to go with useLayoutEffect in case that query fails because the DOM is being updated.

Copy link
Owner Author

Choose a reason for hiding this comment

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

@iansvo Just updated this. It now checks whether we're dealing with the iframe or code editor. This makes sure the content width stays applied even when these events happen and the editor changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bugs, unexpected and weird behaviors
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants