Skip to content

Fixes inconsistent filtering of the paper's text in the Subheading distribution assessment#22882

Merged
marinakoleva merged 3 commits intotrunkfrom
1-table-of-content-assessment-is-broken-with-long-text-and-toc-block
Jan 21, 2026
Merged

Fixes inconsistent filtering of the paper's text in the Subheading distribution assessment#22882
marinakoleva merged 3 commits intotrunkfrom
1-table-of-content-assessment-is-broken-with-long-text-and-toc-block

Conversation

@marinakoleva
Copy link
Copy Markdown
Contributor

@marinakoleva marinakoleva commented Jan 13, 2026

Context

Summary

This PR can be summarized in the following changelog entry:

  • Fixes a bug where the subheading distribution assessment threw an error when the content contained text without subheadings followed by a block that included a subheading (such as a Table of Contents block).
  • [yoastseo] Fixes inconsistent filtering of the paper's text in the Subheading distribution assessment.
  • [shopify-seo] Fixes a bug where the subheading distribution assessment threw an error when there was some text with no headings plus a blockquote containing a heading.

Relevant technical choices:

  • The error was caused by a mismatch in how subheadings are detected vs. analyzed: hasSubheadings() checked for subheadings on the raw text (without filtering blocks), while getResult filtered blocks before analyzing the subheadings.
  • Removing shortcodes in hasSubheadings() is a bit overkill, as it would be necessary only in the scenario where the user has shortcodes with headings inside them. Still, decided to have this step here as well so that the filtering for hasSubheadings() and getSubheadingTextLengths is identical.

Test instructions

Test instructions for the acceptance test before the PR gets merged

This PR can be acceptance tested by following these steps:

Bug replication: WP

  • Install and activate the latest released Yoast SEO Free and Premium
    • For developers: you can build the main branches or trunk
  • Create a post with some content (you can use this text without the title) but with no subheadings
  • Add the Yoast Table of contents block
  • Confirm you can see the error An error occurred in the 'subheadingsTooLong' assessment in the Readability analysis tab and that you can't see a feedback string for the Subheading distribution assessment
  • Confirm you can see a console error Cannot read properties of undefined (reading 'countLength')
  • Save the post

Testing fix: WP

  • For QA: install the latest RC version of Free and Premium
  • For developers: build the Free branch of this PR, and require it for Premium before you build the Premium trunk using the command composer require yoast/wordpress-seo:dev-1-table-of-content-assessment-is-broken-with-long-text-and-toc-block@dev
  • Open the same post
  • Confirm there's no error in the console
  • Confirm there's no error in the Readability analysis tab
  • Confirm you can see the feedback string for the Subheading distribution assessment: You are not using any subheadings, although your text is rather long. Try and add some subheadings. with a red 🔴 traffic light.
  • Add a quote block which includes a heading and a paragraph with a few words.
  • Confirm you can still see the same feedback string for the Subheading distribution assessment as above.

Testing fix: Shopify

  • Create a product with this text, but without the title
  • Add a blockquote somewhere which includes a heading and a paragraph text
  • Save the product and open it in the Yoast editor
  • Confirm you can't see the following error in the Readability analysis tab: An error occurred in the 'subheadingsTooLong' assessment
  • Confirm you can see the feedback string for the Subheading distribution assessment: You are not using any subheadings, although your text is rather long. Try and add some subheadings. with a red 🔴 traffic light.

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:

  • N/a

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.
  • This PR also affects Yoast SEO for Google Docs. I have added a changelog entry starting with [yoast-doc-extension], added test instructions for Yoast SEO for Google Docs and attached the Google Docs Add-on 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.
  • I have run grunt build:images and commited the results, if my PR introduces new images or SVGs.

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

@coveralls
Copy link
Copy Markdown

coveralls commented Jan 13, 2026

Pull Request Test Coverage Report for Build 528b5e401b5adaa0b856ef519fe28292db5e819e

Details

  • 4 of 4 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.003%) to 53.339%

Totals Coverage Status
Change from base Build 2a603d77962027f9876cfa6cfbedc93abd794cd7: 0.003%
Covered Lines: 32904
Relevant Lines: 61882

💛 - Coveralls

@marinakoleva marinakoleva added the changelog: bugfix Needs to be included in the 'Bugfixes' category in the changelog label Jan 13, 2026
@marinakoleva marinakoleva marked this pull request as ready for review January 13, 2026 12:02
marinakoleva and others added 2 commits January 13, 2026 13:03
…-table-of-content-assessment-is-broken-with-long-text-and-toc-block
…f-content-assessment-is-broken-with-long-text-and-toc-block
@agnieszkaszuba
Copy link
Copy Markdown
Contributor

CR: 👍 We could improve the getResult method so that we check if there are subheadings sooner, and don't do things that presuppose that there are subheadings (like getting subheadings lengths) if there aren't any. But that's beyond the scope of this issue and would require testing the whole assessment.

@agnieszkaszuba agnieszkaszuba added the Shopify This PR impacts Shopify. label Jan 20, 2026
@agnieszkaszuba
Copy link
Copy Markdown
Contributor

Acceptance (in WP): 👍

@marinakoleva marinakoleva added this to the 27.0 milestone Jan 21, 2026
@marinakoleva marinakoleva merged commit 52a2952 into trunk Jan 21, 2026
24 checks passed
@marinakoleva marinakoleva deleted the 1-table-of-content-assessment-is-broken-with-long-text-and-toc-block branch January 21, 2026 10:25
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 Shopify This PR impacts Shopify.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants