Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
赵月辉
/
fastgpt-migrated
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Unverified
Commit
6ea0fa96
authored
May 14, 2026
by
Xianquan
Committed by
GitHub
May 14, 2026
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: scroll chat resume to bottom (#6928)
parent
e98a77e1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
163 additions
and
4 deletions
+163
-4
projects/app/src/components/core/chat/ChatContainer/ChatBox/index.tsx
+38
-4
projects/app/src/components/core/chat/ChatContainer/ChatBox/scrollUtils.ts
+33
-0
projects/app/test/components/core/chat/ChatContainer/ChatBox/scrollUtils.test.ts
+92
-0
No files found.
projects/app/src/components/core/chat/ChatContainer/ChatBox/index.tsx
View file @
6ea0fa96
...
...
@@ -73,6 +73,11 @@ import { TeamErrEnum } from '@fastgpt/global/common/error/code/team';
import
{
useMemoEnhance
}
from
'@fastgpt/web/hooks/useMemoEnhance'
;
import
{
cloneDeep
}
from
'lodash'
;
import
{
ChatGenerateStatusEnum
}
from
'@fastgpt/global/core/chat/constants'
;
import
{
getChatScrollTargetKey
,
shouldFollowGeneratingScroll
,
shouldForceScrollAfterRecordsLoaded
}
from
'./scrollUtils'
;
const
FeedbackModal
=
dynamic
(()
=>
import
(
'./components/FeedbackModal'
));
const
SelectMarkCollection
=
dynamic
(()
=>
import
(
'./components/SelectMarkCollection'
));
...
...
@@ -156,6 +161,7 @@ const ChatBox = ({
const
pluginController
=
useRef
(
new
AbortController
());
const
resumeController
=
useRef
<
AbortController
>
();
const
resumedChatTargetRef
=
useRef
<
string
>
();
const
lastRecordsLoadedScrollTargetRef
=
useRef
<
string
>
();
const
[
isLoading
,
setIsLoading
]
=
useState
(
false
);
const
[
feedbackId
,
setFeedbackId
]
=
useState
<
string
>
();
...
...
@@ -185,6 +191,10 @@ const ChatBox = ({
activeAppIdRef
.
current
=
appId
;
const
activeChatIdRef
=
useRef
<
string
|
undefined
>
(
chatId
);
activeChatIdRef
.
current
=
chatId
;
const
chatScrollTargetKey
=
useMemo
(
()
=>
getChatScrollTargetKey
({
appId
,
chatId
}),
[
appId
,
chatId
]
);
const
outLinkAuthData
=
useContextSelector
(
WorkflowRuntimeContext
,
(
v
)
=>
v
.
outLinkAuthData
);
const
welcomeText
=
useContextSelector
(
ChatBoxContext
,
(
v
)
=>
v
.
welcomeText
);
const
variableList
=
useContextSelector
(
ChatBoxContext
,
(
v
)
=>
v
.
variableList
);
...
...
@@ -325,11 +335,14 @@ const ChatBox = ({
const
{
run
:
generatingScroll
}
=
useThrottleFn
(
(
force
?:
boolean
)
=>
{
if
(
!
ScrollContainerRef
.
current
)
return
;
const
isBottom
=
ScrollContainerRef
.
current
.
scrollTop
+
ScrollContainerRef
.
current
.
clientHeight
+
150
>=
ScrollContainerRef
.
current
.
scrollHeight
;
const
isBottom
=
shouldFollowGeneratingScroll
({
scrollTop
:
ScrollContainerRef
.
current
.
scrollTop
,
clientHeight
:
ScrollContainerRef
.
current
.
clientHeight
,
scrollHeight
:
ScrollContainerRef
.
current
.
scrollHeight
,
force
});
if
(
isBottom
||
force
)
{
if
(
isBottom
)
{
scrollToBottom
(
'auto'
);
}
},
...
...
@@ -1274,6 +1287,21 @@ const ChatBox = ({
useEffect
(()
=>
{
if
(
!
shouldForceScrollAfterRecordsLoaded
({
isChatRecordsLoaded
,
targetKey
:
chatScrollTargetKey
,
lastScrolledTargetKey
:
lastRecordsLoadedScrollTargetRef
.
current
})
)
{
return
;
}
lastRecordsLoadedScrollTargetRef
.
current
=
chatScrollTargetKey
;
scrollToBottom
(
'auto'
);
},
[
chatScrollTargetKey
,
isChatRecordsLoaded
,
scrollToBottom
]);
useEffect
(()
=>
{
if
(
!
enableAutoResume
||
!
isReady
||
!
isChatRecordsLoaded
||
...
...
@@ -1296,6 +1324,7 @@ const ChatBox = ({
const
controller
=
new
AbortController
();
resumeController
.
current
=
controller
;
scrollToBottom
(
'auto'
);
scrollToBottom
(
'auto'
,
100
);
let
resumeFinalStatus
=
ChatGenerateStatusEnum
.
done
;
let
hasPreparedResumeAiRecord
=
false
;
...
...
@@ -1337,6 +1366,8 @@ const ChatBox = ({
status
:
ChatStatusEnum
.
finish
}))
);
scrollToBottom
(
'auto'
);
scrollToBottom
(
'auto'
,
100
);
return
;
}
...
...
@@ -1380,6 +1411,7 @@ const ChatBox = ({
return
next
;
});
scrollToBottom
(
'auto'
);
}
catch
(
error
)
{
if
(
controller
.
signal
.
aborted
)
return
;
if
(
!
isActiveResumeTarget
({
appId
:
resumeForAppId
,
chatId
:
resumeForChatId
}))
return
;
...
...
@@ -1417,6 +1449,7 @@ const ChatBox = ({
return
next
;
});
scrollToBottom
(
'auto'
);
if
(
isStreamError
)
{
toast
({
...
...
@@ -1452,6 +1485,7 @@ const ChatBox = ({
);
if
(
finishedInActiveChat
)
{
scrollToBottom
(
'auto'
,
100
);
void
postMarkChatRead
({
appId
:
resumeForAppId
,
chatId
:
resumeForChatId
,
...
...
projects/app/src/components/core/chat/ChatContainer/ChatBox/scrollUtils.ts
0 → 100644
View file @
6ea0fa96
export
const
CHAT_GENERATING_SCROLL_BOTTOM_THRESHOLD
=
150
;
export
const
getChatScrollTargetKey
=
({
appId
,
chatId
}:
{
appId
?:
string
;
chatId
?:
string
})
=>
{
if
(
!
appId
||
!
chatId
)
return
;
return
`
${
appId
}
:
${
chatId
}
`
;
};
export
const
shouldForceScrollAfterRecordsLoaded
=
({
isChatRecordsLoaded
,
targetKey
,
lastScrolledTargetKey
}:
{
isChatRecordsLoaded
:
boolean
;
targetKey
?:
string
;
lastScrolledTargetKey
?:
string
;
})
=>
{
if
(
!
isChatRecordsLoaded
||
!
targetKey
)
return
false
;
return
targetKey
!==
lastScrolledTargetKey
;
};
export
const
shouldFollowGeneratingScroll
=
({
scrollTop
,
clientHeight
,
scrollHeight
,
force
=
false
,
threshold
=
CHAT_GENERATING_SCROLL_BOTTOM_THRESHOLD
}:
{
scrollTop
:
number
;
clientHeight
:
number
;
scrollHeight
:
number
;
force
?:
boolean
;
threshold
?:
number
;
})
=>
force
||
scrollTop
+
clientHeight
+
threshold
>=
scrollHeight
;
projects/app/test/components/core/chat/ChatContainer/ChatBox/scrollUtils.test.ts
0 → 100644
View file @
6ea0fa96
import
{
describe
,
expect
,
it
}
from
'vitest'
;
import
{
CHAT_GENERATING_SCROLL_BOTTOM_THRESHOLD
,
getChatScrollTargetKey
,
shouldFollowGeneratingScroll
,
shouldForceScrollAfterRecordsLoaded
}
from
'@/components/core/chat/ChatContainer/ChatBox/scrollUtils'
;
describe
(
'ChatBox scrollUtils'
,
()
=>
{
it
(
'should build stable scroll target keys only when appId and chatId exist'
,
()
=>
{
expect
(
getChatScrollTargetKey
({
appId
:
'app-1'
,
chatId
:
'chat-1'
})).
toBe
(
'app-1:chat-1'
);
expect
(
getChatScrollTargetKey
({
appId
:
'app-1'
})).
toBeUndefined
();
expect
(
getChatScrollTargetKey
({
chatId
:
'chat-1'
})).
toBeUndefined
();
});
it
(
'should force scroll after a different chat records loaded'
,
()
=>
{
expect
(
shouldForceScrollAfterRecordsLoaded
({
isChatRecordsLoaded
:
false
,
targetKey
:
'app-1:chat-1'
,
lastScrolledTargetKey
:
undefined
})
).
toBe
(
false
);
expect
(
shouldForceScrollAfterRecordsLoaded
({
isChatRecordsLoaded
:
true
,
targetKey
:
undefined
,
lastScrolledTargetKey
:
undefined
})
).
toBe
(
false
);
expect
(
shouldForceScrollAfterRecordsLoaded
({
isChatRecordsLoaded
:
true
,
targetKey
:
'app-1:chat-1'
,
lastScrolledTargetKey
:
undefined
})
).
toBe
(
true
);
expect
(
shouldForceScrollAfterRecordsLoaded
({
isChatRecordsLoaded
:
true
,
targetKey
:
'app-1:chat-2'
,
lastScrolledTargetKey
:
'app-1:chat-1'
})
).
toBe
(
true
);
expect
(
shouldForceScrollAfterRecordsLoaded
({
isChatRecordsLoaded
:
true
,
targetKey
:
'app-1:chat-1'
,
lastScrolledTargetKey
:
'app-1:chat-1'
})
).
toBe
(
false
);
});
it
(
'should keep generating follow-scroll limited to near-bottom unless forced'
,
()
=>
{
expect
(
shouldFollowGeneratingScroll
({
scrollTop
:
0
,
clientHeight
:
500
,
scrollHeight
:
1000
})
).
toBe
(
false
);
expect
(
shouldFollowGeneratingScroll
({
scrollTop
:
350
,
clientHeight
:
500
,
scrollHeight
:
1000
})
).
toBe
(
true
);
expect
(
shouldFollowGeneratingScroll
({
scrollTop
:
0
,
clientHeight
:
500
,
scrollHeight
:
1000
,
force
:
true
})
).
toBe
(
true
);
expect
(
shouldFollowGeneratingScroll
({
scrollTop
:
1000
-
500
-
CHAT_GENERATING_SCROLL_BOTTOM_THRESHOLD
-
1
,
clientHeight
:
500
,
scrollHeight
:
1000
})
).
toBe
(
false
);
expect
(
shouldFollowGeneratingScroll
({
scrollTop
:
1000
-
500
-
CHAT_GENERATING_SCROLL_BOTTOM_THRESHOLD
,
clientHeight
:
500
,
scrollHeight
:
1000
})
).
toBe
(
true
);
});
});
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment