Skip to content

The open alternative to Salesforce, designed for AI.

fix: scroll AI chat to bottom on side panel reopen (#20413)

Félix Malfait524e5d8cf7e7
diff --git a/packages/twenty-front/src/modules/ai/components/AgentChatScrollToBottomOnMountLayoutEffect.tsx b/packages/twenty-front/src/modules/ai/components/AgentChatScrollToBottomOnMountLayoutEffect.tsx
new file mode 100644
index 00000000000..e44c6892025
--- /dev/null
+++ b/packages/twenty-front/src/modules/ai/components/AgentChatScrollToBottomOnMountLayoutEffect.tsx
@@ -0,0 +1,10 @@
+import { scrollAiChatToBottom } from '@/ai/utils/scrollAiChatToBottom';
+import { useLayoutEffect } from 'react';
+
+export const AgentChatScrollToBottomOnMountLayoutEffect = () => {
+ useLayoutEffect(() => {
+ scrollAiChatToBottom();
+ }, []);
+
+ return null;
+};
diff --git a/packages/twenty-front/src/modules/ai/components/AiChatTabMessageList.tsx b/packages/twenty-front/src/modules/ai/components/AiChatTabMessageList.tsx
index bb622e75dee..8256c0c0ac4 100644
--- a/packages/twenty-front/src/modules/ai/components/AiChatTabMessageList.tsx
+++ b/packages/twenty-front/src/modules/ai/components/AiChatTabMessageList.tsx
@@ -3,6 +3,7 @@ import { AiChatLastMessageWithStreamingState } from '@/ai/components/AiChatLastM
import { AiChatNonLastMessageIdsList } from '@/ai/components/AiChatNonLastMessageIdsList';
import { AiChatScrollToBottomButton } from '@/ai/components/AiChatScrollToBottomButton';
import { AgentChatScrollToBottomOnDisplayedThreadChangeLayoutEffect } from '@/ai/components/AgentChatScrollToBottomOnDisplayedThreadChangeLayoutEffect';
+import { AgentChatScrollToBottomOnMountLayoutEffect } from '@/ai/components/AgentChatScrollToBottomOnMountLayoutEffect';
import { AI_CHAT_SCROLL_WRAPPER_ID } from '@/ai/constants/AiChatScrollWrapperId';
import { agentChatHasMessageComponentSelector } from '@/ai/states/selectors/agentChatHasMessageComponentSelector';
import { agentChatIsInitialScrollPendingOnThreadChangeState } from '@/ai/states/agentChatIsInitialScrollPendingOnThreadChangeState';
@@ -49,6 +50,7 @@ export const AiChatTabMessageList = () => {
<AiChatLastMessageWithStreamingState />
<AiChatErrorUnderMessageList />
<AgentChatScrollToBottomOnDisplayedThreadChangeLayoutEffect />
+ <AgentChatScrollToBottomOnMountLayoutEffect />
</ScrollWrapper>
<AiChatScrollToBottomButton />
</StyledScrollWrapperContainer>