8
8
import { EuiButtonIcon , EuiResizableContainer , useEuiScrollBar , useEuiTheme } from '@elastic/eui' ;
9
9
import { css } from '@emotion/react' ;
10
10
import React , { useEffect , useRef } from 'react' ;
11
+ import { useLocation } from 'react-router-dom' ;
11
12
import { useHasActiveConversation } from '../../hooks/use_conversation' ;
12
13
import { ConversationInputForm } from './conversation_input/conversation_input_form' ;
13
14
import { ConversationRounds } from './conversation_rounds/conversation_rounds' ;
@@ -18,6 +19,7 @@ import { useSendMessage } from '../../context/send_message_context';
18
19
import { useConversationScrollActions } from '../../hooks/use_conversation_scroll_actions' ;
19
20
import { useConversationStatus } from '../../hooks/use_conversation' ;
20
21
import { ConversationContent } from './conversation_grid' ;
22
+ import type { LocationState } from '../../hooks/use_navigation' ;
21
23
22
24
const fullHeightStyles = css `
23
25
height : 100% ;
@@ -33,6 +35,9 @@ export const Conversation: React.FC<{}> = () => {
33
35
const { euiTheme } = useEuiTheme ( ) ;
34
36
const { isResponseLoading } = useSendMessage ( ) ;
35
37
const { isFetched } = useConversationStatus ( ) ;
38
+ const location = useLocation < LocationState > ( ) ;
39
+
40
+ const shouldStickToBottom = location . state ?. shouldStickToBottom ?? true ;
36
41
37
42
const scrollContainerRef = useRef < HTMLDivElement | null > ( null ) ;
38
43
const {
@@ -48,14 +53,14 @@ export const Conversation: React.FC<{}> = () => {
48
53
49
54
const scrollContainerHeight = scrollContainerRef . current ?. clientHeight ?? 0 ;
50
55
51
- // Stick to bottom only on initial conversation load or when { conversationId} is changed
56
+ // Stick to bottom only when user returns to an existing conversation ( conversationId is defined and changes)
52
57
useEffect ( ( ) => {
53
- if ( isFetched && conversationId ) {
58
+ if ( isFetched && conversationId && shouldStickToBottom ) {
54
59
requestAnimationFrame ( ( ) => {
55
60
stickToBottom ( ) ;
56
61
} ) ;
57
62
}
58
- } , [ stickToBottom , isFetched , conversationId ] ) ;
63
+ } , [ stickToBottom , isFetched , conversationId , shouldStickToBottom ] ) ;
59
64
60
65
const scrollContainerStyles = css `
61
66
overflow-y : auto;
0 commit comments