Enhance Content Summary block detection to nested blocks#810
Conversation
|
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 If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Codecov Report✅ All modified and coverable lines are covered by tests. 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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
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 ); |
There was a problem hiding this comment.
… Content Summary block
| * @param {any[]} blocks List of blocks to search. | ||
| * @return {any|null} The found block or null. | ||
| */ | ||
| function findSummaryBlock( blocks: any[] ): any { |
There was a problem hiding this comment.
I believe we could narrow the types further.
| 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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Yes that makes sense, I'll align the coding style to the codebase and follow the same.
| // 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(); |
There was a problem hiding this comment.
This negative assertion can pass even if the UI never reaches that state.
There was a problem hiding this comment.
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.
| // Create a new post containing a nested summary block inside columns, with enough content. | ||
| const nestedContent = | ||
| // Content | ||
| '<!-- wp:paragraph -->' + |
There was a problem hiding this comment.
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.
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.This function replaces the existing search logic for the Content Summary block.
Additionally fixed a performance issue of the
useSelecthook 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
Screenshots or screencast
Visual Cues:

Manual Testing Video (from the step of Regenerate Summary click):
Enhancement.Complete.-.Content.Summarization.mov
Changelog Entry