Skip to content

Site Editor Compatibility: Podcast Player block issues in editor and front end views - #19578

Merged
ramonjd merged 8 commits into
masterfrom
fix/site-editor-podcast-player-block
Apr 26, 2021
Merged

ramonjd merged 8 commits into
masterfrom
fix/site-editor-podcast-player-block

Conversation

@ramonjd

@ramonjd ramonjd commented Apr 20, 2021 •

Copy link
Copy Markdown
Member

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:

  1. Adds a check to see if the DOM is loaded before initializing the block on the frontend.
  2. Adds a temporary workaround to inject required assets into the Site Editor iframe.

Screen Shot 2021-04-21 at 3 13 14 pm

Jetpack product discussion

Related to #19504

Does this pull request change what data or activity we track or use?

No

Testing instructions:

  1. Using a block-based theme, e.g., TT1 add a Podcast block to the site editor. Here's an RSS feed link: https://distributed.blog/category/podcast/feed/ 😄
  2. Once loaded, you should be able to interact with the player as expected.
  3. Add another one.
  4. Both should work
  5. Check that, for every podcast block you add, we're not duplicating the mediaelement-css assets.
  6. Take a look at the frontend. The player(s) should both load.
  7. Check a few other themes for regressions.
  8. Sync the changes to WPCOM and ensure that both the block and site editors work as expected.

@matticbot

Copy link
Copy Markdown
Contributor

Caution: This PR has changes that must be merged to WordPress.com
Hello ramonjd! These changes need to be synced to WordPress.com - If you 're an a11n, please commandeer and confirm D60400-code works as expected before merging this PR. Once this PR is merged, please commit the changes to WP.com. Thank you!
This revision will be updated with each commit to this PR

@github-actions github-actions Bot added the [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ label Apr 20, 2021
@github-actions

github-actions Bot commented Apr 20, 2021 •

Copy link
Copy Markdown
Contributor

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • ⚠️ All commits were linted before commit.
  • ✅ Add a "[Status]" label (In Progress, Needs Team Review, ...).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

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.
Then, add the "[Status] Needs Team review" label and ask someone from your team review the code.
Once you’ve done so, switch to the "[Status] Needs Review" label; someone from Jetpack Crew will then review this PR and merge it to be included in the next Jetpack release.


Jetpack plugin:

  • Next scheduled release: May 4, 2021.
  • Scheduled code freeze: April 26, 2021.

@ramonjd
ramonjd requested a review from a team April 21, 2021 05:22

@andrewserong andrewserong left a comment

Copy link
Copy Markdown
Member

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?

@andrewserong

Copy link
Copy Markdown
Member

Oh, it's complaining about a missing changelog entry too 🙂

@ramonjd
ramonjd force-pushed the fix/site-editor-podcast-player-block branch from 908e318 to e2e6aae Compare April 21, 2021 05:41
ramonjd added 3 commits April 22, 2021 11:39
…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.
@ramonjd
ramonjd force-pushed the fix/site-editor-podcast-player-block branch from e2e6aae to 68eda5a Compare April 22, 2021 03:17
@glendaviesnz

glendaviesnz commented Apr 22, 2021 •

Copy link
Copy Markdown
Contributor

@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 ]
	);

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.
@andrewserong

Copy link
Copy Markdown
Member

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 ref is not within the site editor iframe, but is within the iframe rendered within wordpress.com, so it's now trying to break out of Gutenberg). Here's the error after entering a podcast feed URL in the placeholder:

image

*/
export function isElementInIframe( elementRef ) {
const { currentWindow } = getLoadContext( elementRef );
return currentWindow.self !== currentWindow.top;

Copy link
Copy Markdown
Member

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>).

Copy link
Copy Markdown
Member Author

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

Copy link
Copy Markdown
Member Author

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.

@ramonjd ramonjd Apr 22, 2021 •

Copy link
Copy Markdown
Member Author

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
andrewserong
andrewserong previously approved these changes Apr 22, 2021

@andrewserong andrewserong left a comment

Copy link
Copy Markdown
Member

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!

@andrewserong andrewserong added [Status] Needs Review This PR is ready for review. and removed [Status] In Progress labels Apr 22, 2021
…mixed return types

Testing whether we indeed have access to the parent DOM before we try to avoid fatals
@ramonjd

ramonjd commented Apr 22, 2021

Copy link
Copy Markdown
Member Author

I re-tested in FSE across Safari, FF, Edge, and Chrome, via wordpress.com/site-editor and directly from the the site

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.

@jeherve jeherve added this to the jetpack/9.7 milestone Apr 22, 2021

@andrewserong andrewserong left a comment

Copy link
Copy Markdown
Member

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! 🎉

@jeherve jeherve left a comment

Copy link
Copy Markdown
Member

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. 👍

@jeherve jeherve added [Status] Ready to Merge Go ahead, you can push that green button! and removed [Status] Needs Review This PR is ready for review. labels Apr 23, 2021
@ramonjd
ramonjd merged commit 871d75b into master Apr 26, 2021
@ramonjd
ramonjd deleted the fix/site-editor-podcast-player-block branch April 26, 2021 05:38
@github-actions github-actions Bot removed the [Status] Ready to Merge Go ahead, you can push that green button! label Apr 26, 2021
@github-actions

Copy link
Copy Markdown
Contributor

Great news! One last step: head over to your WordPress.com diff, D60400-code, and commit it.
Once you've done so, come back to this PR and add a comment with your changeset ID.

Thank you!

@ramonjd

ramonjd commented Apr 26, 2021

Copy link
Copy Markdown
Member Author

r224746-wpcom

@ramonjd

ramonjd commented May 18, 2021

Copy link
Copy Markdown
Member Author

An api is being added to core Gutenberg that we may be able to use instead of the CSS shuffling: WordPress/gutenberg#31873

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Block] Podcast Player [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ Touches WP.com Files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Site Editor Compatibility: Podcast Player block issues in editor and front end views

5 participants