Skip to content

Commit f021927

Browse files
committed
fix(file-viewer): preserve session linger in hydrate/upsert and clear spacer after stream
1 parent db84d87 commit f021927

2 files changed

Lines changed: 10 additions & 4 deletions

File tree

apps/sim/app/workspace/[workspaceId]/home/hooks/use-file-preview-sessions.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,12 @@ export function reduceFilePreviewSessions(
9090
}
9191
}
9292

93+
const successor = pickActiveSessionId(nextSessions, state.activeSessionId)
9394
return {
9495
sessions: nextSessions,
95-
activeSessionId: pickActiveSessionId(nextSessions, state.activeSessionId),
96+
// Preserve linger: if the active session is a completed (lingered) one
97+
// and no non-complete successor exists, keep it rather than going null.
98+
activeSessionId: successor ?? state.activeSessionId,
9699
}
97100
}
98101

@@ -108,7 +111,8 @@ export function reduceFilePreviewSessions(
108111

109112
let nextActiveSessionId: string | null
110113
if (action.activate === false || action.session.status === 'complete') {
111-
nextActiveSessionId = pickActiveSessionId(nextSessions, state.activeSessionId)
114+
const successor = pickActiveSessionId(nextSessions, state.activeSessionId)
115+
nextActiveSessionId = successor ?? state.activeSessionId
112116
} else {
113117
// Don't steal active from a session that already has renderable content
114118
// just because a new empty/pending session arrived. Wait until the new

apps/sim/hooks/use-scroll-anchor.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,9 @@ export function useScrollAnchor(isStreaming: boolean, content?: string) {
174174
const spacer = spacerRef.current
175175
if (!el) return
176176

177-
if (!hasUserScrolledRef.current) {
177+
// Clear the spacer when the user hasn't scrolled (auto-follow mode) or when
178+
// streaming has ended (content is stable; no more clip-prevention needed).
179+
if (!hasUserScrolledRef.current || !isStreaming) {
178180
if (spacer) spacer.style.minHeight = '0'
179181
return
180182
}
@@ -203,7 +205,7 @@ export function useScrollAnchor(isStreaming: boolean, content?: string) {
203205
if (el.scrollTop < targetScrollTop) {
204206
el.scrollTop = targetScrollTop
205207
}
206-
}, [content])
208+
}, [content, isStreaming])
207209

208210
return {
209211
ref: callbackRef,

0 commit comments

Comments
 (0)