mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-11-17 13:33:45 +00:00
* perf(client): lazy-load query devtools * fix: keep query devtools deps lazy * fix: address query devtools review findings * fix: exclude query devtools from pwa precache --------- Co-authored-by: Danny Avila <danny@librechat.ai>
33 lines
966 B
TypeScript
33 lines
966 B
TypeScript
import { lazy, Suspense } from 'react';
|
|
|
|
interface QueryDevtoolsConfig {
|
|
enableQueryDevtools?: boolean;
|
|
}
|
|
|
|
interface QueryDevtoolsGateProps {
|
|
config?: QueryDevtoolsConfig;
|
|
isDevelopment?: boolean;
|
|
}
|
|
|
|
const LazyReactQueryDevtools = lazy(() =>
|
|
import('@tanstack/react-query-devtools/production').then(({ ReactQueryDevtools }) => ({
|
|
default: ReactQueryDevtools,
|
|
})),
|
|
);
|
|
|
|
export const shouldEnableQueryDevtools = ({
|
|
isDevelopment = import.meta.env.DEV,
|
|
config = typeof window === 'undefined' ? undefined : window.__LIBRECHAT_CONFIG__,
|
|
}: QueryDevtoolsGateProps = {}) => isDevelopment || config?.enableQueryDevtools === true;
|
|
|
|
export default function QueryDevtoolsGate({ isDevelopment, config }: QueryDevtoolsGateProps = {}) {
|
|
if (!shouldEnableQueryDevtools({ isDevelopment, config })) {
|
|
return null;
|
|
}
|
|
|
|
return (
|
|
<Suspense fallback={null}>
|
|
<LazyReactQueryDevtools initialIsOpen={false} position="top-right" />
|
|
</Suspense>
|
|
);
|
|
}
|