5.9 KiB
Manuscript Reader — live updates and persistent Focus Reading
This extends Phase 1 without changing the accepted manuscript store, Word Companion, reconciliation, installers, SQL schema or Maps.
Change detection and server overhead
An authenticated GET to /manuscript/reader/changes checks immediately on opening a selected chapter and every 12 seconds while visible. It carries book/chapter IDs, the last observed accepted book revision and chapter fingerprint. Existing ParagraphManuscript status, Book_Get and Chapter_Get stored procedures enforce book access and validate the active chapter. Stable polls perform three small stored-procedure reads and transfer only a small JSON response; they do not retrieve paragraph JSON or prose.
When the accepted book revision differs, the service uses the existing read-only projection to compute a SHA-256 fingerprint over the selected chapter's ordered paragraph GUIDs, exact text and heading flags, with length-delimited encoding. The returned revision is the revision of the snapshot actually read. A preference revision, unchanged successful synchronisation or another chapter's update does not replace the selected chapter when its fingerprint is unchanged. Pending/rejected submissions never enter the committed source.
Only a changed chapter fingerprint causes the browser to GET /manuscript/reader/chapter, which returns that chapter's JSON paragraphs and accurately sourced timestamps. Both new GET endpoints retain authentication, access checks, no-store responses, safe generic errors and no-index headers. Browser rendering uses textContent, never manuscript HTML insertion. Revisions travel as decimal strings to avoid JavaScript integer precision loss.
The existing storage API still reads/deserialises the book aggregate on the server to calculate a chapter fingerprint after a revision change and to retrieve a changed chapter. This happens on candidate changes, not every polling interval; a genuine selected-chapter change can therefore cause two aggregate reads. There is no new SQL projection, persistent cache, database object or browser book preload. The normal metadata-only path is approximately 15 small stored-procedure calls per minute per visible Reader tab. No polling occurs while hidden.
Reading session behaviour
Updates preserve a visible paragraph GUID and its vertical screen offset, using nearby surviving GUIDs or exact paragraph text when needed. Scroll restoration is instantaneous (including under themes that enable smooth scrolling). Replacements retain Focus Reading. If no usable anchor survives, the page offers an explicit update instead of forcibly resetting the reading session.
A non-collapsed browser selection defers both full chapter retrieval and DOM replacement. Metadata checks can continue tracking the newest accepted version, but the page does not repeatedly fetch or replace the deferred chapter. Clearing the selection fetches the latest accepted chapter. A second selection/pause check after the full fetch protects selections made while that request was running.
Pause automatic updates while listening retains the current text and offers Show updated chapter. The latter is an explicit user action and may clear selection to display the pending chapter. No proprietary text-to-speech API or reliable extension-playback detection exists. Extensions without a browser selection should use the pause control; interruption-free third-party playback cannot be guaranteed during an automatic replacement.
There is one serial polling loop. Hidden pages suspend polling and abort outstanding requests, visible/online pages check promptly, transient errors retain prose and retry, and access/authentication failures stop polling with an unobtrusive message. Requests are cancelled/ignored on navigation. Reinitialisation disposes the old timer and listeners. Browsers restoring a Reader from the back/forward cache rearm its loop.
Focus Reading navigation
Focus Reading is a Reader viewing preference carried by the Reader URL (focus=true), chapter links and chapter form. The server renders the focused state, and CSS applies it before the deferred script executes. Next, Previous, the chapter selector and Reader refresh links preserve it. Explicit exit/Escape removes it; navigating away does not apply focus to other workspaces. No manuscript state or browser prose storage is involved.
Each newly navigated chapter starts at its beginning; automatic updates within the same chapter preserve position. Normal navigation and first/last chapter boundaries are unchanged.
Verification
- Application build, full executable regression harness and the original 24-combination Reader browser suite.
- Focused service tests cover initial/stable metadata-only checks, genuine accepted content, unchanged successful synchronisation, another chapter's update, pending/rejected isolation, chapter/account access and timestamp provenance.
PlotLine.Tests/Browser/manuscript-reader-live.cjscovers actual controller/cache/access boundaries plus simulated accepted updates: no page reload, normal/focused paragraph anchors, deferred/latest version while selected, listening pause/manual action, hidden/visible lifecycle, offline/recovery, reinitialisation/single loop, in-flight navigation, Next/Previous/dropdown focus persistence, top-of-new-chapter and first/last boundaries. It runs desktop/mobile, ordinary browser/simulated PWA, with all four themes checked. It does not write a database or drive real Word.
Example browser invocation against the isolated fixture host:
PD_BROWSER_FIXTURE_URL=http://127.0.0.1:5249 node PlotLine.Tests/Browser/manuscript-reader-live.cjs
The author reports Word-to-server acceptance and manual-refresh Reader visibility were verified before this task. This task's synchronisation-change browser fixtures are simulations, not evidence of another real Word run. Actual installed Windows PWA and text-to-speech extension playback must be qualified on Windows.