Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

🐛 fix: model select panel shiny problem and use normal list implementation (#12485)

Rdmclin25fbf4b3cd487
diff --git a/src/features/ModelSwitchPanel/components/List/ListItemRenderer.tsx b/src/features/ModelSwitchPanel/components/List/ListItemRenderer.tsx
index 200c4631252..b5920d140c6 100644
--- a/src/features/ModelSwitchPanel/components/List/ListItemRenderer.tsx
+++ b/src/features/ModelSwitchPanel/components/List/ListItemRenderer.tsx
@@ -13,7 +13,7 @@ import {
import { cssVar, cx } from 'antd-style';
import { LucideArrowRight, LucideBolt } from 'lucide-react';
import { type ReactNode } from 'react';
-import { memo, useEffect, useState } from 'react';
+import { memo, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { useNavigate } from 'react-router-dom';
import urlJoin from 'url-join';
@@ -30,7 +30,6 @@ import { SingleProviderModelItem } from './SingleProviderModelItem';
interface ListItemRendererProps {
activeKey: string;
extraControls?: (modelId: string, providerId: string) => ReactNode;
- isScrolling: boolean;
item: ListItem;
newLabel: string;
onClose: () => void;
@@ -38,17 +37,11 @@ interface ListItemRendererProps {
}
export const ListItemRenderer = memo<ListItemRendererProps>(
- ({ activeKey, extraControls, isScrolling, item, newLabel, onModelChange, onClose }) => {
+ ({ activeKey, extraControls, item, newLabel, onModelChange, onClose }) => {
const { t } = useTranslation('components');
const navigate = useNavigate();
const [detailOpen, setDetailOpen] = useState(false);
- useEffect(() => {
- if (isScrolling) {
- setDetailOpen(false);
- }
- }, [isScrolling]);
-
switch (item.type) {
case 'no-provider': {
return (
@@ -199,7 +192,6 @@ export const ListItemRenderer = memo<ListItemRendererProps>(
activeKey={activeKey}
data={item.data}
extraControls={extraControls}
- isScrolling={isScrolling}
newLabel={newLabel}
onClose={onClose}
onModelChange={onModelChange}
diff --git a/src/features/ModelSwitchPanel/components/List/MultipleProvidersModelItem.tsx b/src/features/ModelSwitchPanel/components/List/MultipleProvidersModelItem.tsx
index c6d442ae74a..24b75b9d590 100644
--- a/src/features/ModelSwitchPanel/components/List/MultipleProvidersModelItem.tsx
+++ b/src/features/ModelSwitchPanel/components/List/MultipleProvidersModelItem.tsx
@@ -16,7 +16,7 @@ import {
import { cx } from 'antd-style';
import { Check, LucideBolt } from 'lucide-react';
import { type ReactNode } from 'react';
-import { memo, useEffect, useState } from 'react';
+import { memo, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { useNavigate } from 'react-router-dom';
import urlJoin from 'url-join';
@@ -32,24 +32,17 @@ interface MultipleProvidersModelItemProps {
activeKey: string;
data: ModelWithProviders;
extraControls?: (modelId: string, providerId: string) => ReactNode;
- isScrolling: boolean;
newLabel: string;
onClose: () => void;
onModelChange: (modelId: string, providerId: string) => Promise<void>;
}
export const MultipleProvidersModelItem = memo<MultipleProvidersModelItemProps>(
- ({ activeKey, data, extraControls, isScrolling, newLabel, onModelChange, onClose }) => {
+ ({ activeKey, data, extraControls, newLabel, onModelChange, onClose }) => {
const { t } = useTranslation('components');
const navigate = useNavigate();
const [submenuOpen, setSubmenuOpen] = useState(false);
- useEffect(() => {
- if (isScrolling) {
- setSubmenuOpen(false);
- }
- }, [isScrolling]);
-
const activeProvider = data.providers.find((p) => menuKey(p.id, data.model.id) === activeKey);
const isActive = !!activeProvider;
diff --git a/src/features/ModelSwitchPanel/components/List/index.tsx b/src/features/ModelSwitchPanel/components/List/index.tsx
index 93fbb8e935b..123501f0fb3 100644
--- a/src/features/ModelSwitchPanel/components/List/index.tsx
+++ b/src/features/ModelSwitchPanel/components/List/index.tsx
@@ -1,8 +1,7 @@
import { Flexbox } from '@lobehub/ui';
import { type FC, type ReactNode } from 'react';
-import { useCallback, useMemo, useState } from 'react';
+import { useMemo } from 'react';
import { useTranslation } from 'react-i18next';
-import { Virtuoso } from 'react-virtuoso';
import { useEnabledChatModels } from '@/hooks/useEnabledChatModels';
@@ -37,7 +36,6 @@ export const List: FC<ListProps> = ({
const { t: tCommon } = useTranslation('common');
const newLabel = tCommon('new');
- const [isScrolling, setIsScrolling] = useState(false);
const enabledList = useEnabledChatModels();
const { model, provider } = useModelAndProvider(modelProp, providerProp);
const { handleModelChange, handleClose } = usePanelHandlers({
@@ -56,45 +54,28 @@ export const List: FC<ListProps> = ({
const activeKey = menuKey(provider, model);
- const handleScrollingStateChange = useCallback((scrolling: boolean) => {
- setIsScrolling(scrolling);
- }, []);
+ const listHeight = panelHeight - TOOLBAR_HEIGHT - FOOTER_HEIGHT;
- const itemContent = useCallback(
- (index: number) => {
- const item = listItems[index];
- return (
+ return (
+ <Flexbox className={styles.list} flex={1} style={{ height: listHeight }}>
+ {listItems.map((item, index) => (
<ListItemRenderer
activeKey={activeKey}
extraControls={extraControls}
- isScrolling={isScrolling}
item={item}
newLabel={newLabel}
+ key={menuKey(
+ 'provider' in item && item.provider ? item.provider.id : '',
+ 'model' in item && item.model
+ ? item.model.id
+ : 'data' in item && item.data
+ ? item.data.displayName
+ : `${item.type}-${index}`,
+ )}
onClose={handleClose}
onModelChange={handleModelChange}
/>
- );
- },
- [activeKey, extraControls, handleClose, handleModelChange, isScrolling, listItems, newLabel],
- );
-
- const listHeight = panelHeight - TOOLBAR_HEIGHT - FOOTER_HEIGHT;
-
- return (
- <Flexbox
- className={styles.list}
- flex={1}
- style={{
- height: listHeight,
- }}
- >
- <Virtuoso
- isScrolling={handleScrollingStateChange}
- itemContent={itemContent}
- overscan={200}
- style={{ height: listHeight }}
- totalCount={listItems.length}
- />
+ ))}
</Flexbox>
);
};
diff --git a/src/features/ModelSwitchPanel/styles.ts b/src/features/ModelSwitchPanel/styles.ts
index 225c19d881b..84caa3193d2 100644
--- a/src/features/ModelSwitchPanel/styles.ts
+++ b/src/features/ModelSwitchPanel/styles.ts
@@ -2,6 +2,7 @@ import { createStaticStyles } from 'antd-style';
export const styles = createStaticStyles(({ css, cssVar }) => ({
container: css`
+ pointer-events: auto;
overflow: hidden;
padding: 0 !important;
`,