CE-WP-0008: fix capture field values and viewport scroll retry

- Wire fieldValues state in FormsApp so controlled inputs persist typed data
- Add runScrollToHighlightJob with rAF retries when utils/highlights not ready
- Re-trigger scroll when highlights update after PDF load
- Tests: scroll-job unit test, forms-field-values integration tests
- Workplan CE-WP-0008 marked done
This commit is contained in:
2026-06-08 01:07:52 +02:00
parent fc6b91ccb0
commit 305a20d1d1
7 changed files with 384 additions and 17 deletions

View File

@@ -0,0 +1,120 @@
---
id: CE-WP-0008
type: workplan
title: "Capture content editing & viewport scroll reliability"
domain: citation_evidence
repo: citation-evidence
repo_id: a677c189-b4e2-4f2a-9e48-faa482c277e6
topic_slug: citation_evidence_mvp
topic_id: 96fa8e80-9f74-40f2-84cd-644e9747b9ec
status: done
owner: Bernd
created: 2026-06-08
updated: 2026-06-08
depends_on_workplan: CE-WP-0007
planning_order: 8
planning_priority: high
spec_refs:
- wiki/ProductRequirementsDocument.md
- workplans/CE-WP-0007-capture-view-polish.md
---
# CE-WP-0008 — Capture Content Editing & Viewport Scroll
Follow-on fixes from manual Capture-mode demo use after CE-WP-0007.
## User requirements (locked)
1. **Field values persist while typing** — text, textarea, and date inputs must
keep user-entered content; re-renders must not reset controlled inputs.
2. **Date fields hold their value** — picking a date must not snap back to empty
or a stale display value on blur or parent re-render.
3. **Viewport scroll reaches off-page evidence** — selecting evidence whose
passage is not on page 1 must scroll the PDF viewer to that passage (not leave
the viewport at the document top). CE-WP-0007 T01 regressed or was incomplete
when `PdfHighlighter` utils or highlight DOM were not ready on the first
scroll request.
## Dependency order
```
T01 (field value state) ── T02 (viewport scroll retry)
└─ T03 (integration tests)
```
---
## T01 — Wire form field value state in FormsApp
```task
id: CE-WP-0008-T01
priority: critical
status: done
```
**Problem:** `FormRenderer` renders controlled inputs (`value={… ?? ""}`) but
`FormsApp` never passes `values` / `onValueChange`. Every React re-render resets
typed content; date inputs snap back immediately.
**Fix:**
- Hold `fieldValues: Record<string, string>` in `FormsApp`.
- Pass `values` and `onValueChange` through `FormPane``FormRenderer`.
- Preserve values when field label/type is edited (stable field `id`).
**Acceptance:** type in Summary, switch focus to another field, return — text
remains. Set a date — value persists after blur.
---
## T02 — Retry scroll until viewer utils and highlight are ready
```task
id: CE-WP-0008-T02
priority: critical
status: done
depends_on: [T01]
```
**Problem:** `PdfSpikeViewer`'s scroll `useEffect` bails when `utilsRef` or the
target highlight is missing, and never retries because effect deps do not change.
Evidence on page 2+ appears to leave the viewport at the document top.
**Fix:**
- Extract `runScrollToHighlightJob` with rAF retries (same pattern as
`centerHighlightInViewer`).
- Re-run pending scroll when `highlights` updates (annotations rendered after PDF
load).
- Keep `lastScrollKeyRef` guard so successful scrolls are not duplicated.
**Acceptance:** click strip evidence tied to a page-2+ passage — viewer receives
`scrollToAnnotationId` and scroll completes once utils are available.
---
## T03 — Integration tests
```task
id: CE-WP-0008-T03
priority: high
status: done
depends_on: [T01, T02]
```
Happy-dom tests:
- Type text and date in capture fields; refocus; values persist.
- Unit test for scroll job retry when utils arrive late.
**Acceptance:** `npm run test` green.
---
## Acceptance for the workplan
After CE-WP-0008:
1. Capture form fields retain typed values across re-renders and focus changes.
2. Date inputs keep the selected date after blur.
3. Evidence selection scrolls to off-page passages instead of staying at the top.

View File

@@ -3,6 +3,7 @@
MVP workplans for the citation-evidence umbrella repo. CE-WP-0001..0006
delivered the PRD §20 reference scenario and Forms/Review UX polish.
CE-WP-0007 delivered Capture-view polish including field add/edit UX.
CE-WP-0008 fixes capture field value persistence and viewport scroll reliability.
| Workplan | Title | Status |
|----------|----------------------------------------|--------|
@@ -13,14 +14,15 @@ CE-WP-0007 delivered Capture-view polish including field add/edit UX.
| `CE-WP-0005` | Demo sessions — uploads, named sessions, ZIP export/import | done |
| `CE-WP-0006` | Forms & review UX refinements — blob fix, scroll centre, linking | done |
| `CE-WP-0007` | Capture view polish — scroll, linking, layout, rename, field UX | done |
| `CE-WP-0008` | Capture content editing & viewport scroll reliability | done |
## Order
CE-WP-0001..0004 are strictly sequential. CE-WP-0005 depends on 0004.
CE-WP-0006 depends on 0005. CE-WP-0007 depends on 0006:
CE-WP-0006 depends on 0005. CE-WP-0007 depends on 0006. CE-WP-0008 depends on 0007:
```
/ralph-workplan workplans/CE-WP-0007-capture-view-polish.md
/ralph-workplan workplans/CE-WP-0008-capture-content-editing.md
```
## How to run a workplan