Skip to content

Commit

Permalink
Merge pull request #21953 from Yoast/496-ai-optimize-make-highlightin…
Browse files Browse the repository at this point in the history
…g-and-ai-button-work-for-sentence-length-assessment-after-ai-suggestion-is-applied

Updates the readability analysis when the client IDs of the blocks change
  • Loading branch information
Jordi-PV authored Jan 8, 2025
2 parents ab89463 + 25f56a1 commit 975bf4c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
13 changes: 13 additions & 0 deletions packages/yoastseo/spec/worker/AnalysisWebWorkerSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1792,6 +1792,19 @@ describe( "AnalysisWebWorker", () => {
worker._paper = new Paper( "This is the content.", { keyword: "dogs" } );
expect( worker.shouldReadabilityUpdate( paper ) ).toBe( true );
} );

test( "returns true when the client IDs of the blocks inside attributes changes", () => {
const paper = new Paper( "This is the content.", { wpBlocks: [
{ name: "block1", clientId: "1234" },
{ name: "block2", clientId: "5678" },
] } );

worker._paper = new Paper( "This is the content.", { wpBlocks: [
{ name: "block1", clientId: "6783" },
{ name: "block2", clientId: "0636" },
] } );
expect( worker.shouldReadabilityUpdate( paper ) ).toBe( true );
} );
} );

describe( "shouldSeoUpdate", () => {
Expand Down
8 changes: 7 additions & 1 deletion packages/yoastseo/src/worker/AnalysisWebWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// External dependencies.
import { enableFeatures } from "@yoast/feature-flag";
import { __, setLocaleData, sprintf } from "@wordpress/i18n";
import { forEach, has, includes, isEmpty, isNull, isObject, isString, isUndefined, merge, pickBy } from "lodash";
import { forEach, has, includes, isEmpty, isEqual, isNull, isObject, isString, isUndefined, merge, pickBy } from "lodash";
import { getLogger } from "loglevel";

// Internal dependencies.
Expand Down Expand Up @@ -954,6 +954,12 @@ export default class AnalysisWebWorker {
return true;
}

// Perform deep comparison between the list of Gutenberg blocks as we want to update the readability analysis
// if the client IDs of the blocks inside `wpBlocks` change.
if ( ! isEqual( this._paper._attributes.wpBlocks, paper._attributes.wpBlocks ) ) {
return true;
}

return this._paper.getLocale() !== paper.getLocale();
}

Expand Down

0 comments on commit 975bf4c

Please sign in to comment.