Skip to content

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

Merged
mhkuu merged 4 commits intotrunkfrom
21947-yoast-seo-removes-blocks-with-block-recovery-on-save
Feb 5, 2025
Merged

Clone the blocks array first before filtering out the invalid blocks and add block length information#22006
mhkuu merged 4 commits intotrunkfrom
21947-yoast-seo-removes-blocks-with-block-recovery-on-save

Conversation

@FAMarfuaty
Copy link
Copy Markdown
Contributor

@FAMarfuaty FAMarfuaty commented Jan 30, 2025

Context

  • We want to fix a bug where the Yoast SEO analysis removes invalid blocks that display the "Attempt recovery" message.

Summary

This PR can be summarized in the following changelog entry:

  • Fixes a bug where invalid inner blocks would be removed when saving a post in the block editor.

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
Copy Markdown

coveralls commented Jan 30, 2025

Pull Request Test Coverage Report for Build 2f46b90a1435d4aeb0bcd06cb9a2c76c4a2564a5

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

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

Files with Coverage Reduction New Missed Lines %
packages/js/src/integrations-page/recommended-integrations.js 3 0.0%
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
Copy link
Copy Markdown
Contributor

@mhkuu mhkuu left a comment

Choose a reason for hiding this comment

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

CR/ACC: Nice, I can confirm the code works as expected! 🎉

Great that you added a unit test as well 🙌 However, note that the test would pass in the currently shipped version as well (as the invalid block is added on the top level). See the suggestion below for a test that would actually test the new behaviour (for a block added on the child level), you can confirm it fails without the newly added line.

I also made the changelog a bit more clear.

Comment thread packages/js/tests/collectAnalysisData.test.js Outdated
Co-authored-by: Martijn van der Klis <martijnvanderklis@yoast.com>
Comment thread packages/js/tests/collectAnalysisData.test.js
@mhkuu mhkuu force-pushed the 21947-yoast-seo-removes-blocks-with-block-recovery-on-save branch from c6803aa to 0aac3dc Compare February 5, 2025 08:56
@mhkuu mhkuu added this to the 24.6 milestone Feb 5, 2025
@mhkuu mhkuu merged commit 6432da1 into trunk Feb 5, 2025
@mhkuu mhkuu deleted the 21947-yoast-seo-removes-blocks-with-block-recovery-on-save branch February 5, 2025 09:33
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

3 participants