Show the read-time chip only once the visible text is measured - #24
Merged
Conversation
The bar used to paint a server-side estimate over the whole stored HTML and then swap in the overlay's visible-text number, so a doc with hidden tab panels showed a figure we already knew was wrong. There is now no server estimate: the overlay posts word/CJK counts for the text it finds visible, the shell turns those into minutes, and no chip renders until that arrives. The overlay also stops reporting on the theme sample's early ticks — a count taken before a script-built tab UI hides its panels would put up a number that then has to be corrected. It reports once the doc has settled and once more later for a doc that rearranges itself very late. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
sjmiller609
marked this pull request as ready for review
July 31, 2026 15:55
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #23. The bar was painting a server-side estimate over the whole stored HTML and then swapping in the overlay's visible-text number — so a doc with hidden tab panels showed a figure we already knew was wrong, then corrected itself. Now nothing shows until the client has measured.
What changed
estimateReadMinutes(html)and its call inapp/d/[slug]/page.tsxare gone, along with thereadMinutesprop. Counting the stored HTML can only ever produce the number we didn't want.{type:"jh:readtime", words, cjk}instead of minutes. The rate, the rounding and the thresholds stay inlib/docs/reading-time.tsasreadMinutesFor(words, cjk), which the shell calls: one tested definition of the arithmetic instead of the constants being duplicated into the stringified overlay script.readMinutesstartsnull; a doc whose overlay never runs has no chip at all, and an image-only doc still reports 0 and stays chipless.24 minat 700ms,4 minat 1.5s). It now reports at 1.5s and again at 5s for a doc that rearranges itself very late; an unchanged count is a no-op for the shell.Trade-off: the chip appears about 1.5s in rather than immediately, and the other bar controls shift left when it does. That seemed the right side of "don't show a number we'd have to take back".
Testing
npm test— 170 passing. The estimator's HTML-scraping tests are replaced by tests forreadMinutesFor(wpm rounding, CJK rate, mixed docs, the zero case); thresholds and tooltip copy unchanged.npm run buildandtsc --noEmitclean.4 mingreen,9 minbeige,21 mincharcoal, a CSS-tabbed doc4 min, a script-tabbed doc that hides panels at 1s4 min, 4000 words in a closed<details>3 min, and an image-only doc still has no chip. No intermediate wrong number in any of them. Light and dark both checked.Note
Low Risk
Viewer chrome timing and display only; no auth, persistence, or API contract changes beyond the overlay postMessage shape paired with the shell update.
Overview
Stops showing a read-time chip from server HTML and waits for the sandbox overlay to measure visible prose only, so tab panels and other hidden content no longer produce a number that flashes wrong and then corrects.
The viewer page drops
estimateReadMinutesand thereadMinutesprop.CommentsShellkeepsreadMinutesasnulluntiljh:readtimearrives; zero or missing overlay means no chip. The overlay posts{words, cjk}instead of minutes;readMinutesForinlib/docs/reading-time.tsowns rates and rounding. Reporting moves off theme load/400ms ticks to 1.5s and 5s so late tab UIs can settle first. Tests targetreadMinutesForrather than HTML scraping.Reviewed by Cursor Bugbot for commit 82d9b45. Bugbot is set up for automated code reviews on this repo. Configure here.