Browse Source

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 <noreply@anthropic.com>
pull/11786/head
afc163 4 months ago
parent
commit
69ed8e1e4e
  1. 14
      src/pages/chatbot/index.tsx
  2. 27
      src/pages/list/search/applications/index.tsx
  3. 27
      src/pages/list/search/articles/index.tsx
  4. 27
      src/pages/list/search/projects/index.tsx

14
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<ConversationItem[]>([
{ 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: '💬 新对话',

27
src/pages/list/search/applications/index.tsx

@ -112,21 +112,18 @@ const Applications: FC<Record<string, any>> = () => {
>
<Form.Item name="category">
<TagSelect expandable>
{categoryOptions
.filter(
(
category,
): category is { value: string | number; label: string } =>
category.value !== undefined && category.value !== null,
)
.map((category) => (
<TagSelect.Option
value={category.value}
key={category.value}
>
{category.label}
</TagSelect.Option>
))}
{categoryOptions.flatMap((category) =>
category.value !== undefined && category.value !== null
? [
<TagSelect.Option
value={category.value}
key={category.value}
>
{category.label}
</TagSelect.Option>,
]
: [],
)}
</TagSelect>
</Form.Item>
</StandardFormRow>

27
src/pages/list/search/articles/index.tsx

@ -156,21 +156,18 @@ const Articles: FC = () => {
<StandardFormRow title="所属类目" block style={{ paddingBottom: 11 }}>
<FormItem name="category">
<TagSelect expandable>
{categoryOptions
.filter(
(
category,
): category is { value: string | number; label: string } =>
category.value !== undefined && category.value !== null,
)
.map((category) => (
<TagSelect.Option
value={category.value}
key={category.value}
>
{category.label}
</TagSelect.Option>
))}
{categoryOptions.flatMap((category) =>
category.value !== undefined && category.value !== null
? [
<TagSelect.Option
value={category.value}
key={category.value}
>
{category.label}
</TagSelect.Option>,
]
: [],
)}
</TagSelect>
</FormItem>
</StandardFormRow>

27
src/pages/list/search/projects/index.tsx

@ -110,21 +110,18 @@ const Projects: FC = () => {
>
<FormItem name="category">
<TagSelect expandable>
{categoryOptions
.filter(
(
category,
): category is { value: string | number; label: string } =>
category.value !== undefined && category.value !== null,
)
.map((category) => (
<TagSelect.Option
value={category.value}
key={category.value}
>
{category.label}
</TagSelect.Option>
))}
{categoryOptions.flatMap((category) =>
category.value !== undefined && category.value !== null
? [
<TagSelect.Option
value={category.value}
key={category.value}
>
{category.label}
</TagSelect.Option>,
]
: [],
)}
</TagSelect>
</FormItem>
</StandardFormRow>

Loading…
Cancel
Save