Skip to content

Commit 6f5713d

Browse files
committed
fix: make DevTools opt-in to avoid conflicts with consuming apps
- Add enableDevTools prop to StacApiProvider (defaults to false) - Remove automatic DevTools exposure in development mode - Make window.__TANSTACK_QUERY_CLIENT__ optional to prevent type conflicts - Update example app to enable DevTools in development This prevents the library from overwriting QueryClient instances in consuming applications while still allowing opt-in DevTools support.
1 parent 9f30e60 commit 6f5713d

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

example/src/App.jsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ import Main from './pages/Main';
44

55
function App() {
66
const apiUrl = process.env.REACT_APP_STAC_API;
7+
const isDevelopment = process.env.NODE_ENV === 'development';
8+
79
return (
8-
<StacApiProvider apiUrl={apiUrl}>
10+
<StacApiProvider apiUrl={apiUrl} enableDevTools={isDevelopment}>
911
<div className="App grid grid-rows-[min-content_1fr]">
1012
<Header />
1113
<main className="flex items-stretch">

src/context/index.tsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ type StacApiProviderType = {
1111
children: React.ReactNode;
1212
options?: GenericObject;
1313
queryClient?: QueryClient;
14+
enableDevTools?: boolean;
1415
};
1516

1617
function StacApiProviderInner({
@@ -55,11 +56,17 @@ function StacApiProviderInner({
5556
return <StacApiContext.Provider value={contextValue}>{children}</StacApiContext.Provider>;
5657
}
5758

58-
export function StacApiProvider({ children, apiUrl, options, queryClient }: StacApiProviderType) {
59+
export function StacApiProvider({
60+
children,
61+
apiUrl,
62+
options,
63+
queryClient,
64+
enableDevTools,
65+
}: StacApiProviderType) {
5966
const defaultClient = useMemo(() => new QueryClient(), []);
6067
const client: QueryClient = queryClient ?? defaultClient;
6168

62-
if (typeof window !== 'undefined' && process.env.NODE_ENV === 'development') {
69+
if (enableDevTools && typeof window !== 'undefined') {
6370
// Connect TanStack Query DevTools (browser extension)
6471
window.__TANSTACK_QUERY_CLIENT__ = client;
6572
}
@@ -75,6 +82,6 @@ export function StacApiProvider({ children, apiUrl, options, queryClient }: Stac
7582

7683
declare global {
7784
interface Window {
78-
__TANSTACK_QUERY_CLIENT__: import('@tanstack/query-core').QueryClient;
85+
__TANSTACK_QUERY_CLIENT__?: import('@tanstack/query-core').QueryClient;
7986
}
8087
}

0 commit comments

Comments
 (0)