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

Freeform: Unrecoverable error if embed present #4125

Closed
2 tasks
mcsf opened this issue Dec 21, 2017 · 3 comments
Closed
2 tasks

Freeform: Unrecoverable error if embed present #4125

mcsf opened this issue Dec 21, 2017 · 3 comments
Labels
[Feature] Blocks Overall functionality of blocks [Type] Bug An existing feature does not function as intended

Comments

@mcsf
Copy link
Contributor

mcsf commented Dec 21, 2017

Issue Overview

Opening a classic post containing an embed with Gutenberg leads to a broken Freeform block.

Steps to Reproduce (for bugs)

  1. Start a new post with the classic editor.
  2. Insert a paragraph of text, then add a line break.
  3. Paste an embeddable URL, e.g. https://wordpress.tv/2017/12/04/matt-mullenweg-state-of-the-word-2017/ or https://www.youtube.com/watch?v=e-QFj59PON4. An embed should correctly appear.
  4. Add a new paragraph beneath it.
  5. Save the post, as draft or published.
  6. Open the post with Gutenberg.

Expected Behavior

The original post should appear, looking more or less the same, contained in a Freeform block.

Current Behavior

No content appears, and a TypeError is logged:

TypeError: self.editor.iframeElement is undefined in mce-view.js:866:5

Possible Solution

History bisection suggests this isn't a recent regression — has it always been around? Error originates in Freeform > OldEditor > wp.oldEditor > TinyMCE. Not clear yet if error lies only in TinyMCE or in the interaction with OldEditor.

Further debugging shows that regular blocks still work and that the error is properly contained inside the Freeform block, even though the BlockCrashWarning isn't always shown:

screen shot 2017-12-21 at 14 02 02

Screenshots / Video

Related Issues and/or PRs

Todos

  • Tests
  • Documentation
@mcsf mcsf added [Feature] Blocks Overall functionality of blocks [Component] TinyMCE [Type] Bug An existing feature does not function as intended labels Dec 21, 2017
@mcsf
Copy link
Contributor Author

mcsf commented Dec 21, 2017

Note that this change in core fixes the issue for me:

diff --git a/wp-includes/js/mce-view.js b/wp-includes/js/mce-view.js
index f5aa2337ea..12bbdd1d4b 100644
--- a/wp-includes/js/mce-view.js
+++ b/wp-includes/js/mce-view.js
@@ -862,7 +862,7 @@
 			}
 
 			// Obtain the target width for the embed.
-			if ( self.editor ) {
+			if ( self.editor && self.editor.iframeElement ) {
 				maxwidth = self.editor.iframeElement.clientWidth - 20; // Minus the sum of horizontal margins and borders.
 			}

@mcsf
Copy link
Contributor Author

mcsf commented Dec 21, 2017

Hack in Gutenberg instead:

diff --git a/blocks/library/freeform/old-editor.js b/blocks/library/freeform/old-editor.js
index f38f4856..2148303e 100644
--- a/blocks/library/freeform/old-editor.js
+++ b/blocks/library/freeform/old-editor.js
@@ -89,6 +89,14 @@ export default class OldEditor extends Component {
 		const { attributes: { content }, setAttributes } = this.props;
 		const { ref } = this;
 
+		// Stub iframeElement in case plugins expect it there. See
+		// https://github.com/WordPress/gutenberg/issues/4125 for an example
+		// involving WordPress's audio/video views
+		// (wp-includes/js/mce-view.js).
+		if ( ! editor.iframeElement ) {
+			editor.iframeElement = false;
+		}
+
 		if ( content ) {
 			editor.on( 'loadContent', () => editor.setContent( content ) );
 		}

@mcsf
Copy link
Contributor Author

mcsf commented Dec 21, 2017

This was fixed in core 8 days ago:

Closing this issue. :)

@mcsf mcsf closed this as completed Dec 21, 2017
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

No branches or pull requests

1 participant