Skip to content

Fixes highlighting behaviour for posts converted from Classic to Gutenberg - #20667

Merged
FAMarfuaty merged 1 commit into
feature/html-parserfrom
217-html-parser-fix-highlighting-for-when-a-post-created-in-classic-editor-is-opened-in-block-editor
Sep 27, 2023
Merged

FAMarfuaty merged 1 commit into
feature/html-parserfrom
217-html-parser-fix-highlighting-for-when-a-post-created-in-classic-editor-is-opened-in-block-editor

Conversation

@mhkuu

@mhkuu mhkuu commented Sep 25, 2023 •

Copy link
Copy Markdown
Contributor

Context

  • When posts are converted from Classic editor to the default (block/Gutenberg) editor, the posts is displayed using a core/freeform block (docs). Under the hood, the WordPress autop function (docs) is applied to these blocks (see e.g. this PR for context). Our new position-based highlighting functionality did not work in that case, because these <p> tags were not parts of the HTML that is stored in the database (they are removed on save through removep (docs)).
  • In this PR, we do not account for the situation where multiple Classic blocks are added, or a Classic block is added to a post with other blocks. We consider that situation unlikely -- either your whole post is one Classic block, or you have multiple regular blocks.

Summary

This PR can be summarized in the following changelog entry:

  • Fixes an unreleased bug where the highlighting functionality would not work when posts were converted from Classic editor.

Relevant technical choices:

  • We now use getEditedPostContent to fetch the content, which is functionally the same, but reads better than this.getPostAttribute( "content" ).
  • Did a little bit of boy scouting in the touched files.

Test instructions

Test instructions for the acceptance test before the PR gets merged

This PR can be acceptance tested by following these steps:

Relevant test scenarios

  • Changes should be tested with the browser console open
  • Changes should be tested on different posts/pages/taxonomies/custom post types/custom taxonomies
  • Changes should be tested on different editors (Block/Classic/Elementor/other)
  • Changes should be tested on different browsers
  • Changes should be tested on multisite

Test instructions for QA when the code is in the RC

  • QA should use the same steps as above.

QA can test this PR by following these steps:

Impact check

This PR affects the following parts of the plugin, which may require extra testing:

  • The highlighting feature for Classic blocks in Gutenberg.

UI changes

  • This PR changes the UI in the plugin. I have added the 'UI change' label to this PR.

Other environments

  • This PR also affects Shopify. I have added a changelog entry starting with [shopify-seo], added test instructions for Shopify and attached the Shopify label to this PR.

Documentation

  • I have written documentation for this change.

Quality assurance

  • I have tested this code to the best of my abilities.
  • During testing, I had activated all plugins that Yoast SEO provides integrations for.
  • I have added unit tests to verify the code works as intended.
  • If any part of the code is behind a feature flag, my test instructions also cover cases where the feature flag is switched off.
  • I have written this PR in accordance with my team's definition of done.
  • I have checked that the base branch is correctly set.

Innovation

  • No innovation project is applicable for this PR.
  • This PR falls under an innovation project. I have attached the innovation label.
  • I have added my hours to the WBSO document.

Fixes https://github.com/Yoast/lingo-other-tasks/issues/217

@mhkuu mhkuu added the changelog: non-user-facing Needs to be included in the 'Non-userfacing' category in the changelog label Sep 25, 2023
@mhkuu mhkuu added this to the feature/HTML-parser milestone Sep 25, 2023
@mhkuu
mhkuu marked this pull request as ready for review September 25, 2023 09:08
@FAMarfuaty

Copy link
Copy Markdown
Contributor

In this PR, we do not account for the situation where multiple Classic blocks are added, or a Classic block is added to a post with other blocks. We consider that situation unlikely -- either your whole post is one Classic block, or you have multiple regular blocks.

I wonder about this decision, did we decide not account for the cases you mentioned above because of technical challenges? When I read these two articles: How to Use the Classic Editor Block with WordPress Gutenberg and How to Use the WordPress Classic Block
, using multiple classic blocks or mixing classic block with other regular blocks doesn't seem to be discouraged. How can we be sure that those two situations are unlikely?

@mhkuu

mhkuu commented Sep 27, 2023

Copy link
Copy Markdown
Contributor Author

My rationale is that you could in principle do everything with the classic editor -- even add images for example -- so why would you then do that in other blocks, right? Or have two classic blocks?

Also, if people do experience problems, we can always point them out that they can use the "convert to blocks" button.

@FAMarfuaty FAMarfuaty left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The code looks good 🙌🏽 . And indeed I agree that this approach is the one that makes more sense.

My rationale is that you could in principle do everything with the classic editor -- even add images for example -- so why would you then do that in other blocks, right? Or have two classic blocks?

Also, if people do experience problems, we can always point them out that they can use the "convert to blocks" button.

I agree with this rationale. Also I was checking apparently when there are two consecutive classic blocks, both blocks are actually merged on post save. So the highlighting will still work (after the post is saved).

I was also looking if it's actually easier to just support annotating "core/freeform" blocks with Gutenberg annotation API, but it's actually more complicated that what I initially thought 😅

*/
getInitialData( replaceVars ) {
const gutenbergData = this.collectGutenbergData( this.getPostAttribute );
const gutenbergData = this.collectGutenbergData();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice boy scouting 🙌🏽

@FAMarfuaty

Copy link
Copy Markdown
Contributor

Acceptance 💯

@FAMarfuaty
FAMarfuaty merged commit e021830 into feature/html-parser Sep 27, 2023
@FAMarfuaty
FAMarfuaty deleted the 217-html-parser-fix-highlighting-for-when-a-post-created-in-classic-editor-is-opened-in-block-editor branch September 27, 2023 11:28
@mhkuu mhkuu modified the milestones: feature/HTML-parser, 21.4 Oct 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog: non-user-facing Needs to be included in the 'Non-userfacing' category in the changelog

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants