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

Clone the blocks array first before filtering out the invalid blocks and add block length information #22006

Open
wants to merge 3 commits into
base: trunk
Choose a base branch
from

Conversation

FAMarfuaty
Copy link
Contributor

@FAMarfuaty FAMarfuaty commented Jan 30, 2025

Context

  • We want to fix a bug where the Yoast SEO analysis remove broken blocks with "Attempt recovery"

Summary

This PR can be summarized in the following changelog entry:

  • Fixes a bug where broken blocks with "Attempt recovery" were removed on save.

Relevant technical choices:

  • We are fixing the problem by cloning the blocks array before making any modification to the array.

  • This is necessary because otherwise, invalid blocks will be removed from the editor.

  • We are using JSON.parse and JSON.stringify to clone the blocks over lodash.cloneDeep or structuredClone for the following reasons:

    • _.cloneDeep cannot handle private members of classes from the blocks.
    • structuredClone failed in cloning invalid blocks.
    • Both methods will result in the analysis failing because the blocks are not cloned correctly.
  • We are aware of the performance implications of using JSON.parse and JSON.stringify, see this page.

  • However, considering the reasons we've mentioned above regarding the other methods, and we're running this once and not recursively, we consider the performance impact to be negligible.

Test instructions

Test instructions for the acceptance test before the PR gets merged

This PR can be acceptance tested by following these steps:

  • Install and activate the Yoast SEO plugin.
  • Create a post in block/Gutenberg editor
  • Add a core/group block.
  • Add two core/paragraph blocks as inner blocks to that group.
  • In the second core/paragraph block, edit the HTML, change the end tag to <\/p>
  • Now the second block goes into recovery mode, as it's invalid HTML.
  • Save the post
  • Confirm that the broken block (the second paragraph block) is still saved and not removed

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 (Default Block/Gutenberg/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:

  • Smoke test the highlighting function of Keyphrase density and Passive voice sentence assessment.

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. For example, comments in the Relevant technical choices, comments in the code, documentation on Confluence / shared Google Drive / Yoast developer portal, or other.

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

@FAMarfuaty FAMarfuaty added the changelog: bugfix Needs to be included in the 'Bugfixes' category in the changelog label Jan 30, 2025
@coveralls
Copy link

coveralls commented Jan 30, 2025

Pull Request Test Coverage Report for Build c80ce0c90f640421acccef6c12c66776a26680e2

Details

  • 1 of 1 (100.0%) changed or added relevant line in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 54.539%

Totals Coverage Status
Change from base Build fedc1b286bb15dc44c2150ae129cd3beba01321d: 0.0%
Covered Lines: 30187
Relevant Lines: 55776

💛 - Coveralls

@FAMarfuaty FAMarfuaty marked this pull request as ready for review January 30, 2025 13:12
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.

Yoast SEO Removes Blocks with Block Recovery on Save
2 participants