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

Fix Custom HTML error when block is empty #8556

Merged
merged 1 commit into from
Aug 6, 2018

Conversation

Rahmon
Copy link
Contributor

@Rahmon Rahmon commented Aug 5, 2018

Description

Fix Custom HTML block error when block is empty and Preview button is clicked.

Closes: #7277

How has this been tested?

This has been tested with "npm test" and manually on Chrome and Firefox

Types of changes

Bug fix

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.

@noisysocks noisysocks added [Type] Bug An existing feature does not function as intended [Feature] Blocks Overall functionality of blocks labels Aug 6, 2018
Copy link
Member

@noisysocks noisysocks left a comment

Choose a reason for hiding this comment

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

Thanks @Rahmon!

@noisysocks noisysocks merged commit 3a52e52 into WordPress:master Aug 6, 2018
@noisysocks noisysocks added this to the 3.5 milestone Aug 6, 2018
@Rahmon Rahmon deleted the fix/7277 branch August 6, 2018 10:29
@@ -145,7 +145,7 @@ class Sandbox extends Component {
if ( 'DIV' === potentialIframe.tagName || 'SPAN' === potentialIframe.tagName ) {
potentialIframe = potentialIframe.children[0];
}
if ( 'IFRAME' === potentialIframe.tagName ) {
if ( potentialIframe && 'IFRAME' === potentialIframe.tagName ) {
Copy link
Member

Choose a reason for hiding this comment

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

So was the error caused by property access on the undefined value?

If so, shouldn't we also need to consider the .tagName property access in the condition immediately preceding this one?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

potentialIframe && potentialIframe.tagname && 'IFRAME' === potentialIframe.tagName

is that way, right?

Copy link
Member

Choose a reason for hiding this comment

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

If so, shouldn't we also need to consider the .tagName property access in the condition immediately preceding this one?

potentialIframe isn't undefined until it's re-assigned in the condition above.

@aduth
Copy link
Member

aduth commented Aug 6, 2018

What is this code even doing? aspectRatio is unused. width is assigned to 100% but should already be effected this way via the appended styles a few lines below anyways.

Can we just remove it?

@noisysocks
Copy link
Member

cc. @notnownikki

@notnownikki
Copy link
Member

@aduth aspectRatio is used in sendResize to preserve the aspect ratio of iframes with an initial set width and height, so they can be resized to 100% width and keep the correct height. This is important when embedding content such as YouTube videos.

@notnownikki
Copy link
Member

Admittedly, the code to discover the first iframe is janky. Sorry about that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Blocks Overall functionality of blocks [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Preview button of Custom HTML block throws a console error
4 participants