Uh oh!
There was an error while loading. Please reload this page.
fix(web): return focus to the composer after closing a media preview - #9513
Conversation
Opening an attachment preview from the composer left the composer expanded, but closing it dropped focus on the removed dialog. The blur check saw nothing of the composer's under focus and rested it. The dialog now marks itself as composer-owned while open and hands focus back to whatever opened it on close. Co-Authored-By: Claude Code <noreply@anthropic.com>
Thread transfer impact✅ Thread transfer remains within every enforced ceiling.
Baseline: unavailable · PR result: Scenario and decoded snapshot size10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.
Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed. |
ApprovabilityVerdict: Approved at Macroscope's review found this PR approvable — This is a focused one-file UI bug fix that restores focus after media-preview closure and reuses the existing composer focus-scope mechanism. Its runtime impact is limited to preview focus and composer expansion behavior, with no schema, security, billing, infrastructure, or default changes. You can add or adjust custom eligibility rules. Learn more. |
Reported: with the composer expanded and an attachment on it, opening the attachment keeps the composer up (correct), but closing the preview collapses it instead of leaving focus on the composer.
Opening the preview leaves focus on the thumbnail button, which is inside the composer, so the composer stays expanded. But interacting with the dialog — the close button, the image, a media control — moves focus into the portaled dialog, which is outside the composer's focus scope. When the dialog unmounts on close, focus falls to
<body>; the composer's blur check sees nothing of its own focused and rests it. Reliable repro: attach an image with an empty prompt, open it, close it with the ✕.Two changes to
ExpandedImageDialog:composerFloatingLayerProps), so focus landing on the close button or a media control while the preview is open counts as still inside the composer scope — the same mechanism already used for composer menus and popovers.<body>.Applies to image and video previews and every close path (✕, backdrop, Escape, or after interacting with the media). Stacked on #9499; the diff is independent.
Before
Empty prompt + attachment, open the preview, close with ✕ → composer collapses to its resting line.
https://gh-file-drop-api-prod-mi5fy3sowv63ufte.pinglabs.workers.dev/f/2ac3f3888c0ee100/before-preview.mp4
After
Same steps; the composer stays expanded with focus back on it.
https://gh-file-drop-api-prod-mi5fy3sowv63ufte.pinglabs.workers.dev/f/dfb194be5223fd9f/after-preview.mp4
Surfaces
composerEventScopetest already covers that a composer-owned floating layer counts as inside the composer scope.mainthe composer collapsed 254px → 84px on every close; with the fix it stays 254px across ✕, backdrop, Escape, and after clicking the media, for both image and video.Claude Fable 5 via Claude Code.
🤖 Generated with Claude Code
Note
Restore focus to previously active element when
ExpandedImageDialogclosesRecords the document's active element on mount and refocuses it on unmount using
preventScroll, so closing a media preview returns focus to the composer. The portal root also now receivescomposerFloatingLayerProps.Macroscope summarized f842ddf.