Repository navigation
Fix chat scroll restoration across thread switches - #145
Conversation
- Keep auto-scroll pinned to bottom during thread changes, composer resize, and streaming updates - Improve virtualized timeline measurement/keying to prevent stale height reuse between threads - Hand off blob image preview URLs from optimistic to server messages to avoid flicker/revocation races
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Autofix Details
Bugbot Autofix prepared a fix for the issue found in the latest run.
- ✅ Fixed: Filtered preview URL array misaligns with attachment indices
- Changed collectUserMessageBlobPreviewUrls to push undefined for skipped attachments instead of omitting them, preserving positional correspondence with the full attachments array, and updated all type signatures and length guards accordingly.
Or push these changes by commenting:
@cursor push 8963dcf4b4
Preview (8963dcf4b4)
diff --git a/apps/web/src/components/ChatView.tsx b/apps/web/src/components/ChatView.tsx
--- a/apps/web/src/components/ChatView.tsx
+++ b/apps/web/src/components/ChatView.tsx
@@ -257,14 +257,20 @@
}
}
-function collectUserMessageBlobPreviewUrls(message: ChatMessage): string[] {
+function collectUserMessageBlobPreviewUrls(message: ChatMessage): (string | undefined)[] {
if (message.role !== "user" || !message.attachments) {
return [];
}
- const previewUrls: string[] = [];
+ const previewUrls: (string | undefined)[] = [];
for (const attachment of message.attachments) {
- if (attachment.type !== "image") continue;
- if (!attachment.previewUrl || !attachment.previewUrl.startsWith("blob:")) continue;
+ if (
+ attachment.type !== "image" ||
+ !attachment.previewUrl ||
+ !attachment.previewUrl.startsWith("blob:")
+ ) {
+ previewUrls.push(undefined);
+ continue;
+ }
previewUrls.push(attachment.previewUrl);
}
return previewUrls;
@@ -505,7 +511,7 @@
const [terminalFocusRequestId, setTerminalFocusRequestId] = useState(0);
const [composerHighlightedItemId, setComposerHighlightedItemId] = useState<string | null>(null);
const [attachmentPreviewHandoffByMessageId, setAttachmentPreviewHandoffByMessageId] = useState<
- Record<string, string[]>
+ Record<string, (string | undefined)[]>
>({});
const [lastInvokedScriptByProjectId, setLastInvokedScriptByProjectId] = useState<
Record<string, string>
@@ -518,7 +524,7 @@
const composerFormHeightRef = useRef(0);
const composerCommandInputRef = useRef<HTMLInputElement>(null);
const composerImagesRef = useRef<ComposerImageAttachment[]>([]);
- const attachmentPreviewHandoffByMessageIdRef = useRef<Record<string, string[]>>({});
+ const attachmentPreviewHandoffByMessageIdRef = useRef<Record<string, (string | undefined)[]>>({});
const attachmentPreviewHandoffTimeoutByMessageIdRef = useRef<Record<string, number>>({});
const sendInFlightRef = useRef(false);
const dragDepthRef = useRef(0);
@@ -657,8 +663,9 @@
attachmentPreviewHandoffByMessageIdRef.current = {};
setAttachmentPreviewHandoffByMessageId({});
}, []);
- const handoffAttachmentPreviews = useCallback((messageId: MessageId, previewUrls: string[]) => {
- if (previewUrls.length === 0) return;
+ const handoffAttachmentPreviews = useCallback(
+ (messageId: MessageId, previewUrls: (string | undefined)[]) => {
+ if (!previewUrls.some(Boolean)) return;
const previousPreviewUrls = attachmentPreviewHandoffByMessageIdRef.current[messageId] ?? [];
for (const previewUrl of previousPreviewUrls) {
@@ -705,7 +712,7 @@
return message;
}
const handoffPreviewUrls = attachmentPreviewHandoffByMessageId[message.id];
- if (!handoffPreviewUrls || handoffPreviewUrls.length === 0) {
+ if (!handoffPreviewUrls || !handoffPreviewUrls.some(Boolean)) {
return message;
}
@@ -1414,7 +1421,7 @@
setOptimisticUserMessages((existing) => existing.filter((message) => !serverIds.has(message.id)));
for (const removedMessage of removedMessages) {
const previewUrls = collectUserMessageBlobPreviewUrls(removedMessage);
- if (previewUrls.length > 0) {
+ if (previewUrls.some(Boolean)) {
handoffAttachmentPreviews(removedMessage.id, previewUrls);
continue;
}collectUserMessageBlobPreviewUrls returns a compact array (image+blob only). Consumer now indexes by image position, not full attachment index, so blob URLs apply to the correct server attachments when some are skipped. Made-with: Cursor
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Autofix Details
Bugbot Autofix prepared a fix for the issue found in the latest run.
- ✅ Fixed: Redundant workLogCount effect duplicates timelineEntries effect
- Removed the redundant workLogCount effect and its unused variable since timelineEntries already depends on workLogEntries via useMemo, making the workLogCount effect dead code.
Or push these changes by commenting:
@cursor push 85b49d6de6
Preview (85b49d6de6)
diff --git a/apps/web/src/components/ChatView.tsx b/apps/web/src/components/ChatView.tsx
--- a/apps/web/src/components/ChatView.tsx
+++ b/apps/web/src/components/ChatView.tsx
@@ -1284,7 +1284,6 @@
// Auto-scroll on new messages
const messageCount = timelineMessages.length;
- const workLogCount = workLogEntries.length;
const scrollMessagesToBottom = useCallback((behavior: ScrollBehavior = "auto") => {
const scrollContainer = messagesScrollRef.current;
if (!scrollContainer) return;
@@ -1358,11 +1357,6 @@
if (phase !== "running") return;
if (!shouldAutoScrollRef.current) return;
scheduleStickToBottom();
- }, [phase, scheduleStickToBottom, workLogCount]);
- useEffect(() => {
- if (phase !== "running") return;
- if (!shouldAutoScrollRef.current) return;
- scheduleStickToBottom();
}, [phase, scheduleStickToBottom, timelineEntries]);
useEffect(() => {timelineEntries is derived from workLogEntries; the timelineEntries effect already runs when work log changes. Dropped duplicate effect and unused workLogCount variable. Made-with: Cursor
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix prepared a fix for the issue found in the latest run.
- ✅ Fixed: Mixed height measurement APIs cause spurious change detection
- Changed the ResizeObserver callback to use entry.borderBoxSize[0]?.blockSize (with contentRect fallback) so both the initial seed and subsequent measurements use border-box dimensions consistently.
Or push these changes by commenting:
@cursor push cffc3013cd
Preview (cffc3013cd)
diff --git a/apps/web/src/components/ChatView.tsx b/apps/web/src/components/ChatView.tsx
--- a/apps/web/src/components/ChatView.tsx
+++ b/apps/web/src/components/ChatView.tsx
@@ -1335,7 +1335,7 @@
const [entry] = entries;
if (!entry) return;
- const nextHeight = entry.contentRect.height;
+ const nextHeight = entry.borderBoxSize[0]?.blockSize ?? entry.contentRect.height;
const previousHeight = composerFormHeightRef.current;
composerFormHeightRef.current = nextHeight;| const [entry] = entries; | ||
| if (!entry) return; | ||
|
|
||
| const nextHeight = entry.contentRect.height; |
There was a problem hiding this comment.
Mixed height measurement APIs cause spurious change detection
Low Severity
The initial height is stored via getBoundingClientRect().height (border-box size, including padding and border) but the ResizeObserver callback reads entry.contentRect.height (content-box size, excluding padding and border). If the composer form element ever acquires padding or a border (from CSS changes or user-agent styles), the first observer callback will always detect a spurious height "change" and trigger scheduleStickToBottom(), because the two measurement APIs return different values for the same element. Using entry.borderBoxSize[0].blockSize (or consistently using contentRect for the initial seed) would keep the comparison consistent.
…pired-arrow-sessions fix(server): an expired machine arrow ends the sessions it granted
- Client sessions end when an arrow expires: the old level side reads the level the sessions got, through the helper of pingdotgg#145 (MM-912). - A portal set up before app invites reports the missing /client app, so "Set up approvals" shows again (MM-1208). - Invites last 15 minutes and have "Cancel invite" in the client panel and the dialog (MM-913). - Token removal treats a Cloudflare 404 as done, and removal decides by the stored token id (MM-915). - Redeem reads the client again after the Cloudflare calls and deletes the new token when the client is gone or a pause cut its arrows. - The /enroll Bypass app covers /enroll/client, so the extra bypass app is gone. README, spec and fork docs updated.
CodeRabbit on #145: the wake command's stderr was read without a limit and shown to clients in the host's failure message. Now a 4 KiB tail goes to the error for logs, clients see a fixed summary, and a changed wake command is compared element by element.
…in GMACKO Nightly' (pingdotgg#145) from T3CODE-125-git-auth into custom-local
…pingdotgg#145) from sync/upstream-2026-11-28-0330 into dev Reviewed-on: https://git.nepjua.org/yasinuslu/t3code/pulls/145



Summary
requestAnimationFramefor smoother behaviorResizeObserverto maintain scroll position when the textarea grows/shrinksTest plan
🤖 Generated with Claude Code
Note
Medium Risk
Changes core chat scrolling/virtualization behavior and blob URL lifecycle for image previews, which could introduce UI regressions (jumping scroll, incorrect measurements, or leaked/revoked previews) despite being frontend-only.
Overview
Improves chat sticky-bottom behavior when switching threads and during dynamic layout changes by scheduling bottom scroll via
requestAnimationFrame, re-sticking shortly after thread switches, and reacting to composer height changes viaResizeObserver.Hardens
MessagesTimelinevirtualization to avoid scroll/measurement leakage across threads by using stable row keys, keeping the last8rows unvirtualized, using content-based height estimates, and remeasuring on image load/error. Also adds a TTL-based attachment preview handoff so blob image previews don’t flicker when optimistic user messages are replaced by server-confirmed messages.Written by Cursor Bugbot for commit 61a8ca2. This will update automatically on new commits. Configure here.
Note
Restore chat bottom stickiness across thread switches and implement rAF-based auto-scroll with a 96ms fallback, an 8-row unvirtualized tail, and a 5000ms attachment preview handoff in
ChatViewandMessagesTimelineAdd rAF-scheduled bottom scrolling with a timer fallback, transfer
blob:image previews from optimistic to server messages with TTL, and update virtualization to keep the last 8 rows unvirtualized and measure rows using an estimator; wire image load/error to schedule re-measure and resetMessagesTimelineper thread.📍Where to Start
Start with the auto-scroll and preview handoff logic in
ChatViewwithin ChatView.tsx, then review virtualization changes inMessagesTimelinein the same file.Macroscope summarized 61a8ca2.