Skip to content

fix(document-viewer): open document pages at the top - #1782

Merged
BigSimmo merged 9 commits into
mainfrom
cursor/fix-document-open-scroll-e5bf
Aug 9, 2026
Merged

fix(document-viewer): open document pages at the top#1782
BigSimmo merged 9 commits into
mainfrom
cursor/fix-document-open-scroll-e5bf

Conversation

@BigSimmo

@BigSimmo BigSimmo commented Aug 9, 2026

Copy link
Copy Markdown
Owner

Summary

  • Document opens with ?chunk= (every search/answer open) no longer auto-scroll the page to #pdf-preview-section.
  • Pages land at the top overview as usual; the PDF still targets the cited page inside its canvas, and explicit “Open PDF” / hash links still scroll on click.
  • Adds a DocumentViewer shell regression test that asserts mount does not scrollIntoView the PDF section when a chunk deep-link is present.
  • Synced with origin/main (f6b0fac2); only overlapping file was append-only docs/branch-review-ledger.md (auto-merged). No product-file conflicts.

Verification

  • Focused DOM proof: node scripts/run-vitest.mjs run tests/document-viewer-shell.dom.test.tsx7 passed (including new auto-scroll regression; re-run after main merge)
  • Citation landing panel still collapsed: node scripts/run-vitest.mjs run tests/document-section-summary.dom.test.tsx8 passed
  • npm run verify:pr-local -- --dry-run --files src/components/DocumentViewer.tsx,tests/document-viewer-shell.dom.test.tsx (selects full lint/typecheck/test/build; not re-run locally — focused DOM coverage is the changed failure class)
  • git merge origin/main clean; git merge-tree --write-tree origin/main HEAD exit 0
  • UI verification not run: phone-chrome / search-chrome files untouched; regression covered in jsdom via mocked scrollIntoView

Risk and rollout

  • Risk: Low — removes page-level mount scroll only; citation page/chunk targeting and user-initiated PDF jumps unchanged.
  • Rollback: Revert this commit.
  • Provider or production effects: None

Notes

  • Root cause was the citation-landing useEffect in DocumentViewer treating any activeChunkId as a reason to scroll to the PDF; search always attaches chunk.
Open in Web Open in Cursor 

Summary by CodeRabbit

  • Bug Fixes

    • Opening a document viewer with a cited chunk now keeps the page positioned at the top instead of automatically jumping to the PDF preview.
    • Cited chunks remain selected and configured as expected.
  • Tests

    • Added regression coverage to verify the document viewer’s initial position and citation behavior.

cursoragent and others added 2 commits August 9, 2026 10:26
Search and answer links always attach ?chunk=, and the citation-landing
effect scrolled #pdf-preview-section into view on every such open. Remove
that page-level auto-scroll so the overview stays first; the PDF still
targets the cited page inside its canvas.

Co-authored-by: BigSimmo <BigSimmo@users.noreply.github.com>
Co-authored-by: BigSimmo <BigSimmo@users.noreply.github.com>
@coderabbitai

coderabbitai Bot commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

You’ve reached a temporary PR review limit under our Fair Usage Limits Policy.

Your recent review volume is higher than typical usage, so adaptive limits are currently applied.

Next review available in: 55 minutes

Your organization has reached its usage spending cap. Adjust your spending cap in the billing tab.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 3d15c5b6-ac22-4cdd-bd07-6f5eb86bc998

📥 Commits

Reviewing files that changed from the base of the PR and between b6d59c8 and e049a71.

📒 Files selected for processing (9)
  • .claude/skills/handoff/SKILL.md
  • .githooks/pre-commit
  • docs/branch-review-ledger.md
  • docs/design-system/adoption-manifest.json
  • src/components/dsm/dsm-compare-remove-link.tsx
  • tests/docs-inventory.test.ts
  • tests/document-viewer-shell.dom.test.tsx
  • tests/dsm-compare-remove-link.dom.test.tsx
  • tests/ui-route-coverage.spec.ts
📝 Walkthrough

Walkthrough

DocumentViewer no longer scrolls to the PDF preview when a citation chunk becomes active. A regression test verifies that chunk deep-links preserve the page’s top position. The review ledger records the change and its verification.

Changes

Document viewer scroll behavior

Layer / File(s) Summary
Remove automatic citation scrolling
src/components/DocumentViewer.tsx, tests/document-viewer-shell.dom.test.tsx, docs/branch-review-ledger.md
DocumentViewer no longer calls scrollIntoView when an active chunk loads. The regression test verifies that a chunk deep-link does not scroll to #pdf-preview-section. The review ledger records the verification.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly summarizes the primary change: preventing document pages from auto-scrolling and opening them at the top.
Description check ✅ Passed The description covers the summary, verification evidence, risk, rollback, and production effects, but omits the required Clinical Governance Preflight section.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch cursor/fix-document-open-scroll-e5bf

Comment @coderabbitai help to get the list of available commands.

@supabase

supabase Bot commented Aug 9, 2026

Copy link
Copy Markdown

This pull request has been ignored for the connected project sjrfecxgysukkwxsowpy because there are no changes detected in supabase directory. You can change this behaviour in Project Integrations Settings ↗︎.


Preview Branches by Supabase.
Learn more about Supabase Branching ↗︎.

@github-actions

github-actions Bot commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

CI triage

CI failed on this PR. Automated classification of the 3 failed job(s):

  • Static PR checksneeds investigation: inspect the failing step and uploaded diagnostics; rerun only after classifying the cause.
  • Production UI (1)main-side: the same job also failed on the latest completed main CI run.
  • PR requiredmain-side: the same job also failed on the latest completed main CI run.

Compared with main CI run #9522 (failure).

Classification is evidence routing, not permission to ignore a failure. Exact quarantined Playwright identities remain governed by the flake ledger.

@BigSimmo
BigSimmo marked this pull request as ready for review August 9, 2026 10:58

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
tests/document-viewer-shell.dom.test.tsx (1)

188-202: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Prove that the deep link still targets the cited page.

chunk-1 uses page_number: 1, and DocumentViewer also mounts with initialPage={1}. If chunk selection or PDF page targeting regresses, this test can still pass because it only checks that page scrolling did not occur. Use a non-default cited page and assert the rendered selected chunk or PDF canvas target.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/document-viewer-shell.dom.test.tsx` around lines 188 - 202, Update the
test around DocumentViewer to use a non-default page_number and matching
deep-link configuration, then assert that the rendered selected chunk or PDF
canvas targets that cited page. Replace the current assertion that only verifies
scrolling did not occur, ensuring the test fails if chunk selection or PDF page
targeting regresses.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tests/document-viewer-shell.dom.test.tsx`:
- Around line 207-210: Replace the asynchronous waitFor negative assertion in
the document viewer test with a direct synchronous assertion after the existing
ready signals. Assert that scrolledIds does not contain "pdf-preview-section" at
that point, preserving the test’s existing setup and readiness flow.

---

Nitpick comments:
In `@tests/document-viewer-shell.dom.test.tsx`:
- Around line 188-202: Update the test around DocumentViewer to use a
non-default page_number and matching deep-link configuration, then assert that
the rendered selected chunk or PDF canvas targets that cited page. Replace the
current assertion that only verifies scrolling did not occur, ensuring the test
fails if chunk selection or PDF page targeting regresses.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: b1147d6f-c3c7-4861-8d12-1771e0cef9af

📥 Commits

Reviewing files that changed from the base of the PR and between ef9bb51 and b6d59c8.

📒 Files selected for processing (3)
  • docs/branch-review-ledger.md
  • src/components/DocumentViewer.tsx
  • tests/document-viewer-shell.dom.test.tsx
💤 Files with no reviewable changes (1)
  • src/components/DocumentViewer.tsx

Comment thread tests/document-viewer-shell.dom.test.tsx Outdated
…pen-scroll-e5bf

Co-authored-by: BigSimmo <BigSimmo@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Removes automatic PDF-section scrolling so cited document links open at the overview while preserving citation targeting.

Changes:

  • Removes chunk-triggered scrollIntoView.
  • Adds regression coverage for chunk deep links.
  • Records the review in the branch ledger.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
src/components/DocumentViewer.tsx Removes automatic PDF-section scrolling.
tests/document-viewer-shell.dom.test.tsx Tests overview-first citation landing.
docs/branch-review-ledger.md Adds the PR review record.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@BigSimmo
BigSimmo enabled auto-merge (squash) August 9, 2026 11:32
BigSimmo and others added 3 commits August 9, 2026 19:40
The new open-at-top DOM test associates Citation proof with
document-viewer-shell.dom.test.tsx; the committed adoption manifest
drifted and failed both static-pr and unit coverage. Sync the manifest,
harden the negative scroll assertion, and teach pre-commit/handoff to
regenerate adoption on the same input paths so the drift fails before CI.

Co-authored-by: BigSimmo <BigSimmo@users.noreply.github.com>
Co-authored-by: BigSimmo <BigSimmo@users.noreply.github.com>
@cursor

cursor Bot commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

PR #1782 unblock snapshot

Tip: f39df9ecea7bdf8297263590334096196beb43c4 on cursor/fix-document-open-scroll-e5bf
Sync / merge-tree: 0 behind origin/main, merge-tree clean, MERGEABLE (auto-merge already armed — left as-is)

What blocked

Required CI on prior tip f20fed97:

  • Static PR checksdocs/design-system/adoption-manifest.json is out of date
  • Unit coverage — same drift via tests/design-system-adoption.test.ts (committed manifest missing tests/document-viewer-shell.dom.test.tsx under Citation proof)
  • PR required — aggregate of the above

Root cause: the open-at-top DOM test newly associates Citation proof; the manifest was not regenerated after that test landed / after main syncs.

What I fixed

  1. Regenerated docs/design-system/adoption-manifest.json (npm run design-system:adoption:update)
  2. Hardened the negative scroll assertion (flush mount effects, then sync assert) — addresses the CodeRabbit waitFor race note; thread replied + resolved
  3. Prevention: pre-commit now runs design-system:adoption:update when src/app/, src/components/, tests/, or design-system adoption inputs are staged; handoff skill documents the same for Cloud agents that bypass hooks; tests/docs-inventory.test.ts guards the hook wiring

Pushed commits: 98029875 (fix) + f39df9ec (ledger)

Required CI status

Re-triggered on f39df9ec — in progress at comment time (Change scope / PR policy / mergeability / SAST queued or running). Prior Production UI was green on f20fed97; not re-proven locally (not needed for this drift fix).

Residual risks

  • Hosted required checks must finish green on this tip before auto-merge can land
  • Pre-commit prevention only helps when core.hooksPath is installed; Cloud/agent pushes still need the explicit adoption update (now in handoff)
  • Merge left to you / existing auto-merge once required checks pass

No provider-backed gates run. No force-push, rebase, or merge performed.

cursoragent and others added 3 commits August 9, 2026 14:33
Co-authored-by: BigSimmo <BigSimmo@users.noreply.github.com>
Annotate detailPayload as DocumentDetailPayload so chunk deep-link
fixtures typecheck. Escalate DsmCompareRemoveLink to location.assign —
router.push still left the remove control active with a stuck ?ids=
query under Production UI load — and cover the hop with a DOM test.

Co-authored-by: BigSimmo <BigSimmo@users.noreply.github.com>
Co-authored-by: BigSimmo <BigSimmo@users.noreply.github.com>
@cursor

cursor Bot commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

PR #1782 CI fix follow-up

Tip: e049a714f93e7eb148ff2cb8e5248b996c8d2ecb
Sync / merge-tree: merged origin/main (was 11 behind / GitHub DIRTY but merge-tree clean). Now 0 behind, merge-tree clean.

Failures addressed

  1. Static PR / typechecktests/document-viewer-shell.dom.test.tsx TS2322 (chunks: [] inferred as never[], selectedChunkId stuck as null). Fixed by typing detailPayload(): DocumentDetailPayload.
  2. Production UI (1) — DSM compare remove: click left the control [active] but ?ids= never changed (soft-nav/router.push stall under full-suite load). DsmCompareRemoveLink now uses window.location.assign; DOM test covers the hop; route-coverage wait uses domcontentloaded.
  3. PR mergeability — cleared by the main sync (was behind-but-clean reported as conflicting).

Local proof

  • tsc clean for changed paths
  • vitest: document-viewer-shell + dsm-compare-remove-link + design-system-adoption 59/59 PASS
  • check:design-system-adoption PASS
    No provider-backed gates. Playwright left to hosted Production UI.

Required CI

Re-triggered on this tip — merge left to you / existing auto-merge once green.

@BigSimmo
BigSimmo merged commit 9507158 into main Aug 9, 2026
26 checks passed
@BigSimmo
BigSimmo deleted the cursor/fix-document-open-scroll-e5bf branch August 9, 2026 14:48
BigSimmo pushed a commit that referenced this pull request Aug 21, 2026
`Production UI (1)` on run 32473783831 confirmed the review-lens fix — that
step passed — and then went red one test earlier in the same file:

    tests/ui-route-coverage.spec.ts:435:7 › DSM comparison renders responsively
    and removes a selected diagnosis
    TimeoutError: page.waitForURL: Timeout 30000ms exceeded.
    waiting for navigation until "domcontentloaded"

This step looked like a plain link and was left alone in the previous commit.
It is not one. `DsmCompareRemoveLink` renders a `next/link` whose `onClick`
calls `preventDefault()` and `stopPropagation()` and then
`window.location.assign(href)`. Before hydration the anchor is a bare
`<a href>`, so a click in that window races two different navigations — the
browser's native one, or React capturing the discrete event and replaying it
once the root hydrates — and neither is guaranteed to leave the URL where the
assertion reads it. Waiting for the handler makes the assign hop the only path
the click can take.

The control's own component doc already records two earlier stalls of this same
hop under Production UI load (`<Link>` soft-nav, then `router.push` on PR
#1782), which is why it uses a full assign at all; this closes the remaining
pre-hydration window rather than changing the hop again.

Not diagnosed from the uploaded trace: artifact download is not available from
this session. If the stall recurs after this, read
`production-ui-diagnostics-<run>-shard1`'s `error-context.md` and `trace.zip`
before changing the navigation itself.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HoyoNN7nCUVDLaE84k6e6c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants