diff --git a/lightrag_webui/src/components/retrieval/ChatMessage.tsx b/lightrag_webui/src/components/retrieval/ChatMessage.tsx index b70e7bf0..7570f503 100644 --- a/lightrag_webui/src/components/retrieval/ChatMessage.tsx +++ b/lightrag_webui/src/components/retrieval/ChatMessage.tsx @@ -45,7 +45,13 @@ export type MessageWithError = Message & { } // Restore original component definition and export -export const ChatMessage = ({ message }: { message: MessageWithError }) => { // Remove isComplete prop +export const ChatMessage = ({ + message, + isTabActive = true +}: { + message: MessageWithError + isTabActive?: boolean +}) => { const { t } = useTranslation() const { theme } = useTheme() const [katexPlugin, setKatexPlugin] = useState<((options?: KaTeXOptions) => any) | null>(null) @@ -148,8 +154,13 @@ export const ChatMessage = ({ message }: { message: MessageWithError }) => { // } rounded-lg px-4 py-2`} > {/* Thinking process display - only for assistant messages */} + {/* Always render to prevent layout shift when switching tabs */} {message.role === 'assistant' && (isThinking || thinkingTime !== null) && ( -
+
{ @@ -161,7 +172,8 @@ export const ChatMessage = ({ message }: { message: MessageWithError }) => { // > {isThinking ? ( <> - + {/* Only show spinner animation in active tab to save resources */} + {isTabActive && } {t('retrievePanel.chatMessage.thinking')} ) : ( @@ -247,11 +259,12 @@ export const ChatMessage = ({ message }: { message: MessageWithError }) => { //
)} - {(() => { + {/* Loading indicator - only show in active tab */} + {isTabActive && (() => { // More comprehensive loading state check const hasVisibleContent = finalDisplayContent && finalDisplayContent.trim() !== ''; const isLoadingState = !hasVisibleContent && !isThinking && !thinkingTime; - return isLoadingState && ; + return isLoadingState && })()}
) diff --git a/lightrag_webui/src/features/RetrievalTesting.tsx b/lightrag_webui/src/features/RetrievalTesting.tsx index 0f3e0869..3fe8ec13 100644 --- a/lightrag_webui/src/features/RetrievalTesting.tsx +++ b/lightrag_webui/src/features/RetrievalTesting.tsx @@ -103,6 +103,10 @@ const parseCOTContent = (content: string) => { export default function RetrievalTesting() { const { t } = useTranslation() + // Get current tab to determine if this tab is active (for performance optimization) + const currentTab = useSettingsStore.use.currentTab() + const isRetrievalTabActive = currentTab === 'retrieval' + const [messages, setMessages] = useState(() => { try { const history = useSettingsStore.getState().retrievalHistory || [] @@ -716,7 +720,7 @@ export default function RetrievalTesting() { )} - + {message.role === 'assistant' && (