From 69ed8e1e4edc4c81b87e232aafb5e7c5beb50a6f Mon Sep 17 00:00:00 2001 From: afc163 Date: Thu, 14 May 2026 23:52:58 +0800 Subject: [PATCH] fix: resolve react-doctor lint warnings (js-combine-iterations, hydration-mismatch) - Replace .filter().map() with .flatMap() in search pages to avoid double array iteration (js-combine-iterations) - Replace crypto.randomUUID() with ref-based ID generator in chatbot to prevent SSR hydration mismatch (rendering-hydration-mismatch-time) Co-Authored-By: Claude Opus 4.7 --- src/pages/chatbot/index.tsx | 14 +++++++--- src/pages/list/search/applications/index.tsx | 27 +++++++++----------- src/pages/list/search/articles/index.tsx | 27 +++++++++----------- src/pages/list/search/projects/index.tsx | 27 +++++++++----------- 4 files changed, 47 insertions(+), 48 deletions(-) diff --git a/src/pages/chatbot/index.tsx b/src/pages/chatbot/index.tsx index 6aff93a6..5bcd85d1 100644 --- a/src/pages/chatbot/index.tsx +++ b/src/pages/chatbot/index.tsx @@ -8,7 +8,13 @@ import type { import XMarkdown from '@ant-design/x-markdown'; import { useXChat } from '@ant-design/x-sdk'; import { Avatar, Card } from 'antd'; -import React, { useEffect, useMemo, useState } from 'react'; +import React, { + useCallback, + useEffect, + useMemo, + useRef, + useState, +} from 'react'; import type { ConversationItem, ParsedMessage } from './data'; import { createChatProvider } from './service'; @@ -109,6 +115,8 @@ const roleConfig: BubbleListProps['role'] = { const ChatbotPage: React.FC = () => { const { styles } = useStyles(); + const idCounter = useRef(0); + const generateId = useCallback(() => `conv-${++idCounter.current}`, []); const [conversations, setConversations] = useState([ { key: 'default', label: '💬 新对话', group: '今天', isDraft: true }, @@ -180,7 +188,7 @@ const ChatbotPage: React.FC = () => { }; const newChat = () => { - const key = crypto.randomUUID(); + const key = generateId(); setConversations((prev) => [ { key, label: '新对话', group: '今天', isDraft: true }, ...prev, @@ -261,7 +269,7 @@ const ChatbotPage: React.FC = () => { (c) => c.key !== conversation.key, ); if (next.length === 0) { - const key = crypto.randomUUID(); + const key = generateId(); next.push({ key, label: '💬 新对话', diff --git a/src/pages/list/search/applications/index.tsx b/src/pages/list/search/applications/index.tsx index 3d7ad5e4..9aef6d21 100644 --- a/src/pages/list/search/applications/index.tsx +++ b/src/pages/list/search/applications/index.tsx @@ -112,21 +112,18 @@ const Applications: FC> = () => { > - {categoryOptions - .filter( - ( - category, - ): category is { value: string | number; label: string } => - category.value !== undefined && category.value !== null, - ) - .map((category) => ( - - {category.label} - - ))} + {categoryOptions.flatMap((category) => + category.value !== undefined && category.value !== null + ? [ + + {category.label} + , + ] + : [], + )} diff --git a/src/pages/list/search/articles/index.tsx b/src/pages/list/search/articles/index.tsx index 328ce5bd..4d510190 100644 --- a/src/pages/list/search/articles/index.tsx +++ b/src/pages/list/search/articles/index.tsx @@ -156,21 +156,18 @@ const Articles: FC = () => { - {categoryOptions - .filter( - ( - category, - ): category is { value: string | number; label: string } => - category.value !== undefined && category.value !== null, - ) - .map((category) => ( - - {category.label} - - ))} + {categoryOptions.flatMap((category) => + category.value !== undefined && category.value !== null + ? [ + + {category.label} + , + ] + : [], + )} diff --git a/src/pages/list/search/projects/index.tsx b/src/pages/list/search/projects/index.tsx index b9116cb7..f76f1c3b 100644 --- a/src/pages/list/search/projects/index.tsx +++ b/src/pages/list/search/projects/index.tsx @@ -110,21 +110,18 @@ const Projects: FC = () => { > - {categoryOptions - .filter( - ( - category, - ): category is { value: string | number; label: string } => - category.value !== undefined && category.value !== null, - ) - .map((category) => ( - - {category.label} - - ))} + {categoryOptions.flatMap((category) => + category.value !== undefined && category.value !== null + ? [ + + {category.label} + , + ] + : [], + )}