perf: 个人面板增加错误边界

pull/49/head
moonrailgun 2 years ago
parent 5ef71a994c
commit 6c1e622532

@ -11,7 +11,7 @@ import HttpApi from 'i18next-http-backend'; // https://github.com/i18next/i18nex
/** /**
* *
*/ */
type AllowedLanguage = 'zh-CN' | 'en-US'; export type AllowedLanguage = 'zh-CN' | 'en-US';
i18next i18next
.use(languageDetector) .use(languageDetector)

@ -1,7 +1,7 @@
import type { LanguageDetectorAsyncModule } from 'i18next'; import type { LanguageDetectorAsyncModule } from 'i18next';
import { useRef, useMemo, useCallback } from 'react'; import { useRef, useMemo, useCallback } from 'react';
import _isNil from 'lodash/isNil'; import _isNil from 'lodash/isNil';
import { setLanguage as setI18NLanguage } from './index'; import { AllowedLanguage, setLanguage as setI18NLanguage } from './index';
import { getStorage, useStorage } from '../manager/storage'; import { getStorage, useStorage } from '../manager/storage';
import { LANGUAGE_KEY } from '../utils/consts'; import { LANGUAGE_KEY } from '../utils/consts';
@ -23,7 +23,7 @@ export function useLanguage() {
const originLanguageRef = useRef<string>(); const originLanguageRef = useRef<string>();
const setLanguage = useCallback( const setLanguage = useCallback(
async (newLanguage) => { async (newLanguage: AllowedLanguage) => {
if (_isNil(originLanguageRef.current)) { if (_isNil(originLanguageRef.current)) {
originLanguageRef.current = language; originLanguageRef.current = language;
} }

@ -1,3 +1,4 @@
import { ErrorBoundary } from '@/components/ErrorBoundary';
import { pluginCustomPanel } from '@/plugin/common'; import { pluginCustomPanel } from '@/plugin/common';
import React from 'react'; import React from 'react';
import { Redirect, Route, Switch } from 'react-router-dom'; import { Redirect, Route, Switch } from 'react-router-dom';
@ -10,28 +11,30 @@ import { PersonalSidebar } from './Sidebar';
export const Personal: React.FC = React.memo(() => { export const Personal: React.FC = React.memo(() => {
return ( return (
<PageContent data-tc-role="content-personal" sidebar={<PersonalSidebar />}> <PageContent data-tc-role="content-personal" sidebar={<PersonalSidebar />}>
<Switch> <ErrorBoundary>
<Route path="/main/personal/friends" component={FriendPanel} /> <Switch>
<Route path="/main/personal/friends" component={FriendPanel} />
<Route path="/main/personal/plugins" component={PluginsPanel} /> <Route path="/main/personal/plugins" component={PluginsPanel} />
<Route <Route
path="/main/personal/converse/:converseId" path="/main/personal/converse/:converseId"
component={PersonalConverse} component={PersonalConverse}
/> />
{pluginCustomPanel {pluginCustomPanel
.filter((p) => p.position === 'personal') .filter((p) => p.position === 'personal')
.map((p) => ( .map((p) => (
<Route <Route
key={p.name} key={p.name}
path={`/main/personal/custom/${p.name}`} path={`/main/personal/custom/${p.name}`}
component={p.render} component={p.render}
/> />
))} ))}
<Redirect to="/main/personal/friends" /> <Redirect to="/main/personal/friends" />
</Switch> </Switch>
</ErrorBoundary>
</PageContent> </PageContent>
); );
}); });

Loading…
Cancel
Save