Skip to content

Commit 22cd5e4

Browse files
committed
POSSIBLE BREAKAGE: SCROLLING
1 parent d11d3df commit 22cd5e4

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

apps/sim/app/chat/components/message/components/markdown-renderer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ function createCustomComponents(LinkComponent: typeof LinkWithPreview) {
111111
},
112112

113113
inlineCode: ({ children }: { children?: React.ReactNode }) => (
114-
<code className='rounded bg-gray-200 px-1 py-0.5 font-mono text-inherit text-gray-800 dark:bg-gray-700 dark:text-gray-200'>
114+
<code className='rounded bg-gray-200 px-1 py-0.5 font-mono text-gray-800 text-inherit dark:bg-gray-700 dark:text-gray-200'>
115115
{children}
116116
</code>
117117
),

apps/sim/app/workspace/[workspaceId]/files/components/file-viewer/file-viewer.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ interface FileViewerProps {
198198
saveRef?: React.MutableRefObject<(() => Promise<void>) | null>
199199
streamingContent?: string
200200
streamingMode?: 'append' | 'replace'
201+
disableStreamingAutoScroll?: boolean
201202
useCodeRendererForCodeFiles?: boolean
202203
}
203204

@@ -233,6 +234,7 @@ export function FileViewer({
233234
saveRef,
234235
streamingContent,
235236
streamingMode,
237+
disableStreamingAutoScroll = false,
236238
useCodeRendererForCodeFiles = false,
237239
}: FileViewerProps) {
238240
const category = resolveFileCategory(file.type, file.name)
@@ -250,6 +252,7 @@ export function FileViewer({
250252
saveRef={saveRef}
251253
streamingContent={streamingContent}
252254
streamingMode={streamingMode}
255+
disableStreamingAutoScroll={disableStreamingAutoScroll}
253256
useCodeRendererForCodeFiles={useCodeRendererForCodeFiles}
254257
/>
255258
)
@@ -289,6 +292,7 @@ interface TextEditorProps {
289292
saveRef?: React.MutableRefObject<(() => Promise<void>) | null>
290293
streamingContent?: string
291294
streamingMode?: 'append' | 'replace'
295+
disableStreamingAutoScroll: boolean
292296
useCodeRendererForCodeFiles?: boolean
293297
}
294298

@@ -303,6 +307,7 @@ function TextEditor({
303307
saveRef,
304308
streamingContent,
305309
streamingMode = 'append',
310+
disableStreamingAutoScroll,
306311
useCodeRendererForCodeFiles = false,
307312
}: TextEditorProps) {
308313
const initializedRef = useRef(false)
@@ -701,6 +706,10 @@ function TextEditor({
701706

702707
useEffect(() => {
703708
if (!isStreaming) return
709+
if (disableStreamingAutoScroll) {
710+
textareaStuckRef.current = false
711+
return
712+
}
704713
textareaStuckRef.current = true
705714

706715
const el = (shouldUseCodeRenderer ? codeScrollRef.current : textareaRef.current) ?? null
@@ -722,14 +731,14 @@ function TextEditor({
722731
el.removeEventListener('wheel', onWheel)
723732
el.removeEventListener('scroll', onScroll)
724733
}
725-
}, [isStreaming, shouldUseCodeRenderer])
734+
}, [disableStreamingAutoScroll, isStreaming, shouldUseCodeRenderer])
726735

727736
useEffect(() => {
728-
if (!isStreaming || !textareaStuckRef.current) return
737+
if (!isStreaming || !textareaStuckRef.current || disableStreamingAutoScroll) return
729738
const el = (shouldUseCodeRenderer ? codeScrollRef.current : textareaRef.current) ?? null
730739
if (!el) return
731740
el.scrollTop = el.scrollHeight
732-
}, [isStreaming, renderedContent, shouldUseCodeRenderer])
741+
}, [disableStreamingAutoScroll, isStreaming, renderedContent, shouldUseCodeRenderer])
733742

734743
if (streamingContent === undefined) {
735744
if (isLoading) return DOCUMENT_SKELETON

apps/sim/app/workspace/[workspaceId]/home/components/mothership-view/components/resource-content/resource-content.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ export const ResourceContent = memo(function ResourceContent({
107107
}, [workspaceId, streamFileName])
108108

109109
const streamingFileMode: 'append' | 'replace' = 'replace'
110+
const disableStreamingAutoScroll = previewSession?.operation === 'patch'
110111
const rawPreviewText = previewSession?.previewText
111112
const streamingPreviewText =
112113
typeof rawPreviewText === 'string' && rawPreviewText.length > 0 ? rawPreviewText : undefined
@@ -122,6 +123,7 @@ export const ResourceContent = memo(function ResourceContent({
122123
previewMode={previewMode ?? 'preview'}
123124
streamingContent={streamingPreviewText}
124125
streamingMode={streamingFileMode}
126+
disableStreamingAutoScroll={disableStreamingAutoScroll}
125127
useCodeRendererForCodeFiles
126128
/>
127129
) : (
@@ -148,6 +150,7 @@ export const ResourceContent = memo(function ResourceContent({
148150
previewSession?.fileId === resource.id ? streamingPreviewText : undefined
149151
}
150152
streamingMode={streamingFileMode}
153+
disableStreamingAutoScroll={disableStreamingAutoScroll}
151154
/>
152155
)
153156

@@ -437,6 +440,7 @@ interface EmbeddedFileProps {
437440
previewMode?: PreviewMode
438441
streamingContent?: string
439442
streamingMode?: 'append' | 'replace'
443+
disableStreamingAutoScroll?: boolean
440444
}
441445

442446
function EmbeddedFile({
@@ -445,6 +449,7 @@ function EmbeddedFile({
445449
previewMode,
446450
streamingContent,
447451
streamingMode,
452+
disableStreamingAutoScroll = false,
448453
}: EmbeddedFileProps) {
449454
const { canEdit } = useUserPermissionsContext()
450455
const { data: files = [], isLoading, isFetching } = useWorkspaceFiles(workspaceId)
@@ -476,6 +481,7 @@ function EmbeddedFile({
476481
streamingMode={streamingMode}
477482
previewMode={previewMode}
478483
streamingContent={streamingContent}
484+
disableStreamingAutoScroll={disableStreamingAutoScroll}
479485
useCodeRendererForCodeFiles
480486
/>
481487
</div>

0 commit comments

Comments
 (0)