refactor: optimize component rendering with memoization and improve state management

- Added memoization to ChatHistoryPanel, ChatMessageList, and TaskBoard components to prevent unnecessary re-renders.
- Refactored HomePage to utilize useMemo for derived state calculations, enhancing performance.
- Updated main.tsx to conditionally render React.StrictMode based on the environment.
- Improved chat and channel store hooks to allow for selector functions, enhancing flexibility in state selection.
- Enhanced streaming message handling in chat store to manage pending deltas more effectively.
- Refactored LoginPage to include animated decorations for improved user experience.
- Implemented lazy loading for routes in the router to optimize initial load time.
This commit is contained in:
duanshuwen
2026-04-18 11:05:49 +08:00
parent 85d92b937f
commit dfa4388087
12 changed files with 533 additions and 189 deletions

View File

@@ -1,4 +1,4 @@
import { useEffect, useRef, useState } from 'react';
import { memo, useEffect, useRef, useState } from 'react';
import type { ChatHistoryBucket } from './types';
import {
ChevronDown,
@@ -31,7 +31,7 @@ function cx(...classes: Array<string | false | null | undefined>): string {
return classes.filter(Boolean).join(' ');
}
export default function ChatHistoryPanel({
function ChatHistoryPanel({
buckets,
selectedConversationId,
loading,
@@ -50,12 +50,17 @@ export default function ChatHistoryPanel({
useEffect(() => {
setCollapsedBuckets((current) => {
const next: Record<string, boolean> = {};
const currentKeys = Object.keys(current);
let changed = currentKeys.length !== buckets.length;
for (const bucket of buckets) {
next[bucket.key] = current[bucket.key] ?? false;
if (current[bucket.key] !== next[bucket.key]) {
changed = true;
}
}
return next;
return changed ? next : current;
});
}, [buckets]);
@@ -299,3 +304,5 @@ export default function ChatHistoryPanel({
</aside>
);
}
export default memo(ChatHistoryPanel);