Skip to content

fix(web): retrying a failed PDF preview keeps keyboard focus - #47769

Merged
juliusmarminge merged 2 commits into
pingdotgg:mainfrom
only21mil:fix/web-pdf-retry-keeps-keyboard-focus
Dec 2, 2026
Merged

juliusmarminge merged 2 commits into
pingdotgg:mainfrom
only21mil:fix/web-pdf-retry-keeps-keyboard-focus

Conversation

@only21mil

Copy link
Copy Markdown
Contributor

Problem

When a PDF in the Files panel fails to load and a keyboard user activates Try again, focus jumps to the file search box instead of staying in the PDF preview. Clearing error unmounts FileSurfaceFailure while focused, dropping focus to document.body so workspace recovery moves it to Search <project> files.

Change

In apps/web/src/components/files/PdfViewer.tsx, onRetry calls scroll.current?.focus({ preventScroll: true }) before clearing error, keeping focus on the viewer region (role="region", tabIndex={0}) and preserving setRetrying(true) retries. If it cannot take focus, workspaceFocus.ts recovery stays the fallback. Added one regression test in apps/web/src/components/files/PdfViewer.browser.test.tsx.

Scope

Bug fix for keyboard focus loss in the in-app PDF viewer (used on Electron desktop, iOS WebKit, and browsers with built-in PDF viewing disabled). 1-line fix for an obvious bug; no issue filed.

Verification

AI agent checks (Node 26.13.1): on 297b9cc2df58, Enter and pointer click on Try again focused Search sample-project files; on 212790d6904f, Enter kept focus on broken.pdf (:focus-visible) and pointer click landed on broken.pdf without :focus-visible. On both commits, locked.pdf password retry kept File password focus and unlocked on "open me", and valid.pdf showed 1 / 1 page. The new test fails on 297b9cc2df58 (focus lands on <body>) and passes on 212790d6904f; vp run check:changed 297b9cc2df58 passed, and git merge-tree is clean.

Setup: Linux x64, light theme, 1280x800 headless Chromium (navigator.pdfViewerEnabled === false), isolated dev server, synthetic repo (broken.pdf, valid.pdf, locked.pdf).

Steps: Replay (dev) (showcase) → Files → broken.pdf → "Invalid PDF structure." → focus Try again → Enter (debugging port).

Before 297b9cc2df58 After 212790d6904f
Focus jumps to Search files after Enter on Try again
Focus jumps to Search files after Enter on Try again
Focus stays on broken.pdf preview after Enter on Try again
Focus stays on broken.pdf preview after Enter on Try again

Links: PdfViewer.tsx, PdfViewer.browser.test.tsx (apps/web/src/components/files/)

Not shown:

  • Electron desktop (shares apps/web).
  • Native PDF plugin (navigator.pdfViewerEnabled === true uses <iframe>).
  • Mobile (native PDF views; no Try again).
Automated check summaries (Node 26.13.1)

Base (297b9cc2df58) with the new regression test only:

FAIL |browser (chromium)| src/components/files/PdfViewer.browser.test.tsx > keeps keyboard focus in the PDF region when retrying a failed load
Expected element with focus:
  <div aria-label="Broken PDF" role="region" tabindex="0">
Received element with focus:
  <body>
Test Files  1 failed (1)
     Tests  1 failed | 9 passed (10)

Head (212790d6904f) vp run check:changed 297b9cc2df58:

check:changed summary
  pass  format  0.3s
  pass  lint  0.6s
  pass  knip  9.3s
  pass  typecheck (2 packages)  0.5s
  pass  test (1 files)  11.3s
  pass  react compiler (1 files)  1.2s

Generated with Gemini 4 Neon in T3 Code Nightly

@github-actions github-actions Bot added the vouch:unvouched Author is not yet trusted in the VOUCHED list. label Dec 2, 2026
@macroscopeapp

macroscopeapp Bot commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Approved at 212790d

Macroscope's review found this PR approvable — Retrying a failed PDF preview now moves keyboard focus to the preview region without scrolling. The change is limited to that explicit interaction and carries no obvious material risk.

You can add or adjust custom eligibility rules. Learn more.

@github-actions github-actions Bot added the size:XS 0-9 changed lines (additions + deletions). label Dec 2, 2026
@coderabbitai

coderabbitai Bot commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 212790d and 5d162a7.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review

No actionable comments were generated in the recent review.

Walkthrough

When a PDF load fails, retrying now focuses the PDF scroll region without scrolling it before clearing the error and restarting the load. A browser test checks keyboard focus after retry.

Changes: PDF retry focus

Layer / File(s) Summary
Retry focus behavior
apps/web/src/components/files/PdfViewer.tsx, apps/web/src/components/files/PdfViewer.browser.test.tsx
The retry handler focuses the scroll region with preventScroll: true before clearing the error and restarting the load. The browser test activates “Try again” with Enter, checks focus on the “Broken PDF” region, and revokes the temporary object URL.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Change: Bug fix

Suggested reviewers: iamshadmantaqi, yash-singh1

Merge Risk: Minimal · previous review 21279

Retrying a failed PDF preview with the keyboard now keeps focus in the PDF region instead of losing it. No merge-blocking risk was found. Electron and native PDF plugin behavior were not shown.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title "fix(web): retrying a failed PDF preview keeps keyboard focus" matches the changeset. The change makes PdfViewer focus the scroll region before clearing the error on retry, and adds a regres…
Description check Passed The description follows the repository template. It has Problem, Change, Scope, and Verification sections, and each section has specific content. The Problem section explains the focus jump to the sea…
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.
Full details: Title check

Explanation

The title "fix(web): retrying a failed PDF preview keeps keyboard focus" matches the changeset. The change makes PdfViewer focus the scroll region before clearing the error on retry, and adds a regression test for that focus behavior. It is a conventional commit title, specific, and states the primary change.

Full details: Description check

Explanation

The description follows the repository template. It has Problem, Change, Scope, and Verification sections, and each section has specific content. The Problem section explains the focus jump to the search box and reproduction steps. The Change section names the files and the onRetry behavior, with the workspaceFocus fallback. The Scope section states this is a bug fix, links the test file, and explains why no issue was filed. The Verification section lists concrete steps, before and after results, the failing test output, and the check results. It includes before and after screenshots and states what was not checked (Electron, native PDF plugin, mobile). The template asks for the agent model and harness at the end, and the footer says "Generated with Gemini 4 Neon in T3 Code Nightly", so that is covered. The Scope section cites no issue link, but the author gives a reason for omitting one, which the template allows.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 56d114d and 212790d.

Files selected for processing: 2

  • apps/web/src/components/files/PdfViewer.browser.test.tsx
  • apps/web/src/components/files/PdfViewer.tsx

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.

@juliusmarminge juliusmarminge added the takeover:in-progress A takeover lead is working on this PR label Dec 2, 2026
@juliusmarminge

Copy link
Copy Markdown
Member

Evidence

Environment: real web app, Linux Chromium 156, 1440×900, light theme; separate fresh server state per commit, synthetic files and Replay thread seeded through T3 APIs.

Steps: Seed a synthetic proj project containing an invalid broken.pdf and a Replay thread; open the thread, toggle the right panel, choose Files, click broken.pdf, wait for Invalid PDF structure / Try again, press Tab until Try again has keyboard focus, then press Enter. Capture the repeated error and check focus remains within the PDF region and window scroll stays (0,0).

Scenario: Retrying a failed PDF keeps keyboard focus in its preview

Proven: the scenario fails on base c5651d74d6 and passes on head 5d162a7bf6.

Base c5651d74d6 Head 5d162a7bf6
Result ❌ failed
ASSERTION_FAILED: expected {"inPdf":false,"x":0,"y":0} to equal {"inPdf":true,"x":0,"y":0}
✅ passed
after keyboard retry Base c5651d74d6: after keyboard retry Head 5d162a7bf6: after keyboard retry

| Recording | Before recording | After recording |

Base: focus jumps to Search proj files. Head: focus stays on the broken.pdf region. Both retain window scroll (0,0).

Scenario source

@juliusmarminge juliusmarminge added takeover:ready Takeover done; auto-lands when gates pass and removed takeover:in-progress A takeover lead is working on this PR labels Dec 2, 2026
@juliusmarminge
juliusmarminge merged commit 4698ccc into pingdotgg:main Dec 2, 2026
40 checks passed
@juliusmarminge juliusmarminge removed the takeover:ready Takeover done; auto-lands when gates pass label Dec 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XS 0-9 changed lines (additions + deletions). vouch:unvouched Author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants