Skip to content

Commit

Permalink
Also update readability analysis if the list of blocks change, includ…
Browse files Browse the repository at this point in the history
…ing their client IDs
  • Loading branch information
FAMarfuaty committed Jan 7, 2025
1 parent ab89463 commit 25f56a1
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 25f56a1

Please sign in to comment.