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

Post Editor: Update EmbedView to use createRef instead of string refs #39316

Closed
wants to merge 2 commits into from

Conversation

tyxla
Copy link
Member

@tyxla tyxla commented Feb 7, 2020

This PR is a follow-up to a recommendation made in a previous PR: #38608 (comment) by @jsnajdr.

Changes proposed in this Pull Request

  • Post Editor: Update EmbedView to use createRef instead of string refs

Testing instructions

  • Tinker with embeds in the classic Calypso post editor and verify they still work well and unchanged.

@tyxla tyxla added [Feature] Post/Page Editor The editor for editing posts and pages. [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. [Type] Janitorial labels Feb 7, 2020
@tyxla tyxla requested review from jsnajdr and a team February 7, 2020 16:36
@tyxla tyxla self-assigned this Feb 7, 2020
@matticbot
Copy link
Contributor

@matticbot
Copy link
Contributor

Here is how your PR affects size of JS and CSS bundles shipped to the user's browser:

Sections (~9 bytes added 📈 [gzipped])

name         parsed_size           gzip_size
post-editor        -23 B  (-0.0%)       +9 B  (+0.0%)

Sections contain code specific for a given set of routes. Is downloaded and parsed only when a particular route is navigated to.

Legend

What is parsed and gzip size?

Parsed Size: Uncompressed size of the JS and CSS files. This much code needs to be parsed and stored in memory.
Gzip Size: Compressed size of the JS and CSS files. This much data needs to be downloaded over network.

Generated by performance advisor bot at iscalypsofastyet.com.

@@ -49,12 +33,12 @@ class EmbedView extends Component {
}

constrainEmbedDimensions() {
if ( ! this.refs.iframe ) {
if ( ! this.iframe ) {
Copy link
Member

Choose a reason for hiding this comment

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

this.iframe is always an object, for example, { current: null }. What you really want to check for is ! this.iframe.current.

@@ -78,11 +62,11 @@ class EmbedView extends Component {
}

setHtml() {
if ( ! this.props.embed?.body || ! this.refs.iframe ) {
if ( ! this.props.embed?.body || ! this.iframe ) {
Copy link
Member

Choose a reason for hiding this comment

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

Check for this.iframe.current instead.

},
this.setHtml
);
this.setHtml();
Copy link
Member

Choose a reason for hiding this comment

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

componentDidMount should also call constrainEmbedDimensions() here.

Previously, there was a setState( { wrapper } ) call that immediately triggered a second render. On that second render, componentDidUpdate was called with in turn called constrainEmbedDimensions.

But now, when this setState() is gone, there can be just one initial render with no further updates.

wrapper: this.refs.view,
},
this.setHtml
);
Copy link
Member

Choose a reason for hiding this comment

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

I'm afraid this setState() call, which forces a two pass render, might be necessary. It first renders the container <div> and then, in second pass, creates the <iframe>. Instead of rendering <div><iframe></div> in one pass.

When iframe is being created in DOM, it might go through some weird intermediate state where iframe.contentDocument or iframe.contentWindow are null. And they are initialized only a moment later, when some async process inside the browser finishes.

If iframe.contentDocument is null, our code can either crash, or fail to set the content HTML.

I've been debugging this a few months ago inside the components/web-preview component and still don't understand it.

Here's the relevant definition from the spec: https://html.spec.whatwg.org/multipage/iframe-embed-object.html#dom-iframe-contentwindow

I don't know what "nested browsing context" means and when it exists or not.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not sure either 🤷 I prefer closing this one to avoid introducing subtle bugs. Let's revisit in the future 👍

@tyxla tyxla added [Status] In Progress [Status] Needs Author Reply [Pri] Low Address when resources are available. and removed [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. labels Feb 21, 2020
@matticbot matticbot added the [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. label Sep 10, 2020
@tyxla
Copy link
Member Author

tyxla commented Sep 10, 2020

Closing, will revisit in the future.

@tyxla tyxla closed this Sep 10, 2020
@tyxla tyxla deleted the update/tinymce-embed-view-string-refs branch September 10, 2020 09:31
@tyxla tyxla removed [Status] In Progress [Status] Needs Author Reply [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. labels Sep 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Post/Page Editor The editor for editing posts and pages. [Pri] Low Address when resources are available. [Type] Janitorial
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants