fix(web): quote comment box stays on screen for long code lines #22149
main fromrefs/pull/22149/head·merged by t3dotgg(GitHub profile, opens in a new tab) View on GitHubProblem#
Quoting code that ends in a code block's hidden sideways overflow opens the comment box off-screen. Typing into it then scrolls the whole app sideways (3058.5 px measured) until Esc.
Fixes #22109
Root cause#
The comment popover anchors to the last client rect of the cited range (AssistantCitationChip.tsx:92-97). With syntax highlighting, that rect is just the final token span, which can sit entirely in the <pre>'s hidden overflow. Base UI's default limitShift keeps the popup touching its anchor, so it follows it off-screen. Typing then scrolls document.scrollingElement to reveal the caret. (An unsplit text node doesn't reproduce: its wide rect still overlaps the viewport.)
Change#
popupAnchor.getBoundingClientRect now clamps the anchor rect horizontally to the cited message's bounds, keeping its top and height. A visible quote anchors as before. Fixing the anchor puts the box on screen, so typing has no off-screen caret to scroll to: no scroll guard, and the shared ui/popover.tsx is untouched. The Cite toolbar already clamps this way (AssistantSelectionToolbar.tsx:43).
Scope and approval#
Triaged issue #22109. The maintainer suggested handling the sideways shift separately if it remained once the box stayed on screen; it doesn't. 2 files, +54/−1 (code +9/−1, test +45).
Verification#
Real app, 800 px wide, wrapping off; main at 2fcefc9abf vs 6ef0bcca18.
Long text line: triple-click, Cite, type abc. Popup right edge 4137 → 753 px; scrollingElement.scrollLeft after typing 3058.5 → 0.
| Before (main) | After (this PR) |
|---|---|
![]() | ![]() |
After typing, the app is scrolled 3058.5 px left: ![]() | Box at x 433–753, inside the code block. Nothing scrolls. |
Highlighted TypeScript: drag past the visible edge, Cite, type. Popup right edge 818.8 → 753 px (innerWidth 800); this case clipped the box but didn't scroll.
| Before (main) | After (this PR) |
|---|---|
![]() | ![]() |
Save is half hidden. | Box fully visible; Cancel and Save on screen. |
New browser test: 40 token spans ending past innerWidth; open the box, type note, assert scrollLeft === 0 and the popup within innerWidth.
cd apps/web
vp test run src/components/chat/AssistantCitationChip.browser.test.tsx
- Red with main's
AssistantCitationChip.tsx:AssertionError: expected 2241 to be +0(Tests 1 failed | 4 passed (5)). - Green:
Tests 5 passed (5); the reviewer re-ran red and green independently.vp lintandvpr typecheck(apps/web) exit 0.
Known limits:
- Scrolling the code block while the box is open doesn't move it (
autoUpdatedoesn't watch the<pre>). Same on main. - The clamp is to the cited message, which today always sits inside the viewport.
Related PRs#
#22126 by @fixfon targets the same issue by passing sticky through the shared ui/popover.tsx and leaves the sideways scroll out of scope; this PR fixes the anchor instead, which removes both symptoms. #17023 (open) wraps popupAnchor in useMemo; if both land, keep the clamp inside its getBoundingClientRect.
Process#
Loop-record: implementer=claude/claude-opus-5-5/high reviewer=codex/gpt-6.1-sol rounds=1/0 defects=0 role=worker
Implemented test-first by Claude Opus 5.5 (Claude Code in T3 Code). Reviewed by GPT-6.1-Sol (Codex): 1 round, approved, 0 blocking defects.
Model and harness: Claude Opus 5.5 · Claude Code
🤖 Generated with Claude Code
— EtanHey's t3codeClaude (worker) · claude-code/claude-opus-5-5
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:S
Approvability#
Verdict: Approved at
6ef0bccMacroscope's review found this PR approvable — This is a contained web UI bug fix that clamps citation comment popups to the visible message bounds and adds a regression test covering hidden code-block overflow and typing. Its runtime impact is limited to popup positioning, with no schema, infrastructure, security, billing, or authentication changes.
You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
-
⚙️ Run configuration
-
- Configuration used: Path: .coderabbit.config.ts
- Review profile: CHILL
- Plan: Advanced
- Run ID:
a721f701-0457-4cf5-b6f6-5f11eefc0544
📥 Commits
-
Reviewing files that changed from the base of the PR and between 5cd164e845670e49f47ff8d2a0324029c2bab81b and d0572bd61cc6a880a3766415d4b43587ab525000.
📒 Files selected for processing: 1
-
apps/web/src/components/chat/AssistantCitationChip.browser.test.tsx
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
-
📝 Walkthrough
-
The citation popup anchor is clamped to the source message bounds. A browser regression test covers citations in a horizontally overflowing code block and verifies that typing does not cause horizontal document scrolling.
Changes: Citation popup bounds
Layer / File(s) Summary Clamp citation anchor and verify popup position
apps/web/src/components/chat/AssistantCitationChip.tsx,apps/web/src/components/chat/AssistantCitationChip.browser.test.tsxThe popup anchor uses the final client rect and clamps its horizontal edges to the source message bounds. The browser test loads application styles, simulates typing, and verifies popup placement and horizontal scrolling. Priority: ➖ Normal
Estimated code review effort: 2 (Simple) | ~10 minutes
Change: Bug fix · Severity of issue fixed: Medium
Suggested reviewers:
juliusmarminge
Merge Risk: ⚪ Minimal · up to
d0572-
The long-code-line citation case is covered, with no identified issue requiring a fix before merge.
Pre-merge checks:
4-
Check name Status Explanation Description check The description covers the problem, root cause, implementation, scope and approval, verification results, screenshots, test commands, known limits, and agent details. It is complete and directly relat… Title check The title clearly and concisely describes the primary fix: keeping the quote comment box visible for long code lines. Linked Issues check Issue [ #22109] requires the citation comment popover to stay visible when quoted text ends in hidden horizontal overflow and to avoid sideways scrolling while typing.AssistantCitationChip.tsxclamp…Out of Scope Changes check The pull request changes only AssistantCitationChip.tsxand its browser test. The implementation directly targets the linked citation-anchor defect. The test verifies the reported popup-position and…Full details: Description check
-
Explanation
The description covers the problem, root cause, implementation, scope and approval, verification results, screenshots, test commands, known limits, and agent details. It is complete and directly related to the change.
Full details: Linked Issues check
-
Explanation
Issue [
#22109] requires the citation comment popover to stay visible when quoted text ends in hidden horizontal overflow and to avoid sideways scrolling while typing.AssistantCitationChip.tsxclamps the final citation rect toactiveSourceAnchor.sourcebounds while preserving its top and height. The browser test creates 40 token spans beyond the viewport, typesnote, and checks zero document and body horizontal scroll plus viewport-contained popup bounds. The change preserves the existing rect when it is within the message bounds.
Full details: Out of Scope Changes check
-
Explanation
The pull request changes only
AssistantCitationChip.tsxand its browser test. The implementation directly targets the linked citation-anchor defect. The test verifies the reported popup-position and horizontal-scroll behavior. No unrelated product behavior or shared popover code changed.
-
✨ Finishing Touches
-
🧪 Generate unit tests (beta)
-
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
-
t3dotgg(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.





Save is half hidden.
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes