Skip to content

Commit fa08d9c

Browse files
committed
fix(code): preserve session scroll position across window focus
The visibilitychange handler in ConversationView unconditionally scrolled the conversation to the bottom whenever the document became visible again, so cmd+tab away and back would always destroy the user's reading position. Gate the scroll on the same at-bottom state already reported by VirtualizedList, so we only re-pin to the bottom when the user was already following the stream. Manual scroll positions now survive focus changes. Generated-By: PostHog Code Task-Id: 2297f0c5-16fb-475d-8a2b-13cbcae500dd
1 parent d7b8cbb commit fa08d9c

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

apps/code/src/renderer/features/sessions/components/ConversationView.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ export function ConversationView({
5050
compact = false,
5151
}: ConversationViewProps) {
5252
const listRef = useRef<VirtualizedListHandle>(null);
53+
const isAtBottomRef = useRef(true);
5354
const [showScrollButton, setShowScrollButton] = useState(false);
5455
const debugLogsCloudRuns = useSettingsStore((s) => s.debugLogsCloudRuns);
5556
const showDebugLogs = debugLogsCloudRuns;
@@ -129,6 +130,7 @@ export function ConversationView({
129130
}, [items]);
130131

131132
const handleScrollStateChange = useCallback((isAtBottom: boolean) => {
133+
isAtBottomRef.current = isAtBottom;
132134
setShowScrollButton(!isAtBottom);
133135
}, []);
134136

@@ -139,7 +141,7 @@ export function ConversationView({
139141

140142
useEffect(() => {
141143
const handleVisibilityChange = () => {
142-
if (!document.hidden) {
144+
if (!document.hidden && isAtBottomRef.current) {
143145
listRef.current?.scrollToBottom();
144146
setShowScrollButton(false);
145147
}

0 commit comments

Comments
 (0)