Skip to content

Commit e0819c4

Browse files
committed
fix: externalize @tanstack/react-query in build and fix StacApiProvider initialization order
- Add @tanstack/react-query to vite external dependencies to prevent bundling - Refactor StacApiProvider to split into inner/outer components, ensuring QueryClient is available before any React Query hooks execute - Add @tanstack/react-query peer dependency to example app package.json
1 parent 4d0f701 commit e0819c4

File tree

4 files changed

+33
-3
lines changed

4 files changed

+33
-3
lines changed

example/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"dependencies": {
66
"@mapbox/mapbox-gl-draw": "^1.3.0",
77
"@mapbox/mapbox-gl-draw-static-mode": "^1.0.1",
8+
"@tanstack/react-query": "^5.90.10",
89
"@testing-library/jest-dom": "^5.14.1",
910
"@testing-library/react": "^13.0.0",
1011
"@testing-library/user-event": "^13.2.1",

example/yarn.lock

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2474,6 +2474,24 @@ __metadata:
24742474
languageName: node
24752475
linkType: hard
24762476

2477+
"@tanstack/query-core@npm:5.90.10":
2478+
version: 5.90.10
2479+
resolution: "@tanstack/query-core@npm:5.90.10"
2480+
checksum: 10c0/c51762d4413f99886af24d0a4897e286233fae305131df2db8294c26b1375e74e87d0cd7dafbe1b7d23338221fca0304c05058dd9a909c0988a8829d8f7283e6
2481+
languageName: node
2482+
linkType: hard
2483+
2484+
"@tanstack/react-query@npm:^5.90.10":
2485+
version: 5.90.10
2486+
resolution: "@tanstack/react-query@npm:5.90.10"
2487+
dependencies:
2488+
"@tanstack/query-core": "npm:5.90.10"
2489+
peerDependencies:
2490+
react: ^18 || ^19
2491+
checksum: 10c0/a852c44fafb0331a47ba8b46f96bc6c3c66a1bfbec8a09de15fc0ba6fd1b867da42c4974f83489a03cc4d7fd9fa40ec23b8790d2f69a930ca63b85f2bf4a4885
2492+
languageName: node
2493+
linkType: hard
2494+
24772495
"@testing-library/dom@npm:^8.5.0":
24782496
version: 8.13.0
24792497
resolution: "@testing-library/dom@npm:8.13.0"
@@ -5839,6 +5857,7 @@ __metadata:
58395857
dependencies:
58405858
"@mapbox/mapbox-gl-draw": "npm:^1.3.0"
58415859
"@mapbox/mapbox-gl-draw-static-mode": "npm:^1.0.1"
5860+
"@tanstack/react-query": "npm:^5.90.10"
58425861
"@testing-library/jest-dom": "npm:^5.14.1"
58435862
"@testing-library/react": "npm:^13.0.0"
58445863
"@testing-library/user-event": "npm:^13.2.1"

src/context/index.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ type StacApiProviderType = {
1313
queryClient?: QueryClient;
1414
};
1515

16-
export function StacApiProvider({ children, apiUrl, options, queryClient }: StacApiProviderType) {
16+
function StacApiProviderInner({
17+
children,
18+
apiUrl,
19+
options,
20+
}: Omit<StacApiProviderType, 'queryClient'>) {
1721
const { stacApi } = useStacApi(apiUrl, options);
1822
const [collections, setCollections] = useState<CollectionsResponse>();
1923
const [items, setItems] = useState(new Map<string, Item>());
@@ -48,6 +52,10 @@ export function StacApiProvider({ children, apiUrl, options, queryClient }: Stac
4852
[addItem, collections, deleteItem, getItem, stacApi]
4953
);
5054

55+
return <StacApiContext.Provider value={contextValue}>{children}</StacApiContext.Provider>;
56+
}
57+
58+
export function StacApiProvider({ children, apiUrl, options, queryClient }: StacApiProviderType) {
5159
const defaultClient = useMemo(() => new QueryClient(), []);
5260
const client: QueryClient = queryClient ?? defaultClient;
5361

@@ -58,7 +66,9 @@ export function StacApiProvider({ children, apiUrl, options, queryClient }: Stac
5866

5967
return (
6068
<QueryClientProvider client={client}>
61-
<StacApiContext.Provider value={contextValue}>{children}</StacApiContext.Provider>
69+
<StacApiProviderInner apiUrl={apiUrl} options={options}>
70+
{children}
71+
</StacApiProviderInner>
6272
</QueryClientProvider>
6373
);
6474
}

vite.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export default defineConfig({
1212
},
1313
sourcemap: true,
1414
rollupOptions: {
15-
external: ['react', 'react-dom'],
15+
external: ['react', 'react-dom', '@tanstack/react-query'],
1616
},
1717
},
1818
plugins: [

0 commit comments

Comments
 (0)