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

Don't send empty paragraph tags to view on Android #22561

Merged
merged 14 commits into from
Aug 31, 2020

Conversation

cameronvoell
Copy link
Member

@cameronvoell cameronvoell commented May 22, 2020

Fixes wordpress-mobile/gutenberg-mobile#1970

Gutenberg-Mobile PR: wordpress-mobile/gutenberg-mobile#2307

Description

This change is for fixing missing placeholder text on Quote and Pullquote blocks on Android. The updates here detect in RichText on Android when we are sending empty paragraph tags to RCTAztecView and send an empty string instead.

We then add a check to onTextUpdate to ensure that empty paragraph text does not get passed back to the RichText Value without having its paragraph tags added back.

How has this been tested?

  1. Add Quote and Pullquote blocks, verify that the "Enter Quote" placeholder text is visible.
  2. Try adding multiline quotes and merging other blocks into a quote block, make sure no text is lost.
  3. Smoke test other rich text based blocks to ensure there is no unintended behavior
  4. Add empty, and multiline quotes and make sure the html shows paragraph tags for each line of text.

*Note that this fix does not resolve the extra backspace issue seen in other blocks (wordpress-mobile/gutenberg-mobile#1524). The simple case of typing a quote and then pressing backspace seems to reshow the placeholder correctly, but if you press enter to make a multiline quote, and then backspace til empty, the placeholder will not show similar to how we need an extra backspace in other blocks.

Screenshots

Screen Shot 2020-05-22 at 6 20 29 PM

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.
  • I've updated all React Native files affected by any refactorings/renamings in this PR.

@cameronvoell cameronvoell marked this pull request as draft May 22, 2020 21:21
@github-actions
Copy link

github-actions bot commented May 22, 2020

Size Change: 0 B

Total Size: 1.17 MB

ℹ️ View Unchanged
Filename Size Change
build/a11y/index.js 1.14 kB 0 B
build/annotations/index.js 3.67 kB 0 B
build/api-fetch/index.js 3.44 kB 0 B
build/autop/index.js 2.82 kB 0 B
build/blob/index.js 620 B 0 B
build/block-directory/index.js 7.99 kB 0 B
build/block-directory/style-rtl.css 953 B 0 B
build/block-directory/style.css 952 B 0 B
build/block-editor/index.js 126 kB 0 B
build/block-editor/style-rtl.css 10.8 kB 0 B
build/block-editor/style.css 10.8 kB 0 B
build/block-library/editor-rtl.css 8.52 kB 0 B
build/block-library/editor.css 8.52 kB 0 B
build/block-library/index.js 136 kB 0 B
build/block-library/style-rtl.css 7.47 kB 0 B
build/block-library/style.css 7.47 kB 0 B
build/block-library/theme-rtl.css 741 B 0 B
build/block-library/theme.css 742 B 0 B
build/block-serialization-default-parser/index.js 1.88 kB 0 B
build/block-serialization-spec-parser/index.js 3.1 kB 0 B
build/blocks/index.js 47.7 kB 0 B
build/components/index.js 200 kB 0 B
build/components/style-rtl.css 15.7 kB 0 B
build/components/style.css 15.7 kB 0 B
build/compose/index.js 9.67 kB 0 B
build/core-data/index.js 12.3 kB 0 B
build/data-controls/index.js 1.29 kB 0 B
build/data/index.js 8.55 kB 0 B
build/date/index.js 5.38 kB 0 B
build/deprecated/index.js 772 B 0 B
build/dom-ready/index.js 568 B 0 B
build/dom/index.js 4.48 kB 0 B
build/edit-navigation/index.js 11.7 kB 0 B
build/edit-navigation/style-rtl.css 1.16 kB 0 B
build/edit-navigation/style.css 1.16 kB 0 B
build/edit-post/index.js 304 kB 0 B
build/edit-post/style-rtl.css 5.61 kB 0 B
build/edit-post/style.css 5.61 kB 0 B
build/edit-site/index.js 17 kB 0 B
build/edit-site/style-rtl.css 3.06 kB 0 B
build/edit-site/style.css 3.06 kB 0 B
build/edit-widgets/index.js 11.9 kB 0 B
build/edit-widgets/style-rtl.css 2.45 kB 0 B
build/edit-widgets/style.css 2.45 kB 0 B
build/editor/editor-styles-rtl.css 492 B 0 B
build/editor/editor-styles.css 493 B 0 B
build/editor/index.js 45.3 kB 0 B
build/editor/style-rtl.css 3.81 kB 0 B
build/editor/style.css 3.81 kB 0 B
build/element/index.js 4.65 kB 0 B
build/escape-html/index.js 733 B 0 B
build/format-library/index.js 7.71 kB 0 B
build/format-library/style-rtl.css 547 B 0 B
build/format-library/style.css 548 B 0 B
build/hooks/index.js 2.13 kB 0 B
build/html-entities/index.js 621 B 0 B
build/i18n/index.js 3.57 kB 0 B
build/is-shallow-equal/index.js 710 B 0 B
build/keyboard-shortcuts/index.js 2.52 kB 0 B
build/keycodes/index.js 1.94 kB 0 B
build/list-reusable-blocks/index.js 3.12 kB 0 B
build/list-reusable-blocks/style-rtl.css 476 B 0 B
build/list-reusable-blocks/style.css 476 B 0 B
build/media-utils/index.js 5.32 kB 0 B
build/notices/index.js 1.79 kB 0 B
build/nux/index.js 3.4 kB 0 B
build/nux/style-rtl.css 671 B 0 B
build/nux/style.css 668 B 0 B
build/plugins/index.js 2.56 kB 0 B
build/primitives/index.js 1.41 kB 0 B
build/priority-queue/index.js 789 B 0 B
build/redux-routine/index.js 2.85 kB 0 B
build/rich-text/index.js 13.9 kB 0 B
build/server-side-render/index.js 2.77 kB 0 B
build/shortcode/index.js 1.7 kB 0 B
build/token-list/index.js 1.27 kB 0 B
build/url/index.js 4.06 kB 0 B
build/viewport/index.js 1.85 kB 0 B
build/warning/index.js 1.14 kB 0 B
build/wordcount/index.js 1.17 kB 0 B

compressed-size-action

@cameronvoell cameronvoell force-pushed the rnmobile/fix-missing-placeholder-quote-blocks branch from 353607a to af6afdd Compare May 23, 2020 00:08
@cameronvoell cameronvoell added the Mobile App - i.e. Android or iOS Native mobile impl of the block editor. (Note: used in scripts, ping mobile folks to change) label May 23, 2020
@cameronvoell cameronvoell self-assigned this May 23, 2020
@cameronvoell cameronvoell force-pushed the rnmobile/fix-missing-placeholder-quote-blocks branch from af6afdd to c7cb54a Compare May 23, 2020 01:43
@cameronvoell cameronvoell marked this pull request as ready for review May 23, 2020 02:44
}
return value;
}

Copy link
Member Author

Choose a reason for hiding this comment

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

Removing empty paragraph tags to fix missing placeholders on Quote/Pullquote blocks seems to work fine except for calls to the imported create function from gutenberg/packages/rich-text/src/create.js. That function seems to only work at extracting text in order to create the record object if we re-add paragraph tags for multiline text.

@hypest hypest requested review from SergioEstevao and removed request for hypest May 25, 2020 14:08
@@ -679,8 +698,8 @@ export class RichText extends Component {
value = '';
}
// On android if content is empty we need to send no content or else the placeholder will not show.
if ( ! this.isIOS && value === '' ) {
return value;
if ( ! this.isIOS && ( value === '' || value === '<p></p>' ) ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

In here instead of doing value === <p></p> you should write value === '<'+tagname+'></'+tagname'>'

Copy link
Member Author

@cameronvoell cameronvoell May 26, 2020

Choose a reason for hiding this comment

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

I understand the thought here, but there are a few issues. First off to catch this issue for Quote/Pullquote and List Block we would not want to use tagName, but this.multilineTag which seems to be the tag that is staying in value that is preventing us from seeing the placeholder. Even if we do switch this to target the general case of a remaining this.multilineTag, removing this for the List Block seems to create issues that are quite unique from the Quote and Pullquote block (basically the ListBlock no longer acts like a list block), different enough to justify a separate fix for List Block in my opinion.

Copy link
Contributor

@SergioEstevao SergioEstevao left a comment

Choose a reason for hiding this comment

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

While it solves the issues with placeholder on quotes and pullquotes, I think we should also try to fix lists and make the code change only affect Android.

Left some comments on the code on how to address those.

@cameronvoell cameronvoell force-pushed the rnmobile/fix-missing-placeholder-quote-blocks branch from 717df2d to eace29c Compare May 26, 2020 07:46
@cameronvoell
Copy link
Member Author

While it solves the issues with placeholder on quotes and pullquotes, I think we should also try to fix lists and make the code change only affect Android.

@SergioEstevao Thanks for the comments and feedback. I addressed your second point by making the fix only touch Android.

As far as fixing List Block placeholders go, it seems to me that the strategy of this fix for Quote/Pullquote would require some pretty unique changes to simultaneously fix List Block (see comment here #22561 (comment)).

My opinion now is that given how convuluted RichText has become, to get a quick win for fixing Quote/Pullquote placeholders for the upcoming release, my thinking was that the strategy of being as non-intrusive as possible felt like the only way of fixing without refactoring more and more of RichText.

I would love to make this fix feel even safer and more targeted for this release, and am open to advice on that front, otherwise if we think it is not worth fixing this single case, without a larger refactor to address some of the underlying causes I understand that perspective as well. @hypest I'd be interested to hear your opinion on this as well.

@hypest
Copy link
Contributor

hypest commented May 26, 2020

Had a look on develop trying to understand what's different with the Quote/Pullquote blocks and, say, the Paragraph block. I haven't totally finished the investigation but, there might be something wrong with how the Pullquote block is defining its tagName and multilineTag parameters: While debugging, I see that valueToFormat() fails to remove the empty <p></p> pair because toHTMLString is adding ps while removeRootTagsProduceByAztec is removing divs. Can't tell yet if the the two tag parameters should match, but something feels wrong.

Let's get to the bottom of this before finalizing the fix, to be sure the fix is safe.

@mchowning
Copy link
Contributor

Noticed that if text without any newline is added to a pullquote or quote block and then deleted, the placeholder is restored. But adding text with a newline then deleting all the text (including the newline) does not restore the placeholder. If you deselect the block and reselect it, the placeholder reappears, so this seems like a pretty minor issue that doesn't need to be fixed right away.

A quick bit of debugging makes me think this is because of something happening inside of Aztec because the html looks fine.

@cameronvoell
Copy link
Member Author

Ran through the writing flows manual tests, making sure to test Quote and Pullquote whenever relevant

Had some problems with this test:
TC002
Undo/redo text

  • Write some text on a text based block .
  • Press Undo until all new text has disappeared.
  • Press Redo to see the text appear again.

It looks like this behavior is not perfect on Android on develop and Beta release (cursor seems to move to incorrect position, end -1 ). However on the branch with this fix, the Quote and Pullquote seems to have additional problems on undo and redo. I had one case where I was unable to press redo enough times to recover all the text I deleted by pressing undo. I'm going to see if I can fix this.

@cameronvoell cameronvoell force-pushed the rnmobile/fix-missing-placeholder-quote-blocks branch from e0f3acf to 47494b5 Compare May 28, 2020 16:20
@ceyhun
Copy link
Member

ceyhun commented May 28, 2020

Tried this from inside WPAndroid and got a red screen:

To reproduce:

  1. Add a Pullquote and write some text to quote part
  2. Exit and save as draft
  3. Re-open draft

@cameronvoell cameronvoell force-pushed the rnmobile/fix-missing-placeholder-quote-blocks branch from 0d04f77 to 47494b5 Compare August 13, 2020 04:43
@cameronvoell
Copy link
Member Author

cameronvoell commented Aug 13, 2020

@ceyhun Did not get to test this extensively yet, but f664971 seems to fix the red screen you were seeing. I think I can spend some time making the code itself more clear, but at least this seems like a relatively simple viable strategy since it seems to fix all issues I was seeing previously.

Can test WPAndroid using the APK here: wordpress-mobile/WordPress-Android#12663 (comment)

@mchowning
Copy link
Contributor

I feel like there's a chance this PR might also address wordpress-mobile/gutenberg-mobile#1524. May be worth checking that issue as well when reviewing this.

@cameronvoell cameronvoell marked this pull request as ready for review August 28, 2020 04:50
! this.isIOS &&
( value === '' || value === EMPTY_MULTILINE_PARAGRAPH )
) {
return '';
Copy link
Member Author

@cameronvoell cameronvoell Aug 28, 2020

Choose a reason for hiding this comment

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

This ensures that empty paragraph tags do not get passed to the RCTAztecView (thus hiding the placeholder)

@@ -283,14 +286,29 @@ export class RichText extends Component {
const contentWithoutRootTag = this.removeRootTagsProduceByAztec(
unescapeSpaces( event.nativeEvent.text )
);
let formattedContent = contentWithoutRootTag;
if ( ! this.isIOS ) {
formattedContent = this.restoreParagraphTags(
Copy link
Member Author

@cameronvoell cameronvoell Aug 28, 2020

Choose a reason for hiding this comment

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

Text with removed paragraph tags from https://github.com/WordPress/gutenberg/pull/22561/files#r478829512 can not pass from RCTAztecView to the RichText value without coming through this call in the onTextUpdate function.

@@ -264,7 +267,7 @@ export class RichText extends Component {
/*
* Handles any case where the content of the AztecRN instance has changed
*/
onChange( event ) {
onChangeFromAztec( event ) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Updated method name to help distinguish from this.props.onChange which is used many times elsewhere in this class.

@cameronvoell
Copy link
Member Author

I feel like there's a chance this PR might also address wordpress-mobile/gutenberg-mobile#1524. May be worth checking that issue as well when reviewing this.

@mchowning Unfortunately, that issue seems to be different from the quote/pullquote issue, and the fix here does not address the backspace sometimes needed to show the placeholder. My current thoughts are that that issue should be tackled in a separate PR.

Copy link
Contributor

@mchowning mchowning left a comment

Choose a reason for hiding this comment

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

Looks good and works well for me. Only had one minor code comment. Nice job! 👍

@@ -59,6 +59,8 @@ const gutenbergFormatNamesToAztec = {
'core/strikethrough': 'strikethrough',
};

const EMPTY_MULTILINE_PARAGRAPH = '<p></p>';
Copy link
Contributor

Choose a reason for hiding this comment

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

Not a big deal, but what is the significance of "MULTILINE" in this name? Is there a non-multiline paragraph we're distinguishing?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point, updated to better name here: 8f9bd43

@mchowning
Copy link
Contributor

Unfortunately, that issue seems to be different from the quote/pullquote issue, and the fix here does not address the backspace sometimes needed to show the placeholder. My current thoughts are that that issue should be tackled in a separate PR.

👍 I agree, that doesn't need to be fixed here. I just thought there was a chance that might get fixed "for free" with your changes.

@cameronvoell
Copy link
Member Author

@hypest Let us know if you can remove the requested change restriction here from Sergio #22561 (review). His concern was about simultaneously fixing List block placeholder on Android which as I explained here: #22561 (comment) it feels like the List block issue should be addressed separately.

@hypest hypest dismissed SergioEstevao’s stale review August 31, 2020 09:49

Dismissing since Sérgio is on sabbatical at the moment and the blocking bit (including the List block handling as well) can be addressed seperately.

@cameronvoell cameronvoell merged commit e268e1e into master Aug 31, 2020
@cameronvoell cameronvoell deleted the rnmobile/fix-missing-placeholder-quote-blocks branch August 31, 2020 16:18
@github-actions github-actions bot added this to the Gutenberg 8.9 milestone Aug 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Mobile App - i.e. Android or iOS Native mobile impl of the block editor. (Note: used in scripts, ping mobile folks to change)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Quote block placeholder is not visible
5 participants