Skip to content

Enhance Content Summary block detection to nested blocks#810

Open
Intenzi wants to merge 10 commits into
WordPress:developfrom
Intenzi:feat/summarization-nested-regeneration
Open

Enhance Content Summary block detection to nested blocks#810
Intenzi wants to merge 10 commits into
WordPress:developfrom
Intenzi:feat/summarization-nested-regeneration

Conversation

@Intenzi

@Intenzi Intenzi commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

What?

Closes #809

Enhances the Content Summarization experiment to detect Content Summary block inside nested-level blocks.

Why?

It solves the problem of new Content Summary block insertion when we want to regenerate the content summary if existing one is moved inside a nested block level such as inside a Group/Column block.
This PR ensures that the existing Content Summary block is found and edited instead.

How?

The fix is performed by implementing a recursive function named findSummaryBlock.

  • Recursively performs Depth First Search to identify the Content Summary block's existence.

This function replaces the existing search logic for the Content Summary block.

  • Implemented E2E test validating the same.

Additionally fixed a performance issue of the useSelect hook re-evaluating and running on every single render due to missing dependancy array. This was fixed by adding [] as empty dependancy array.

Use of AI Tools

AI assistance: Yes
Tool(s): Antigravity IDE
Model(s): Gemini 3.5 Flash (Low)
Used for: Identifying relevant code file, deciding on implementation for enhancement. E2E test was implemented via it. The performance fix was detected by the model. Final implementation and tests were reviewed and edited by me.

Testing Instructions

  • Enable Content Summarization Experiment.
  • Create a new post with minimum required content for the button to enable.
  • Click the Generate Summary button present inside the Post sidebar.
  • Create a Group/Column block and place the generated Content Summary group block inside it.
  • Identify that the button still states Regenerate Summary - (inside both Post sidebar and selected Block hovering menu bar)
  • Click Regenerate Summary.
  • Identify that the existing Content Summary group block has been modified instead of inserting a new block.

Screenshots or screencast

Visual Cues:
image

Manual Testing Video (from the step of Regenerate Summary click):

Enhancement.Complete.-.Content.Summarization.mov

Changelog Entry

Changed - Content Summary block detection from top-level only to checking nested blocks as well.

Open WordPress Playground Preview

@github-actions

github-actions Bot commented Jul 1, 2026

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: Intenzi <intenzi@git.wordpress.org>
Co-authored-by: yogeshbhutkar <yogeshbhutkar@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@Intenzi Intenzi changed the title Feat/summarization nested regeneration Enhance Content Summary block detection to nested blocks Jul 1, 2026
@codecov

codecov Bot commented Jul 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 75.50%. Comparing base (30fc728) to head (3309fa2).

Additional details and impacted files
@@            Coverage Diff             @@
##             develop     #810   +/-   ##
==========================================
  Coverage      75.50%   75.50%           
  Complexity      2086     2086           
==========================================
  Files             99       99           
  Lines           8626     8626           
==========================================
  Hits            6513     6513           
  Misses          2113     2113           
Flag Coverage Δ
unit 75.50% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Intenzi

Intenzi commented Jul 1, 2026

Copy link
Copy Markdown
Contributor Author

Raised #811 to increase gh action run timeout which was causing the E2E test job to cancel mid-run.

block.name === 'core/group' &&
block.attributes[ 'aiGeneratedSummary' ] === true // eslint-disable-line dot-notation
);
const summaryGroup = findSummaryBlock( allBlocks );

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.

We could instead use flattenBlocks here.

Ref:

ai/src/utils/blocks.ts

Lines 91 to 101 in 203cb1d

export function flattenBlocks< T extends BlockWithContent >(
blocks: T[]
): T[] {
return blocks.reduce< T[] >( ( acc, block ) => {
acc.push( block );
if ( block.innerBlocks?.length ) {
acc.push( ...flattenBlocks( block.innerBlocks as T[] ) );
}
return acc;
}, [] );
}

@Intenzi Intenzi requested a review from yogeshbhutkar July 1, 2026 13:24
* @param {any[]} blocks List of blocks to search.
* @return {any|null} The found block or null.
*/
function findSummaryBlock( blocks: any[] ): any {

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.

I believe we could narrow the types further.

Suggested change
function findSummaryBlock( blocks: any[] ): any {
import type { Block } from '@wordpress/blocks';
function findSummaryBlock( blocks: Block[] ): Block | undefined

flattenBlocks( blocks ).find(
( block ) =>
'core/group' === block.name &&
true === block.attributes[ 'aiGeneratedSummary' ] // eslint-disable-line dot-notation

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.

Yoda-style comparison is technically (IMO) unnecessary in JS/TS-World. I believe we should keep this consistent with other segments of the JS/TS codebase.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes that makes sense, I'll align the coding style to the codebase and follow the same.

Comment on lines +300 to +306
// Wait for the generation to complete (button changes from "Generating..." back to "Regenerate Summary").
await expect(
page.getByRole( 'button', {
name: 'Generating…',
exact: true,
} )
).not.toBeVisible();

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.

This negative assertion can pass even if the UI never reaches that state.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I have refactored the logic to now wait on the Content Summary block's content to change after button click. Thus I have now removed that assertion.

@Intenzi Intenzi requested a review from a team July 1, 2026 16:36
// Create a new post containing a nested summary block inside columns, with enough content.
const nestedContent =
// Content
'<!-- wp:paragraph -->' +

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.

Nit: We could use editor.insertBlock with innerBlocks here. This should make it easy to accomodate in case the block metadata/markup contract changes upstream in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enhancement/Fix: Content Summarization block to be found inside nested blocks

2 participants