@buoy-gg/react-query 7.0.29 → 7.0.31

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -60,6 +60,12 @@ export { QueryDebugInfo } from "./react-query/components/QueryDebugInfo";
60
60
  export { WifiToggle } from "./react-query/components/WifiToggle";
61
61
  export { ReactQuerySection } from "./react-query/components/ReactQuerySection";
62
62
  export { ReactQueryDevToolsModal } from "./react-query/components/ReactQueryDevToolsModal";
63
+ /**
64
+ * Connects the event store to the app's QueryClient at startup. Auto-rendered
65
+ * by `FloatingDevTools`; exported so a host that does not use the floating menu
66
+ * can mount it itself.
67
+ */
68
+ export { ReactQueryTracker } from "./react-query/components/ReactQueryTracker";
63
69
 
64
70
  // Shared data viewer components
65
71
  export { VirtualizedDataExplorer, DataViewer, TypeLegend } from "@buoy-gg/shared-ui/dataViewer";
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+
3
+ import { useContext, useEffect } from "react";
4
+ import { QueryClientContext } from "@tanstack/react-query";
5
+ import { reactQueryEventStore } from "../stores/reactQueryEventStore";
6
+
7
+ /**
8
+ * Connects the React Query event store to the app's QueryClient at startup.
9
+ *
10
+ * Auto-rendered by `FloatingDevTools` (the same treatment `RouteTracker` gets),
11
+ * so nobody has to mount it by hand.
12
+ *
13
+ * Why it has to exist: until this, `setQueryClient` was called from exactly one
14
+ * place — `ReactQueryDevToolsModal`'s mount effect — which meant the store had
15
+ * no client unless somebody opened the React Query TOOL. Anything else that
16
+ * consumes these events was therefore silently empty, and the Events timeline
17
+ * showed a React Query badge with a confident `0` on it: not "nothing to
18
+ * report" but "nobody was listening", and no way to tell the two apart.
19
+ *
20
+ * `useContext(QueryClientContext)`, NOT `useQueryClient()`: the hook throws
21
+ * when there is no provider above it, and this component is mounted whether or
22
+ * not the host app uses React Query at all. An app without a provider just
23
+ * reads `undefined` here and nothing connects, which is the old behaviour.
24
+ */
25
+ export function ReactQueryTracker() {
26
+ const queryClient = useContext(QueryClientContext);
27
+ useEffect(() => {
28
+ if (!queryClient) return;
29
+ // The tool connects the same client when it opens; leave that alone rather
30
+ // than tearing down its cache subscriptions and rebuilding them.
31
+ if (reactQueryEventStore.isConnected()) return;
32
+ reactQueryEventStore.setQueryClient(queryClient);
33
+ }, [queryClient]);
34
+ return null;
35
+ }