-
Notifications
You must be signed in to change notification settings - Fork 798
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
Site Editor Compatibility: Podcast Player block issues in editor and front end views #19578
Conversation
Caution: This PR has changes that must be merged to WordPress.com |
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖 Once your PR is ready for review, check one last time that all required checks (other than "Required review") appearing at the bottom of this PR are passing or skipped. Jetpack plugin:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for investigating this one @ramonjd. I think this looks like a reasonable temporary workaround. I haven't tested it yet, but just wondered if we should add a couple of extra checks just in case (for some reason?) the expected CSS hasn't been enqueued in the parent document?
projects/plugins/jetpack/extensions/blocks/podcast-player/utils.js
Outdated
Show resolved
Hide resolved
projects/plugins/jetpack/extensions/blocks/podcast-player/utils.js
Outdated
Show resolved
Hide resolved
Oh, it's complaining about a missing changelog entry too 🙂 |
908e318
to
e2e6aae
Compare
…til the dom is loaded before we execute DOM-based queries.
I don't like doing this, but there's no other way to enqueue/inject the styles we need for the podcast player into the site editor iframe. So, using JS and the DOM, we find the CSS we need from the head of the parent window and move it into the site editor. YAY. Changelog Adding null checks to the elements we should ensure that the parent-level dom elements are there before we use them
…e now before we load. Abstracting the element copier to be more generic.
e2e6aae
to
68eda5a
Compare
@ramon it looks like there might be some funny race condition as it doesn't work for me locally as the useEffect never gets fired with podcastPlayerRef.current defined. TIL - it seems like you can't rely on ref to cause a rerender when the dom node is assigned/changed and should use a callback ref instead. I switched it to the following locally and that seemed to fix it for me: const podCastPlayerRef = useCallback(
node => {
if ( node !== null && ! hasMigratedStyles ) {
maybeCopyElementsToSiteEditorContext(
[ 'link#mediaelement-css', 'link#wp-mediaelement-css' ],
node
);
setHasMigratedStyles( true );
}
},
[ hasMigratedStyles ]
); |
projects/plugins/jetpack/extensions/shared/block-editor-asset-loader.js
Outdated
Show resolved
Hide resolved
In the case of style sheets it won't matter much for our current use case (podcast player) but for other elements we might want to leave the element in both contexts. I can't for the life of me think of a reason why right now.
This is testing well in FSE across Safari, FF, Chrome, and Edge. Unfortunately, I think this approach introduces a regression in a non-FSE theme in wpcom. Because in that context we are rendering Gutenberg within an iframe from wordpress.com, it looks like it's attempting to access the wrong parent document (e.g. the |
*/ | ||
export function isElementInIframe( elementRef ) { | ||
const { currentWindow } = getLoadContext( elementRef ); | ||
return currentWindow.self !== currentWindow.top; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We might need to add an additional check either here or within getLoadContext
that we're in the correct iframe (the site editor) and not within another version of an iframed editor (e.g. the post/page editor iframed within wordpress.com/post/<blog_name>/<post_id>
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh wow, thanks for double checking that. 🤕
I did check in WPCOM when I was initially targeting 'iframe[name="editor-canvas"]'
I'll try to reinstate that test.
THANK YOU
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I re-added an iframe name check. Not ideal, but the whole thing is (theoretically) transitory.
I could try to check in the back end and add a global JS variable if it might help future endeavours.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could also test that the iframe passes the same-origin-policy before we try to start injecting things into the header and bork it all again. :D
…e name. It's not 100% bullet-proof, but aligns with the general theme of ephemerality in relation to these site editor bug fixes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for implementing all those changes @ramonjd! This is testing nicely for me now. I re-tested in FSE across Safari, FF, Edge, and Chrome, via wordpress.com/site-editor and directly from the the site, and double-checked that the addition of checking for the iframe name resolves the regression 👍
LGTM!
…mixed return types Testing whether we indeed have access to the parent DOM before we try to avoid fatals
Thanks for testing so thoroughly! I added another, small condition to see if the child iframe has access to its parent (same origin). Hopefully will prevent borks if the editor iframe name ever changes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for adding the additional check @ramonjd 👍 that looks safer. Just gave this another quick smoke test in the post/page editor (via wordpress.com iframe and via wp-admin) and the site editor (again via wordpress.com/site-editor and the direct /wp-admin url). LGTM! 🎉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This tests well for me. 👍
Great news! One last step: head over to your WordPress.com diff, D60400-code, and commit it. Thank you! |
r224746-wpcom |
An api is being added to core Gutenberg that we may be able to use instead of the CSS shuffling: WordPress/gutenberg#31873 |
This PR addresses Podcast Player block compatibility issues in the site editor, and on the frontend in block-based themes.
Fixes #19483
Changes proposed in this Pull Request:
Jetpack product discussion
Related to #19504
Does this pull request change what data or activity we track or use?
No
Testing instructions: