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

Heading: Uncaught TypeError when pressing Enter #3867

Closed
2 tasks
mcsf opened this issue Dec 8, 2017 · 2 comments · Fixed by #3917
Closed
2 tasks

Heading: Uncaught TypeError when pressing Enter #3867

mcsf opened this issue Dec 8, 2017 · 2 comments · Fixed by #3917
Labels
[Feature] Blocks Overall functionality of blocks [Feature] Writing Flow Block selection, navigation, splitting, merging, deletion...

Comments

@mcsf
Copy link
Contributor

mcsf commented Dec 8, 2017

Issue Overview

When pressing Enter in a Heading block, either at the end of the editable field or anywhere before that, an uncaught TypeError is thrown, though seemingly no user-facing breakage occurs.

Steps to Reproduce (for bugs)

  1. Open the browser console.
  2. Start a post.
  3. Type ## This is a heading, which should convert to a H2-level Heading.
  4. Press Enter to start a Paragraph below.

Expected Behavior

Nothing should happen aside from a new Paragraph appearing and the cursor (and focus) moving to it.

Current Behavior

On the top of the expected behavior, a logged TypeError appears in the console.

Possible Solution

A quick glance at the stack trace and some reading of blocks/editable/index.js make me wonder if this is caused by an interaction in/with TinyMCE. Perhaps @ephox-mogran knows.

Screenshots / Video

screen shot 2017-12-08 at 11 33 00

Todos

  • Tests
  • Documentation
@mcsf mcsf added [Feature] Blocks Overall functionality of blocks [Feature] Writing Flow Block selection, navigation, splitting, merging, deletion... labels Dec 8, 2017
@ephox-mogran
Copy link
Contributor

The problem is that the enter key handling is firing on an editor that has just been removed from the dom. If you include a stopImmediatePropagation in the onKeyDown code in editable/index.js, it doesn't happen.

} else {
				event.preventDefault();
                                // This line is added.
				event.stopImmediatePropagation();

				if ( event.shiftKey || ! this.props.onSplit ) {
					this.editor.execCommand( 'InsertLineBreak', false, event );
				} else {
					this.splitContent();
				}
			}

Note, you may only want to add it if you aren't pressing Shift because you really only want to add it when you are recreating the editors. E.g.

} else {
				event.preventDefault();
				if ( event.shiftKey || ! this.props.onSplit ) {
					this.editor.execCommand( 'InsertLineBreak', false, event );
				} else {
                                       // This line is added.
	           		       event.stopImmediatePropagation();

					this.splitContent();
				}
			}

This should stop the caret handling that happens onKeyDown which is causing this problem. It is trying to read the range of an editor no longer in the DOM.

@mcsf
Copy link
Contributor Author

mcsf commented Dec 11, 2017

Thanks for the comment, @ephox-mogran. I've opened a fix.

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 [Feature] Writing Flow Block selection, navigation, splitting, merging, deletion...
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants