Skip to content

Commit 5b5411c

Browse files
arbrandesclaude
andcommitted
fix: use dynamic import for ReactQueryDevtools to fix consumer builds
The static import of @tanstack/react-query-devtools caused consumer builds to fail since the package is in devDependencies and not installed by consumers. Replaced with a process.env.NODE_ENV-guarded React.lazy call so the consumer's webpack dead-code-eliminates the import in production builds. Closes #143 Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 290ecc0 commit 5b5411c

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

src/Main.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
1+
import { lazy, Suspense } from 'react';
12
import { CurrentAppProvider, getAppConfig } from '@openedx/frontend-base';
23
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
34
import { Outlet } from 'react-router-dom';
4-
import { ReactQueryDevtools } from '@tanstack/react-query-devtools';
55
import { AlertProvider } from './providers/AlertProvider';
66
import { appId } from './constants';
77
import PageWrapper from './pageWrapper/PageWrapper';
88

99
import './app.scss';
1010

11+
// Use a dynamic import guarded by process.env.NODE_ENV so the consumer's
12+
// webpack dead-code-eliminates this in production builds, meaning
13+
// @tanstack/react-query-devtools does not need to be installed by consumers.
14+
const ReactQueryDevtools = process.env.NODE_ENV === 'development'
15+
? lazy(() => import('@tanstack/react-query-devtools').then((m) => ({ default: m.ReactQueryDevtools })))
16+
: null;
17+
1118
const queryClient = new QueryClient();
1219

1320
const Main = () => (
@@ -18,7 +25,11 @@ const Main = () => (
1825
<PageWrapper>
1926
<Outlet />
2027
</PageWrapper>
21-
{ getAppConfig(appId).NODE_ENV === 'development' && <ReactQueryDevtools initialIsOpen={false} /> }
28+
{ReactQueryDevtools && getAppConfig(appId).NODE_ENV === 'development' && (
29+
<Suspense fallback={null}>
30+
<ReactQueryDevtools initialIsOpen={false} />
31+
</Suspense>
32+
)}
2233
</main>
2334
</AlertProvider>
2435
</QueryClientProvider>

0 commit comments

Comments
 (0)