fix @node-rs/jieba and window not found (#1313)

* dynamic import

* perf: entry

* fix: jieba package
This commit is contained in:
Archer
2024-04-28 10:27:34 +08:00
committed by GitHub
parent d407e87dd9
commit 59ece446a2
16 changed files with 560 additions and 139 deletions

View File

@@ -0,0 +1,22 @@
import { ChakraProvider, ColorModeScript } from '@chakra-ui/react';
import { theme } from '@fastgpt/web/styles/theme';
import { Router } from 'next/router';
import { ReactNode } from 'react';
import NProgress from 'nprogress'; //nprogress module
import 'nprogress/nprogress.css';
Router.events.on('routeChangeStart', () => NProgress.start());
Router.events.on('routeChangeComplete', () => NProgress.done());
Router.events.on('routeChangeError', () => NProgress.done());
export const ChakraUIContext = ({ children }: { children: ReactNode }) => {
return (
<ChakraProvider theme={theme}>
<ColorModeScript initialColorMode={theme.config.initialColorMode} />
{children}
</ChakraProvider>
);
};
export default ChakraUIContext;

View File

@@ -0,0 +1,20 @@
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { ReactNode } from 'react';
// Create a client
const queryClient = new QueryClient({
defaultOptions: {
queries: {
keepPreviousData: true,
refetchOnWindowFocus: false,
retry: false,
cacheTime: 10
}
}
});
const QueryClientContext = ({ children }: { children: ReactNode }) => {
return <QueryClientProvider client={queryClient}>{children}</QueryClientProvider>;
};
export default QueryClientContext;

View File

@@ -0,0 +1,81 @@
import { useCallback, useEffect, useState } from 'react';
import { clientInitData } from '@/web/common/system/staticData';
import { useTranslation } from 'next-i18next';
import { useRouter } from 'next/router';
import { useSystemStore } from '@/web/common/system/useSystemStore';
import type { FastGPTFeConfigsType } from '@fastgpt/global/common/system/types/index.d';
import { change2DefaultLng, setLngStore } from '@/web/common/utils/i18n';
export const useInitApp = () => {
const router = useRouter();
const { hiId } = router.query as { hiId?: string };
const { i18n } = useTranslation();
const { loadGitStar, setInitd, feConfigs } = useSystemStore();
const [scripts, setScripts] = useState<FastGPTFeConfigsType['scripts']>([]);
const [title, setTitle] = useState(process.env.SYSTEM_NAME || 'AI');
const initFetch = useCallback(async () => {
const {
feConfigs: { scripts, isPlus, show_git, systemTitle }
} = await clientInitData();
setTitle(systemTitle || 'FastGPT');
// log fastgpt
if (!isPlus) {
console.log(
'%cWelcome to FastGPT',
'font-family:Arial; color:#3370ff ; font-size:18px; font-weight:bold;',
`GitHubhttps://github.com/labring/FastGPT`
);
}
if (show_git) {
loadGitStar();
}
setScripts(scripts || []);
setInitd();
}, [loadGitStar, setInitd]);
const initUserLanguage = useCallback(() => {
// get default language
const targetLng = change2DefaultLng(i18n.language);
if (targetLng) {
setLngStore(targetLng);
router.replace(router.asPath, undefined, { locale: targetLng });
}
}, []);
useEffect(() => {
initFetch();
initUserLanguage();
const errorTrack = (event: ErrorEvent) => {
window.umami?.track('windowError', {
device: {
userAgent: navigator.userAgent,
platform: navigator.platform,
appName: navigator.appName
},
error: event,
url: location.href
});
};
// add window error track
window.addEventListener('error', errorTrack);
return () => {
window.removeEventListener('error', errorTrack);
};
}, []);
useEffect(() => {
hiId && localStorage.setItem('inviterId', hiId);
}, [hiId]);
return {
feConfigs,
scripts,
title
};
};