-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Conversation
Here is how your PR affects size of JS and CSS bundles shipped to the user's browser: Sections (~9 bytes added 📈 [gzipped])
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. Generated by performance advisor bot at iscalypsofastyet.com. |
@@ -49,12 +33,12 @@ class EmbedView extends Component { | |||
} | |||
|
|||
constrainEmbedDimensions() { | |||
if ( ! this.refs.iframe ) { | |||
if ( ! this.iframe ) { |
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.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 ) { |
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.
Check for this.iframe.current
instead.
}, | ||
this.setHtml | ||
); | ||
this.setHtml(); |
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.
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 | ||
); |
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'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.
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'm not sure either 🤷 I prefer closing this one to avoid introducing subtle bugs. Let's revisit in the future 👍
Closing, will revisit in the future. |
This PR is a follow-up to a recommendation made in a previous PR: #38608 (comment) by @jsnajdr.
Changes proposed in this Pull Request
Testing instructions