diff --git a/next-i18next.config.js b/next-i18next.config.js index 20fc389776..5b34d68e7b 100644 --- a/next-i18next.config.js +++ b/next-i18next.config.js @@ -2,10 +2,9 @@ const i18n = require('./.i18nrc'); /** @type {import('next-i18next').UserConfig} */ module.exports = { - debug: process.env.NODE_ENV === 'development', + debug: false, fallbackLng: { - default: ['en'], - zh_TW: ['zh_CN'], + default: ['zh_CN'], }, i18n: { defaultLocale: i18n.entryLocale, @@ -13,5 +12,4 @@ module.exports = { }, localePath: typeof window === 'undefined' ? require('node:path').resolve('./public/locales') : '/locales', - reloadOnPrerender: process.env.NODE_ENV === 'development', }; diff --git a/next-utils.config.js b/next-utils.config.js deleted file mode 100644 index 7b80598a84..0000000000 --- a/next-utils.config.js +++ /dev/null @@ -1,22 +0,0 @@ -const pc = require('picocolors'); - -const nextUtilsConfig = () => { - const trueEnv = ['true', '1', 'yes']; - const esmExternals = trueEnv.includes(process.env?.NEXTJS_ESM_EXTERNALS ?? 'false'); - const tsconfigPath = process.env.NEXTJS_TSCONFIG_PATH - ? process.env.NEXTJS_TSCONFIG_PATH - : './tsconfig.json'; - - // eslint-disable-next-line no-console - console.warn( - `${pc.green('warn -')} experimental.esmExternals is ${esmExternals ? 'enabled' : 'disabled'}`, - ); - return { - esmExternals, - tsconfigPath, - }; -}; - -module.exports = { - loadCustomBuildParams: nextUtilsConfig, -}; diff --git a/next.config.mjs b/next.config.mjs index 14fea43063..fa0a988d98 100644 --- a/next.config.mjs +++ b/next.config.mjs @@ -1,22 +1,14 @@ import i18nConfig from './next-i18next.config.js'; -import utilsConfig from './next-utils.config.js'; const API_END_PORT_URL = process.env.API_END_PORT_URL || ''; -const { esmExternals = false, tsconfigPath } = utilsConfig.loadCustomBuildParams(); - /** @type {import('next').NextConfig} */ const nextConfig = { - experimental: { - esmExternals, // https://nextjs.org/blog/next-11-1#es-modules-support - }, i18n: i18nConfig.i18n, reactStrictMode: true, pageExtensions: ['page.tsx', 'api.ts'], transpilePackages: ['@lobehub/ui', 'antd-style'], - typescript: { - tsconfigPath, - }, + webpack(config) { config.experiments = { asyncWebAssembly: true, diff --git a/package.json b/package.json index 0796a78e33..28ef9003e4 100644 --- a/package.json +++ b/package.json @@ -86,7 +86,7 @@ "react-layout-kit": "^1", "swr": "^2", "ts-md5": "^1", - "zustand": "^4", + "zustand": "4.3.6", "zustand-utils": "^1" }, "devDependencies": { @@ -113,7 +113,6 @@ "lint-staged": "^13", "next-pwa": "^5", "node-fetch": "^3", - "picocolors": "^1", "postcss-styled-syntax": "^0.4", "prettier": "^2", "remark": "^14", diff --git a/src/i18n/index.ts b/src/i18n/index.ts deleted file mode 100644 index 132672bdb6..0000000000 --- a/src/i18n/index.ts +++ /dev/null @@ -1,18 +0,0 @@ -import type { Namespace } from 'i18next'; -import type { SSRConfig, UserConfig } from 'next-i18next'; -import { serverSideTranslations } from 'next-i18next/serverSideTranslations'; - -import nextI18nextConfig from '@/../next-i18next.config'; - -type ArrayElementOrSelf = T extends Array ? U[] : T[]; - -export const getServerTranslations = async ( - locale: string, - namespacesRequired?: ArrayElementOrSelf | undefined, - configOverride?: UserConfig, - extraLocales?: string[] | false, -): Promise => { - const config = configOverride ?? nextI18nextConfig; - // @ts-ignore - return serverSideTranslations(locale, namespacesRequired, config, extraLocales); -}; diff --git a/src/pages/_app.page.tsx b/src/pages/_app.page.tsx index e0107fd765..5cdccd173c 100644 --- a/src/pages/_app.page.tsx +++ b/src/pages/_app.page.tsx @@ -1,18 +1,15 @@ import { Analytics } from '@vercel/analytics/react'; import { appWithTranslation } from 'next-i18next'; import type { AppProps } from 'next/app'; -import { Suspense } from 'react'; import Layout from '@/layout'; function MyApp({ Component, pageProps }: AppProps) { return ( - - - - - - + + + + ); } diff --git a/src/pages/chat/SessionList/List/SessionItem.tsx b/src/pages/chat/SessionList/List/SessionItem.tsx index 695e240db1..a99d9e3ead 100644 --- a/src/pages/chat/SessionList/List/SessionItem.tsx +++ b/src/pages/chat/SessionList/List/SessionItem.tsx @@ -2,13 +2,16 @@ import { ActionIcon, Avatar, List } from '@lobehub/ui'; import { Popconfirm } from 'antd'; import { X } from 'lucide-react'; import { useTranslation } from 'next-i18next'; -import { FC, memo } from 'react'; +import { FC, memo, useCallback } from 'react'; +import { Flexbox } from 'react-layout-kit'; import { shallow } from 'zustand/shallow'; import { sessionSelectors, useChatStore } from '@/store/session'; import { useStyles } from './style'; +const { Item } = List; + interface SessionItemProps { active: boolean; id: string; @@ -24,8 +27,8 @@ const SessionItem: FC = memo(({ id, active = true, loading }) const meta = session.meta; const systemRole = session.config.systemRole; return [ - meta.title || t('noDescription'), - systemRole || t('defaultAgent'), + meta.title, + systemRole, sessionSelectors.getAgentAvatar(meta), meta.backgroundColor, session?.updateAt, @@ -34,32 +37,21 @@ const SessionItem: FC = memo(({ id, active = true, loading }) ]; }, shallow); - return ( - - } - className={styles.container} - classNames={{ time: cx('session-time', styles.time) }} - date={updateAt} - description={title} - loading={loading} - onClick={() => { - switchAgent(id); - }} - style={{ - alignItems: 'center', - color: theme.colorText, - }} - title={systemRole} - > + const AvatarItem = useCallback( + () => ( + + ), + [], + ); + + const RemoveButton = useCallback( + ({ id }: Pick) => ( = memo(({ id, active = true, loading }) > - + ), + [], ); -}); + + return ( + + } + classNames={{ time: cx('session-time', styles.time) }} + date={updateAt} + description={title} + loading={loading} + onClick={() => switchAgent(id)} + style={{ + alignItems: 'center', + color: theme.colorText, + }} + title={systemRole} + /> + + + ); +}, shallow); export default SessionItem; diff --git a/src/pages/chat/SessionList/List/index.tsx b/src/pages/chat/SessionList/List/index.tsx index a4fd94e557..bcc9b5bcf8 100644 --- a/src/pages/chat/SessionList/List/index.tsx +++ b/src/pages/chat/SessionList/List/index.tsx @@ -1,3 +1,4 @@ +import isEqual from 'fast-deep-equal'; import { memo } from 'react'; import { Flexbox } from 'react-layout-kit'; import { shallow } from 'zustand/shallow'; @@ -9,8 +10,9 @@ import SessionItem from './SessionItem'; const SessionList = memo(() => { const { styles, cx } = useStyles(); - const [list, activeId, loading] = useChatStore( - (s) => [sessionSelectors.chatList(s), s.activeId, s.loading.summarizingTitle], + const list = useChatStore((s) => sessionSelectors.chatList(s), isEqual); + const [activeId, loading] = useChatStore( + (s) => [s.activeId, s.loading.summarizingTitle], shallow, ); diff --git a/src/store/session/slices/session/selectors/chat.ts b/src/store/session/slices/session/selectors/chat.ts index d8e5efd38d..96d1bb0026 100644 --- a/src/store/session/slices/session/selectors/chat.ts +++ b/src/store/session/slices/session/selectors/chat.ts @@ -1,3 +1,3 @@ import { MetaData } from '@/types/meta'; -export const getAgentAvatar = (s: MetaData) => s.avatar || '😎'; +export const getAgentAvatar = (s: MetaData) => s.avatar || 'default';