mirror of
https://github.com/labring/FastGPT.git
synced 2025-08-01 03:48:24 +00:00
fix @node-rs/jieba and window not found (#1313)
* dynamic import * perf: entry * fix: jieba package
This commit is contained in:
22
projects/app/src/web/context/ChakraUI.tsx
Normal file
22
projects/app/src/web/context/ChakraUI.tsx
Normal 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;
|
20
projects/app/src/web/context/QueryClient.tsx
Normal file
20
projects/app/src/web/context/QueryClient.tsx
Normal 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;
|
81
projects/app/src/web/context/useInitApp.ts
Normal file
81
projects/app/src/web/context/useInitApp.ts
Normal 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;',
|
||||
`GitHub:https://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
|
||||
};
|
||||
};
|
Reference in New Issue
Block a user