Repository navigation
fix(audit): read a page's readability as the editor's Quality does, with one Flesch band (#1411 follow-up) - #1442
Conversation
…ith one Flesch band (ansvisor#1411 follow-up) Site Audit and the Content Editor gave the same page different Flesch scores (a 240-word page read 73 in the editor and 66 in the audit): - the audit's readability signal now reads the page's main content (extractPageContent, as the editor's URL import) with a server mirror of the editor's blocks, sentences and syllables (signals/readability.js); menus and footers no longer count, text loose in a div is a paragraph, and a page with too few words of its own has no score - one band in both places, the rubric's: 50–70 passes (full points in the editor), 30–50 and 70–80 warn (half), past them fails (none), read on the score as it shows - the editor's detail and the audit's how-to-fix and recommendation say which way to go: under 50 shorter, over 70 fuller - one fixture page reads Flesch 82 in both tests Co-Authored-By: Claude Opus 5.5 <[email protected]>
gkhngyk
left a comment
There was a problem hiding this comment.
Looks good. Three follow-ups below, none of them blocking.
The band is still an open product call: 50–70, and fewer reading-level points above 70 for plain English pages. This review covers the code only.
-
(low) The audit and the editor still read two kinds of page differently.
- Text with no tag of its own. This is text that sits straight in
<main>or<article>, for example spans with<br>between them.readingBlocks(server/src/lib/audit/signals/readability.js:74-90) reads only text inside one of the tags it lists, so the audit returns "not enough text".- The editor wraps the same text in a paragraph and scores it. My page reads 82 there.
- Fix: also read the text runs at the top level of the content, one block per run between blocks.
- Page-builder text in minified HTML. When the HTML has no whitespace between blocks, the editor's import joins neighbouring blocks:
cleanHtml(DOMPurify) dropsdiv,figcaption,ddanddtbut keeps their text, so the texts run together: "…shake it level.Start with a short pour…", "…fresh beans.BloomFresh coffee…".- The editor then counts one sentence where the audit counts two.
- Results, editor against audit:
- the fixture with every
<p>turned into a<div>and minified: 80 against 82; - a page of six page-builder text blocks: 73 against 82;
- a page with a figure caption and a definition list: 75 against 86.
- the fixture with every
- The audit's reading is the right one, and the joined words also show in the imported draft.
- Fix on the editor side: in
cleanHtml, turn those tags into<p>before purifying, or at least add a space. This can be its own PR.
- Text with no tag of its own. This is text that sits straight in
-
(low) The main-content read is slow on large pages.
extractPageContentnow runs on every audit, synchronously, in the API process.judge→textOf(server/src/lib/page-content.js:176,:365) reads each element's whole subtree at every levelstripgoes down. So the time grows faster than the page does.- On a product grid, all under the 2 MB cap:
- 0.4 s at 0.39 MB;
- 2.9 s at 1.17 MB;
- 6.5 s at 1.69 MB.
- A 0.94 MB long article takes 1.3 s. The old signal took 0.15 s on the same page.
- Typical pages stay well under a second: a 48-product category page took 0.23 s.
- Fix: compute each element's text length once, bottom-up, and have
judgeread it. That speeds up the URL import too. LoweringMAX_READ_HTML(signals/content.js:18) would also cap the cost.
-
(low) The two comments in
web/src/lib/content/readability.test.ts:23and:79say the fixture is shared withsignals/readability.test.js. It is inserver/src/lib/audit/audit.test.js.
Note on existing audits. Re-audits will change many readability results, mostly upward:
- The old counter found a sentence end only where a space followed the full stop.
- A page whose HTML has no space between blocks therefore read as a few very long sentences. That often gave a negative score and a fail.
- Those pages are now read properly.
- When a fail becomes a pass, the page's total rises by about 2 points, since Content has about 11 evaluated signals.
- The overview's change from the previous audit and the "Improving" status will show that rise even when the page didn't change. That's worth a line in the changelog.
Checked
-
One reading on both sides. I ran 401 random pages in the editor's own HTML through both counters. The pages covered:
- headings;
- lists with nested lists and paragraphs;
- quotes and tables;
- line breaks, abbreviations and closing quotes.
The server and the editor gave the same rounded Flesch and the same band on every page. The fixture reads 82 through the full import path as well.
-
Rubric version, signal count, docs and
en.json: nothing to update.- The signal count stays 48.
rubric_versionis stored with each audit, but nothing reads it. It also stayed v1.1 through #1424.- The Site Audit guide doesn't state the band.
- The rubric's copy reaches the UI from
rubric.json. - Both new editor strings are in
en.json. The olddetailstring is still used for German, French, Spanish and Turkish.
-
Merge state: merges cleanly on current main, including #1444's change to
readability.ts. No migration. CI is green.
ansvisor#1433 is on main (squash-merged), with ansvisor#1429–ansvisor#1436 and ansvisor#1442/ansvisor#1444; this branch's own change (Send to CMS part 2) is applied on top. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…library ansvisor#1438's branch now has main (ansvisor#1429–ansvisor#1436, ansvisor#1442, ansvisor#1444); this branch's own changes (Send to CMS part 3a) are applied on top. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…-bulk ansvisor#1439's branch now has main (ansvisor#1429–ansvisor#1436, ansvisor#1442, ansvisor#1444); this branch's own change (Send to CMS part 3b) is applied on top. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Summary
Follow-up to #1411, review item 4: Site Audit and the Content Editor gave the same page different Flesch scores. The cause was three differences: syllables, sentences and the band. This needs to land before
NEXT_PUBLIC_CONTENT_QUALITY_PHASEis turned on.One reading
server/src/lib/audit/signals/readability.jsis a JS mirror of the editor's English reading inweb/src/lib/content/readability.ts. It is marked "Mirrors… keep the two in step", as other mirrored modules are. It covers:readabilitysignal now reads the page's main content throughextractPageContent, the same extraction the editor's URL import uses, instead of the whole body.na("not enough text") rather than a score made of menu items.div,section,figcaptionordd/dtcounts as a paragraph, as the editor's import makes it one.server/src/lib/audit/audit.test.jsandweb/src/lib/content/readability.test.ts.One band: the rubric's
rubric.jsonalready documents the audit's band ("50–70 for general audiences; sub-30 academic and 80+ childlike both underperform"). I kept it and moved the editor onto it. Both sides apply it to the score as it shows, rounded:The advice now says which way to go:
howToFix;@gkhngyk, please confirm the band.
FLESCH_BAND) plus the rubric line.Effect on prod
Related issue
Follow-up to #1411 (review item 4).
Type of change
feat— New featurefix— Bug fixchore— Maintenance / dependenciesdocs— Documentation onlyrefactor— Code change that neither fixes a bug nor adds a featuretest— Adding or updating testsHow to test
cd server && npx vitest run src/lib/audit/. The fixture reads 82 throughfleschReadingEaseand through the signal with a nav and footer around it. A page with little text of its own givesna, div text is read, and a page over 2 MB isn't read.cd web && npx vitest run src/lib/content/readability.test.ts. The same fixture reads 82, and the band tests check full, half and none on both sides of 50–70.NEXT_PUBLIC_CONTENT_QUALITY_PHASE=1, paste the fixture (in either test file) into a draft. Instructions › Quality shows "Reading level 82 (Flesch Reading Ease) · Aim for 50–70: the page reads simpler…".I checked step 3 locally at 1024px, in light and dark, with a temporary draft that I deleted afterwards.
Checklist
feature/,fix/,chore/,docs/) — see CONTRIBUTING.mdyarn lintpasses (run fromweb/): 0 errors, 6 existing warnings in files this PR doesn't touchyarn typecheckpasses (run fromweb/)yarn format:checkpasses (run fromweb/)Also run:
npm run format,npm run lintandnpm test(191 files / 2316 tests);yarn test(362 / 3283) andyarn buildwith CI's placeholder env.🤖 Generated with Claude Code