You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(web): retrying a failed PDF preview keeps keyboard focus - #47769
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).
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:
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.
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.
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.
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: 4
Check name
Status
Explanation
Title check
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
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
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
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
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.
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
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
size:XS0-9 changed lines (additions + deletions).vouch:unvouchedAuthor is not yet trusted in the VOUCHED list.
2 participants
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.
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
errorunmountsFileSurfaceFailurewhile focused, dropping focus todocument.bodyso workspace recovery moves it toSearch <project> files.Change
In
apps/web/src/components/files/PdfViewer.tsx,onRetrycallsscroll.current?.focus({ preventScroll: true })before clearingerror, keeping focus on the viewer region (role="region",tabIndex={0}) and preservingsetRetrying(true)retries. If it cannot take focus,workspaceFocus.tsrecovery stays the fallback. Added one regression test inapps/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 focusedSearch sample-project files; on212790d6904f, Enter kept focus onbroken.pdf(:focus-visible) and pointer click landed onbroken.pdfwithout:focus-visible. On both commits,locked.pdfpassword retry keptFile passwordfocus and unlocked on"open me", andvalid.pdfshowed1 / 1 page. The new test fails on297b9cc2df58(focus lands on<body>) and passes on212790d6904f;vp run check:changed 297b9cc2df58passed, andgit merge-treeis 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).Focus jumps to Search files 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:
apps/web).navigator.pdfViewerEnabled === trueuses<iframe>).Automated check summaries (Node 26.13.1)
Base (
297b9cc2df58) with the new regression test only:Head (
212790d6904f)vp run check:changed 297b9cc2df58:Generated with Gemini 4 Neon in T3 Code Nightly