-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
elem instanceof HTMLDivElement fails in iframe editor #53867
Comments
Are you enqueuing Masonry outside or inside the iframe? In this particular case, you should enqueue it inside the iframe because it's a script that should run both in the editor and front-end. We actually used Masonry in an e2e test: gutenberg/packages/e2e-tests/plugins/iframed-masonry-block/editor.js Lines 33 to 57 in c7ff22a
|
I'm importing it in my edit.js file:
|
I am having the same issue. I wanted to use keen-slider in my edit function, which also checks for import { useEffect, useRef } from '@wordpress/element';
export default function Edit() {
const myRef = useRef();
useEffect( () => {
if ( myRef.current ) {
console.log( myRef.current.constructor.name ); // => HTMLDivElement
console.log( myRef.current instanceof HTMLDivElement ); // => false
const refDocumnent = myRef.current.ownerDocument;
const refDocumnentParent = refDocumnent.defaultView.parent.document;
console.log( refDocumnent === window.document ); // => false
console.log( refDocumnentParent === window.document ); // => true
}
}, [ ] );
return <div ref={ myRef }>Test</div>;
} |
Hi, |
If you want to use element instanceOf element.ownerDocument.defaultView.HTMLDivElement In the case of Masonry it's better to load it in the iframe instead of the editor frame, because it's a front-end script. #53867 (comment) |
Has anyone managed to make Masonry work in the iFrame editor using the code posted by @ellatrix? In my case, it's not loaded at all. |
In case anyone is having problems with this, you need to add the Masonry lib to the |
Description
I'm using https://masonry.desandro.com in some of my blocks, both on frontend and in the editor. Trying out the new iframed editor in Wordpress 6.3, I noticed that Masonry in the editor isn't working anymore - no items are added to the masonry and the layout fails.
Turns out that this line hidden in the Masonry code is the reason:
For some reason,
elem instanceof HTMLDivElement
always fails when this code is loaded in the iframed editor. Now, if I check the type of elem it indeed is HTMLDivElement. I'm guessing this is some kind of scoping issue, i.e. that the HTMLDivElement type of the iframe is not equal to the type of the HTMLDivElement in the parent document?Is there a fix for this in Wordpress/Gutenberg, apart from hoping the Masonry will update their code?
Step-by-step reproduction instructions
Run editor javascript code that checks if an html element is an instance of HTMLDivElement
Screenshots, screen recording, code snippet
No response
Environment info
No response
Please confirm that you have searched existing issues in the repo.
Yes
Please confirm that you have tested with all plugins deactivated except Gutenberg.
Yes
The text was updated successfully, but these errors were encountered: