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

Fixes an incompatibility with Gutenberg for position-based highlighting #21005

Merged
merged 2 commits into from
Jan 4, 2024

Conversation

mhkuu
Copy link
Contributor

@mhkuu mhkuu commented Dec 22, 2023

Context

  • We want to fix an incompatibility with the latest Gutenberg version (17.3.0) for position-based highlighting.

Summary

This PR can be summarized in the following changelog entry:

  • Fixes a bug where highlighting for the keyphrase density assessment would not work when using the latest version of Gutenberg (17.3.0).

Relevant technical choices:

  • Before Gutenberg 17.3.0, the HTML content could be retrieved by directly calling on the RichText block's attributes. Since Gutenberg 17.3.0, that returns a RichTextData object, from which we can retrieve the HTML through toString().
  • Note that we can not use getBlockContent from @wordpress/blocks here, as the richTextIdentifier may differ per block (e.g., we only want to retrieve the caption from an image block, not the image itself).
  • In this PR, I also updated some JSDoc, and renamed some variables -- so a little bit of boy scouting.

Test instructions

Test instructions for the acceptance test before the PR gets merged

This PR can be acceptance tested by following these steps:

With new Gutenberg

  • Install and activate Free (with this PR) and Gutenberg (>= 17.3.0).
  • Create a new post.
  • Add the English text from Appendix A of the HTML Parser phase 2.2 ATP.
  • Set the following keyword: Mahler.
  • Make sure that the feedback for the keyphrase density says the following: Keyphrase density: The focus keyphrase was found 9 times. This is great!.
  • Make sure that all 9 occurrences of the keyphrase are highlighted when pressing the highlighting button.
  • Note that in the occurrence of Mahler that is followed by a dash, the word after the dash will also be highlighted (Mahler—who). This is known behavior.
  • Change the keyphrase to: Gustav Mahler.
  • Make sure that the feedback for the keyphrase density says the following: Keyphrase density: The focus keyphrase was found 2 times. This is great!
  • Make sure that all 2 occurrences of the keyphrase are highlighted when pressing the highlighting button.
  • Add an image block, set the caption to Gustav Mahler was an Austro-Bohemian Romantic composer. More on Gustav Mahler in this image..
  • Make sure that the feedback for the keyphrase density says the following: Keyphrase density: The focus keyphrase was found 4 times. This is great!.
  • Make sure that all 4 occurrences of the keyphrase are highlighted when pressing the highlighting button.

Without Gutenberg

  • Keep Free (with this PR), but deactivate Gutenberg (so that we're using the version of Gutenberg coupled with WordPress 6.4.2).
  • Repeat the above steps and verify everything works.

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 of the keyphrase density assessment in the default and Gutenberg editor.

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 #21001

@mhkuu mhkuu added the changelog: bugfix Needs to be included in the 'Bugfixes' category in the changelog label Dec 22, 2023
@coveralls
Copy link

coveralls commented Dec 22, 2023

Pull Request Test Coverage Report for Build b916859d6412f9f668afb94f29ae49ca5db20d6a

  • 11 of 12 (91.67%) changed or added relevant lines in 2 files are covered.
  • 1419 unchanged lines in 38 files lost coverage.
  • Overall coverage decreased (-10.4%) to 38.833%

Changes Missing Coverage Covered Lines Changed/Added Lines %
packages/js/src/decorator/helpers/searchBasedAnnotationHelper.js 5 6 83.33%
Files with Coverage Reduction New Missed Lines %
admin/class-option-tabs-formatter.php 1 0.0%
src/generated/assets/externals.php 1 0.0%
src/generated/assets/languages.php 1 0.0%
src/integrations/blocks/structured-data-blocks.php 1 15.5%
src/integrations/settings-integration.php 1 21.59%
admin/class-admin-editor-specific-replace-vars.php 2 85.71%
admin/formatter/class-metabox-formatter.php 2 82.29%
inc/class-wpseo-custom-fields.php 2 0.0%
inc/class-wpseo-utils.php 2 44.29%
inc/sitemaps/class-post-type-sitemap-provider.php 2 94.09%
Totals Coverage Status
Change from base Build 7345460417: -10.4%
Covered Lines: 18872
Relevant Lines: 45398

💛 - Coveralls

@mhkuu mhkuu force-pushed the fix/highlighting-gutenberg-17.3.0 branch from e729236 to 1da5157 Compare December 28, 2023 09:13
@mhkuu mhkuu changed the base branch from trunk to release/21.8 December 28, 2023 09:14
@mhkuu mhkuu marked this pull request as ready for review December 28, 2023 09:54
@mykola mykola merged commit ef60a03 into release/21.8 Jan 4, 2024
16 checks passed
@mykola mykola deleted the fix/highlighting-gutenberg-17.3.0 branch January 4, 2024 09:12
@mhkuu mhkuu added this to the 21.8 milestone Jan 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog: bugfix Needs to be included in the 'Bugfixes' category in the changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Keyphrase density highlighting does not work with latest Gutenberg
3 participants