From 25f56a1e22d352baa8cd07a88687f7651b8f815e Mon Sep 17 00:00:00 2001 From: aidamarfuaty Date: Tue, 7 Jan 2025 15:06:16 +0100 Subject: [PATCH] Also update readability analysis if the list of blocks change, including their client IDs --- .../yoastseo/spec/worker/AnalysisWebWorkerSpec.js | 13 +++++++++++++ packages/yoastseo/src/worker/AnalysisWebWorker.js | 8 +++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/packages/yoastseo/spec/worker/AnalysisWebWorkerSpec.js b/packages/yoastseo/spec/worker/AnalysisWebWorkerSpec.js index 964d4d83977..e648398747c 100644 --- a/packages/yoastseo/spec/worker/AnalysisWebWorkerSpec.js +++ b/packages/yoastseo/spec/worker/AnalysisWebWorkerSpec.js @@ -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", () => { diff --git a/packages/yoastseo/src/worker/AnalysisWebWorker.js b/packages/yoastseo/src/worker/AnalysisWebWorker.js index 42efb800333..3c33e46680c 100644 --- a/packages/yoastseo/src/worker/AnalysisWebWorker.js +++ b/packages/yoastseo/src/worker/AnalysisWebWorker.js @@ -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. @@ -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(); }