@osdk/react 2.94.0 → 2.95.0-main-a5bdff2e9db1a01e5858042ee5232cb13c13368a

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.
Files changed (64) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/build/browser/new/platform-apis/admin/useCurrentFoundryUser.js.map +1 -1
  3. package/build/browser/new/platform-apis/admin/useFoundryUser.js.map +1 -1
  4. package/build/browser/new/platform-apis/admin/useFoundryUsersList.js.map +1 -1
  5. package/build/browser/new/useLinks.js.map +1 -1
  6. package/build/browser/new/useObjectSet.js.map +1 -1
  7. package/build/browser/new/useOsdkAggregation.js +2 -5
  8. package/build/browser/new/useOsdkAggregation.js.map +1 -1
  9. package/build/browser/new/useOsdkObjects.js.map +1 -1
  10. package/build/browser/util/UserAgent.js +1 -1
  11. package/build/browser/util/UserAgent.js.map +1 -1
  12. package/build/cjs/{chunk-EJT5W6SI.cjs → chunk-YG7PT4LT.cjs} +3 -3
  13. package/build/cjs/chunk-YG7PT4LT.cjs.map +1 -0
  14. package/build/cjs/index.cjs +15 -15
  15. package/build/cjs/public/experimental.cjs +16 -16
  16. package/build/cjs/public/experimental.d.cts +9 -12
  17. package/build/cjs/public/platform-apis.d.cts +1 -4
  18. package/build/esm/new/platform-apis/admin/useCurrentFoundryUser.js.map +1 -1
  19. package/build/esm/new/platform-apis/admin/useFoundryUser.js.map +1 -1
  20. package/build/esm/new/platform-apis/admin/useFoundryUsersList.js.map +1 -1
  21. package/build/esm/new/useLinks.js.map +1 -1
  22. package/build/esm/new/useObjectSet.js.map +1 -1
  23. package/build/esm/new/useOsdkAggregation.js +2 -5
  24. package/build/esm/new/useOsdkAggregation.js.map +1 -1
  25. package/build/esm/new/useOsdkObjects.js.map +1 -1
  26. package/build/esm/util/UserAgent.js +1 -1
  27. package/build/esm/util/UserAgent.js.map +1 -1
  28. package/build/types/new/platform-apis/admin/useCurrentFoundryUser.d.ts +0 -1
  29. package/build/types/new/platform-apis/admin/useCurrentFoundryUser.d.ts.map +1 -1
  30. package/build/types/new/platform-apis/admin/useFoundryUser.d.ts +1 -2
  31. package/build/types/new/platform-apis/admin/useFoundryUser.d.ts.map +1 -1
  32. package/build/types/new/platform-apis/admin/useFoundryUsersList.d.ts +0 -1
  33. package/build/types/new/platform-apis/admin/useFoundryUsersList.d.ts.map +1 -1
  34. package/build/types/new/useLinks.d.ts +2 -2
  35. package/build/types/new/useObjectSet.d.ts +2 -2
  36. package/build/types/new/useOsdkAggregation.d.ts +3 -6
  37. package/build/types/new/useOsdkAggregation.d.ts.map +1 -1
  38. package/build/types/new/useOsdkObjects.d.ts +2 -2
  39. package/docs/actions.mdx +314 -0
  40. package/docs/aggregations.mdx +256 -0
  41. package/docs/cache-invalidation.mdx +229 -0
  42. package/docs/devtools/cache.mdx +29 -0
  43. package/docs/devtools/components.mdx +40 -0
  44. package/docs/devtools/console.mdx +29 -0
  45. package/docs/devtools/index.mdx +151 -0
  46. package/docs/devtools/overview.mdx +45 -0
  47. package/docs/functions.mdx +246 -0
  48. package/docs/index.mdx +62 -0
  49. package/docs/links.mdx +270 -0
  50. package/docs/meta.json +30 -0
  51. package/docs/object-sets.mdx +296 -0
  52. package/docs/objects.mdx +489 -0
  53. package/docs/optimistic-updates.mdx +164 -0
  54. package/docs/platform-apis.mdx +296 -0
  55. package/docs/testing.mdx +348 -0
  56. package/package.json +7 -7
  57. package/build/cjs/chunk-EJT5W6SI.cjs.map +0 -1
  58. package/docs/actions.md +0 -432
  59. package/docs/advanced-queries.md +0 -678
  60. package/docs/cache-management.md +0 -222
  61. package/docs/getting-started.md +0 -319
  62. package/docs/platform-apis.md +0 -234
  63. package/docs/prerequisites.md +0 -48
  64. package/docs/querying-data.md +0 -810
@@ -0,0 +1,229 @@
1
+ ---
2
+ title: Invalidate the cache
3
+ description: Refetch cached objects, lists, and function results with useObservableClient when data changes outside OSDK actions.
4
+ ---
5
+
6
+ {/* cspell:ignore refetch refetches refetched refetching canonicalization */}
7
+
8
+ Invalidating cached data makes every component that shows it refetch. Most apps rarely need it: the cache updates itself after actions. This page covers the cases it cannot see and the methods that handle them. For how the cache stores and shares data, see [Caching](../(docs)/concepts/caching.mdx).
9
+
10
+ ## When the cache updates itself
11
+
12
+ You do not need to invalidate after:
13
+
14
+ - **Actions applied with `useOsdkAction`.** The server reports which objects the action added, modified, and deleted. The cache refetches those objects, and every list, link, aggregation, and function that depends on their types re-evaluates.
15
+ - **Optimistic updates.** They are removed when the action finishes. See [Optimistic updates](./optimistic-updates.mdx).
16
+ - **Lists with `streamUpdates: true`.** The server pushes changes over a WebSocket.
17
+ - **Functions with `dependsOn` or `dependsOnObjects`.** They rerun after actions edit what they declare. See [Call functions](./functions.mdx#refetch-when-objects-change).
18
+
19
+ ## When to invalidate
20
+
21
+ The cache only learns about changes that pass through it. Invalidate when data changes some other way:
22
+
23
+ - A pipeline, schedule, or external system writes to the ontology.
24
+ - Your code applies an action with the `Client` directly, as in `client(modifyEmployee).applyAction(...)`, instead of through `useOsdkAction`.
25
+ - Another service tells your app, for example over its own WebSocket, that records changed.
26
+ - A function reads data the cache cannot track, and you did not declare `dependsOn`.
27
+
28
+ ## Get the observable client
29
+
30
+ `useObservableClient` returns the `ObservableClient` that `OsdkProvider` created. Call it in a component or hook below the provider, and call the invalidation methods from an event handler or effect:
31
+
32
+ ```tsx title="src/RefreshEmployee.tsx"
33
+ import { Employee } from "@my-app/sdk";
34
+ import { useObservableClient } from "@osdk/react";
35
+ import { useState } from "react";
36
+
37
+ export function RefreshEmployee({ employee }: { employee: Employee.OsdkInstance }) {
38
+ const observableClient = useObservableClient();
39
+ const [isRefreshing, setRefreshing] = useState(false);
40
+
41
+ async function refresh() {
42
+ setRefreshing(true);
43
+ try {
44
+ await observableClient.invalidateObjects(employee);
45
+ } finally {
46
+ setRefreshing(false);
47
+ }
48
+ }
49
+
50
+ return (
51
+ <button disabled={isRefreshing} onClick={() => void refresh()}>
52
+ {isRefreshing ? "Refreshing…" : "Refresh"}
53
+ </button>
54
+ );
55
+ }
56
+ ```
57
+
58
+ ## Invalidation methods
59
+
60
+ | Method | Refetches | Use it when |
61
+ | --- | --- | --- |
62
+ | `invalidateObjects(objects)` | The given object or array of objects, in every variant cached for them. Also reruns functions that list one of them in `dependsOnObjects`, and refreshes links from or to their type. An object that is not cached yet is fetched. | You know exactly which objects changed. |
63
+ | `invalidateObjectType(type)` | Every cached query that reads the type: its objects, lists and object sets over it, aggregations over it, links from or to it, and functions that declare it in `dependsOn`. Takes the type from your SDK or its API name. | Many objects of one type changed, or you do not know which. |
64
+ | `invalidateFunction(fn, params?)` | With `params`, the one cached call with exactly those parameters. Without, every cached call of that function. Takes the function from your SDK or its API name. | A function's inputs changed outside the cache. |
65
+ | `invalidateFunctionsByObject(apiName, primaryKey)` | Functions that list that object in `dependsOnObjects`. | One object changed and you only want its functions to rerun. |
66
+ | `invalidateAll()` | Everything in the cache. | Last resort, when you cannot tell what changed. |
67
+
68
+ All methods return a promise that resolves when the refetches have settled. The promise does not reject: a failed refetch shows up as `error` on the hooks that read the data. While a refetch runs, those hooks keep their current data and report `isLoading: true`.
69
+
70
+ ## Examples
71
+
72
+ ### After an external write
73
+
74
+ A component that starts a server-side job, then refreshes the type the job writes to once it finishes:
75
+
76
+ ```tsx title="src/ImportEmployeesButton.tsx"
77
+ import { Employee } from "@my-app/sdk";
78
+ import { useObservableClient } from "@osdk/react";
79
+ import { useState } from "react";
80
+ import { runEmployeeImport } from "./api";
81
+
82
+ export function ImportEmployeesButton() {
83
+ const observableClient = useObservableClient();
84
+ const [status, setStatus] = useState<"idle" | "running" | "failed">("idle");
85
+
86
+ async function handleImport() {
87
+ setStatus("running");
88
+ try {
89
+ await runEmployeeImport();
90
+ await observableClient.invalidateObjectType(Employee);
91
+ setStatus("idle");
92
+ } catch (e) {
93
+ console.error("Import failed", e);
94
+ setStatus("failed");
95
+ }
96
+ }
97
+
98
+ return (
99
+ <div>
100
+ <button disabled={status === "running"} onClick={() => void handleImport()}>
101
+ Import employees
102
+ </button>
103
+ {status === "failed" && <p role="alert">The import failed.</p>}
104
+ </div>
105
+ );
106
+ }
107
+ ```
108
+
109
+ ### After a direct client call
110
+
111
+ When you apply an action with the `Client`, invalidate what it edited. Ask for the edits with `$returnEdits` and invalidate by type:
112
+
113
+ ```tsx title="src/useUpdateJobTitle.ts"
114
+ import { Employee, modifyEmployee } from "@my-app/sdk";
115
+ import { useObservableClient, useOsdkClient } from "@osdk/react";
116
+ import { useCallback } from "react";
117
+
118
+ export function useUpdateJobTitle() {
119
+ const client = useOsdkClient();
120
+ const observableClient = useObservableClient();
121
+
122
+ return useCallback(
123
+ async (employee: Employee.OsdkInstance, jobTitle: string) => {
124
+ const edits = await client(modifyEmployee).applyAction(
125
+ { employee, jobTitle },
126
+ { $returnEdits: true },
127
+ );
128
+ await Promise.all(
129
+ edits.editedObjectTypes.map((type) =>
130
+ observableClient.invalidateObjectType(String(type)),
131
+ ),
132
+ );
133
+ },
134
+ [client, observableClient],
135
+ );
136
+ }
137
+ ```
138
+
139
+ `useOsdkAction` does this for you, and more precisely, so prefer it. See [Apply actions](./actions.mdx).
140
+
141
+ ### Refresh a function
142
+
143
+ ```tsx title="src/RefreshMetrics.tsx"
144
+ import { getEmployeeMetrics } from "@my-app/sdk";
145
+ import { useObservableClient } from "@osdk/react";
146
+
147
+ export function RefreshMetrics({ department }: { department: string }) {
148
+ const observableClient = useObservableClient();
149
+
150
+ return (
151
+ <div>
152
+ <button
153
+ onClick={() =>
154
+ void observableClient.invalidateFunction(getEmployeeMetrics, { department })
155
+ }
156
+ >
157
+ Refresh this department
158
+ </button>
159
+ <button onClick={() => void observableClient.invalidateFunction(getEmployeeMetrics)}>
160
+ Refresh all departments
161
+ </button>
162
+ </div>
163
+ );
164
+ }
165
+ ```
166
+
167
+ For a single call site, `refetch` from `useOsdkFunction` does the same as `invalidateFunction` with that call's parameters.
168
+
169
+ ### Refresh when another service notifies you
170
+
171
+ Subscribe in an effect and invalidate when a message arrives. `invalidateObjects` needs an object instance, so with only a primary key, invalidate the type, and rerun the functions bound to that one object with `invalidateFunctionsByObject`:
172
+
173
+ ```tsx title="src/useEmployeeChangeFeed.ts"
174
+ import { Employee } from "@my-app/sdk";
175
+ import { useObservableClient } from "@osdk/react";
176
+ import { useEffect } from "react";
177
+
178
+ export function useEmployeeChangeFeed(url: string) {
179
+ const observableClient = useObservableClient();
180
+
181
+ useEffect(() => {
182
+ const socket = new WebSocket(url);
183
+ socket.addEventListener("message", (event) => {
184
+ const { employeeId } = JSON.parse(String(event.data)) as { employeeId: number };
185
+ void observableClient.invalidateFunctionsByObject(Employee.apiName, employeeId);
186
+ void observableClient.invalidateObjectType(Employee);
187
+ });
188
+ return () => socket.close();
189
+ }, [observableClient, url]);
190
+ }
191
+ ```
192
+
193
+ ## Best practices
194
+
195
+ 1. **Let actions drive updates.** If a change comes from `useOsdkAction`, do not invalidate afterward. It refetches data that is already fresh.
196
+ 2. **Invalidate the narrowest thing you can.** `invalidateObjects` is cheaper than `invalidateObjectType`, which is cheaper than `invalidateAll`.
197
+ 3. **Declare function dependencies.** `dependsOn` and `dependsOnObjects` let the cache rerun functions after actions, so you do not invalidate them by hand.
198
+ 4. **Do not invalidate on mount.** Calling `invalidateAll` or `invalidateObjectType` in a mount effect refetches on every navigation and defeats the cache.
199
+ 5. **Keep OSDK data in the cache.** Copying it into component state, Redux, or another query library creates a second copy that invalidation and optimistic updates do not reach.
200
+
201
+ ## Debug the cache
202
+
203
+ The `devMode` prop on `OsdkProvider` turns on logging in development builds. It has no effect in production builds.
204
+
205
+ ```tsx title="src/main.tsx"
206
+ import { OsdkProvider } from "@osdk/react";
207
+ import { client } from "./client";
208
+ import { App } from "./App";
209
+
210
+ export function Root() {
211
+ return (
212
+ <OsdkProvider
213
+ client={client}
214
+ devMode={{ logLevel: "debug", debug: { refCounts: true, cacheKeys: true } }}
215
+ >
216
+ <App />
217
+ </OsdkProvider>
218
+ );
219
+ }
220
+ ```
221
+
222
+ | Option | Type | Default | Description |
223
+ | --- | --- | --- | --- |
224
+ | `logLevel` | `"trace" \| "debug" \| "info" \| "warn" \| "error" \| "fatal"` | `"error"` | Log level for the observable client. Set `"debug"` to see its tracing. |
225
+ | `debug.refCounts` | `boolean` | `false` | Logs when cache entries are created, referenced, and cleaned up, and shortens how long unused entries are kept so cleanup happens sooner. |
226
+ | `debug.cacheKeys` | `boolean` | `false` | Logs cache-key lookups and whether each key already existed. |
227
+ | `actionDelayMs` | `number` | `1000` | Delay before optimistic updates are removed. See [Optimistic updates](./optimistic-updates.mdx#simulate-latency-in-development). |
228
+
229
+ To browse cache entries in the running app instead, use [OSDK Devtools](/devtools).
@@ -0,0 +1,29 @@
1
+ ---
2
+ title: Cache
3
+ description: Use the Cache tab in OSDK Devtools to inspect and invalidate observable cache entries and review recent cache hits and misses.
4
+ ---
5
+
6
+ The Cache tab shows the entries in the `@osdk/react` observable cache and a timeline of recent cache hits and misses. Use it to confirm that a repeated read came from the cache, or to see when a read went to the network. For how the cache works, see [Caching](../../(docs)/concepts/caching.mdx).
7
+
8
+ ![Cache tab](/img/react-devtools/cache.png)
9
+
10
+ ## Cache inspector
11
+
12
+ The summary shows the number of entries and their estimated total size. **Search cache** matches cache keys, object types, and entry types.
13
+
14
+ Each entry header shows its status (`init`, `loading`, `loaded`, or `error`), age, and estimated size. Expand an entry to see its cache key, current value, and query details.
15
+
16
+ | Control | Effect |
17
+ | --- | --- |
18
+ | **Refresh** | Reloads the inspector snapshot. It does not refetch data. |
19
+ | Refresh icon on an object entry | Invalidates that object. |
20
+ | Refresh icon on a list, link, or object set entry | Invalidates every entry for that object type. |
21
+ | **Clear cache** | After you confirm, invalidates the whole cache. Active queries refetch. |
22
+
23
+ ## Cache history
24
+
25
+ Cache history lists the 50 most recent cache hits (✓) and misses (×), newest first. Each row shows the query or object signature, how long ago it happened, and the response time when one was recorded. **Reset metrics** clears it.
26
+
27
+ ## Related metrics
28
+
29
+ Requests saved, Cache hit rate, and Avg response time on [Overview](./overview.mdx) summarize the same operations. Select **View in Cache** under Cache hit rate to move from the metric to the entries behind it.
@@ -0,0 +1,40 @@
1
+ ---
2
+ title: Components
3
+ description: Use the Components tab in OSDK Devtools to find which React components call OSDK hooks and what objects, actions, and properties they use.
4
+ ---
5
+
6
+ The Components tab maps `@osdk/react` hooks to the React components that mounted them. Use it to find the component that owns a query, compare components that read the same object type, or trace an overfetching recommendation back to its source.
7
+
8
+ ![Components tab](/img/react-devtools/components.png)
9
+
10
+ ## What appears
11
+
12
+ Only components that call an `@osdk/react` hook, such as `useOsdkObject` or `useOsdkObjects`, appear. A component that only renders an OSDK-aware child like `ObjectTable`, or receives objects through props, does not appear; look for the child that owns the hook instead. Data loaded with raw network calls or another state library is not tracked.
13
+
14
+ Component attribution relies on the Fiber hook that the Vite plugin installs before React loads. If the panel shows a **DevTools Hook Not Installed** notice, see [Troubleshooting](./index.mdx#troubleshooting).
15
+
16
+ ## Find a component
17
+
18
+ - **Search ontology** matches component names, object types, primary keys, actions, and property names.
19
+ - The summary line counts mounted components, object types, and action types.
20
+ - The filter chips narrow the list to one object type or action. Select **All** to clear the filter.
21
+
22
+ ## Component cards
23
+
24
+ Each card groups what the monitor observed for one component:
25
+
26
+ | Section | Contents |
27
+ | --- | --- |
28
+ | Related objects | Object types the component's hooks load, with the primary keys of instances whose properties were read. |
29
+ | Related actions | Actions the component binds with `useOsdkAction`. |
30
+ | Related properties | Properties read on objects the component's hooks returned, by the component or by children it passed them to. |
31
+ | React props | Props captured from the mounted component. |
32
+
33
+ ## Health badge
34
+
35
+ A card shows **Healthy** unless the monitor detects a problem. After a component has rendered more than five times, the monitor flags:
36
+
37
+ - Wasted renders: renders in which the component read no tracked property.
38
+ - Properties read fewer times than 10% of the component's render count.
39
+
40
+ An unhealthy card replaces the badge with a summary such as `3 wasted · over-fetch 2`.
@@ -0,0 +1,29 @@
1
+ ---
2
+ title: Console
3
+ description: Use the Console tab in OSDK Devtools to search and filter browser console output captured while your OSDK React app runs.
4
+ ---
5
+
6
+ The Console tab captures browser console output from page load, whether the panel is open or minimized, and keeps it as you navigate within the app. A full reload clears it. Use it to match an Errors & warnings count on [Overview](./overview.mdx) to the original message, or to keep a brief warning visible after the page changes.
7
+
8
+ ![Console tab](/img/react-devtools/console.png)
9
+
10
+ ## Search and filter
11
+
12
+ - **Filter logs** searches the serialized arguments of each entry.
13
+ - The level menu shows all entries, or only `log`, `info`, `warn`, `error`, or `debug`.
14
+ - **Clear logs**, in the same menu, empties the feed. It does not reset the other devtools metrics.
15
+
16
+ The toolbar shows counts for errors, warnings, and other entries. When a search or level filter hides entries, it also shows how many are hidden.
17
+
18
+ ## Log entries
19
+
20
+ Each entry shows its level, timestamp, arguments, and source location when the browser provides one. Objects and errors are serialized with depth and size limits, so a large payload cannot take over the panel. The tab omits the OSDK client's own debug logging and duplicate errors re-emitted by the React DevTools extension.
21
+
22
+ ## Limits
23
+
24
+ | Limit | Value |
25
+ | --- | --- |
26
+ | Entries stored | 1,000 most recent |
27
+ | Entries rendered | 200 most recent that match the current search and level |
28
+
29
+ Narrow the search or level filter to bring an older matching entry back into the rendered list.
@@ -0,0 +1,151 @@
1
+ ---
2
+ title: OSDK Devtools
3
+ description: Add an in-app panel that shows Ontology usage, hook owners, console output, and the observable cache of a running OSDK React app.
4
+ ---
5
+
6
+ `@osdk/react-devtools` adds a panel to your `@osdk/react` app during development. Use it to see which components own OSDK hooks, how often reads hit the cache, and what your app logs to the console.
7
+
8
+ <Callout type="warn">
9
+ `@osdk/react-devtools` is in beta. Its panels and metrics can change between minor versions.
10
+ </Callout>
11
+
12
+ ## Set up the panel
13
+
14
+ <Steps>
15
+ <Step>
16
+
17
+ ### Install the package
18
+
19
+ Add `@osdk/react-devtools` as a dev dependency:
20
+
21
+ ```npm
22
+ npm install -D @osdk/react-devtools
23
+ ```
24
+
25
+ The package has peer dependencies on `@osdk/api`, `@osdk/client`, `@osdk/react`, `react`, `react-dom`, `@types/react`, and, optionally, `vite` 5, 6, or 7. An app created with `@osdk/create-app` has all of these except `@osdk/api`, which comes in through `@osdk/client`.
26
+
27
+ </Step>
28
+ <Step>
29
+
30
+ ### Add the Vite plugin
31
+
32
+ Import `osdkDevTools` from `@osdk/react-devtools/vite` and add it to `plugins`:
33
+
34
+ ```ts title="vite.config.ts"
35
+ import { osdkDevTools } from "@osdk/react-devtools/vite";
36
+ import react from "@vitejs/plugin-react";
37
+ import { defineConfig } from "vite";
38
+
39
+ export default defineConfig({
40
+ plugins: [react(), osdkDevTools()],
41
+ });
42
+ ```
43
+
44
+ `osdkDevTools` is also the default export of `@osdk/react-devtools/vite`.
45
+
46
+ </Step>
47
+ <Step>
48
+
49
+ ### Keep your existing provider
50
+
51
+ You do not add any JSX. During `vite dev`, the plugin injects two scripts into `index.html`: one that installs a React Fiber hook, and one that imports the panel:
52
+
53
+ ```html
54
+ <script type="module">import '@osdk/react-devtools';</script>
55
+ ```
56
+
57
+ The import registers the devtools with `@osdk/react`. Your existing `OsdkProvider` then wraps its client with the monitor and renders the panel:
58
+
59
+ ```tsx title="src/main.tsx"
60
+ import { OsdkProvider } from "@osdk/react";
61
+ import ReactDOM from "react-dom/client";
62
+ import App from "./App.js";
63
+ import { client } from "./client.js";
64
+
65
+ ReactDOM.createRoot(document.getElementById("root")!).render(
66
+ <OsdkProvider client={client}>
67
+ <App />
68
+ </OsdkProvider>,
69
+ );
70
+ ```
71
+
72
+ </Step>
73
+ <Step>
74
+
75
+ ### Start the dev server
76
+
77
+ Run your dev script, for example `npm run dev`. The panel opens in the top right corner of the page on the Overview tab.
78
+
79
+ </Step>
80
+ </Steps>
81
+
82
+ ## Plugin options
83
+
84
+ All options are optional.
85
+
86
+ | Option | Type | Default | Description |
87
+ | --- | --- | --- | --- |
88
+ | `enabled` | `boolean` | `true` unless `NODE_ENV` is `"production"` | Set to `false` to keep the plugin in your config without injecting the panel. |
89
+ | `verbose` | `boolean` | `false` | Logs plugin diagnostics in the terminal, including whether the scripts were injected into `index.html`, and hook-installation messages in the browser console. |
90
+
91
+ ```ts title="vite.config.ts"
92
+ osdkDevTools({ enabled: true, verbose: true });
93
+ ```
94
+
95
+ ## Open and arrange the panel
96
+
97
+ Select **Minimize** in the panel header to collapse it to a `</>` launcher in the bottom right corner. Select the launcher to reopen the panel.
98
+
99
+ ![Collapsed OSDK Devtools launcher](/img/react-devtools/launcher.png)
100
+
101
+ The header controls apply to every tab:
102
+
103
+ | Control | What it does |
104
+ | --- | --- |
105
+ | Theme | Cycles through dark (the default), light, and auto, which follows your system setting. |
106
+ | Dock mode | Cycles through floating, docked to the bottom, and docked to the right. |
107
+ | Reset metrics | Clears the request, cache, and action metrics and the cache history. It does not clear console logs, change app data, or touch the cache. |
108
+ | Minimize | Collapses the panel to the `</>` launcher. |
109
+
110
+ Drag the header to move a floating panel, and drag an edge or corner to resize it. The panel saves its position, size, theme, dock mode, and collapsed state in `localStorage`, so they survive reloads.
111
+
112
+ ## Tabs
113
+
114
+ | Tab | Use it to |
115
+ | --- | --- |
116
+ | [Overview](./overview.mdx) | See Ontology usage, requests saved, cache hit rate, optimistic coverage, errors, overfetching, and recommendations. |
117
+ | [Components](./components.mdx) | Find which React components call OSDK hooks and which object types, actions, and properties they use. |
118
+ | [Console](./console.mdx) | Search and filter captured console output by level. |
119
+ | [Cache](./cache.mdx) | Inspect cache entries, invalidate them, and review recent cache hits and misses. |
120
+
121
+ ## How collection works
122
+
123
+ The panel observes the app you already run. It does not send its own requests.
124
+
125
+ - **Requests and cache.** The devtools wrap the observable client that `OsdkProvider` creates and record the cache reads, network requests, and actions that pass through it. Data you load with raw `fetch`, `axios`, or another state library does not appear.
126
+ - **Components.** The injected Fiber hook attributes each `@osdk/react` hook to the component that mounted it. The hook must install before React loads. If React loads first, the panel still works but shows a **DevTools Hook Not Installed** notice and component attribution is limited.
127
+ - **Console.** The monitor captures `console` calls from page load, whether the panel is open or minimized.
128
+
129
+ Use **Reset metrics** before the flow you want to inspect to start from zero.
130
+
131
+ ## Production builds
132
+
133
+ The plugin applies only to `vite dev` and `vite serve`. It does nothing during `vite build`, in `production` mode, or under Vitest, so the panel does not ship to users. To turn it off during development, do one of the following:
134
+
135
+ - Pass `osdkDevTools({ enabled: false })`.
136
+ - Pass `enableDevTools={false}` to `OsdkProvider`.
137
+ - Remove `osdkDevTools()` from `plugins`.
138
+ - Uninstall `@osdk/react-devtools`.
139
+
140
+ ## Compatibility
141
+
142
+ Use compatible versions of `@osdk/react-devtools` and your other `@osdk/*` packages. Mismatched versions can behave unexpectedly. See [Installation](../../(docs)/installation.mdx) for how to keep OSDK packages in sync.
143
+
144
+ ## Troubleshooting
145
+
146
+ | Symptom | Check |
147
+ | --- | --- |
148
+ | The panel does not appear. | Confirm `osdkDevTools()` is in `plugins`, `enabled` is not `false`, and you run `vite dev`. Set `verbose: true` and look for `Injected devtools into HTML` in the terminal. Your `index.html` needs a `</head>` or `</body>` tag. |
149
+ | The panel appears but shows no data. | Confirm the app renders `OsdkProvider` and the screen reads data through `@osdk/react` hooks. |
150
+ | The panel shows **DevTools Hook Not Installed** or **Fiber Access Unavailable**. | Something loaded React before the injected script. Remove manual imports or scripts in `index.html` that load React ahead of it. |
151
+ | The panel appears in a deployed build. | Look for code that imports `@osdk/react-devtools` directly, or a stale development bundle on the server. |
@@ -0,0 +1,45 @@
1
+ ---
2
+ title: Overview
3
+ description: Read the Overview tab in OSDK Devtools to check Ontology usage, cache hit rate, optimistic coverage, errors, overfetching, and recommendations.
4
+ ---
5
+
6
+ {/* cspell:ignore revalidations */}
7
+
8
+ The Overview tab is the first tab the panel shows. It summarizes how the mounted components use the Ontology and how the client has performed since the page loaded or since you last selected **Reset metrics**.
9
+
10
+ ![Overview tab](/img/react-devtools/overview.png)
11
+
12
+ ## Ontology
13
+
14
+ Counts the distinct object types, action types, and links that mounted components use. If no component uses the Ontology yet, the section says so and links to these docs.
15
+
16
+ ## Metrics
17
+
18
+ | Metric | What it measures | Highlighted when |
19
+ | --- | --- | --- |
20
+ | Requests saved | Reads served from the cache, revalidations, and deduplicated requests that did not reach the network. | Never |
21
+ | Optimistic coverage | Share of actions that updated the UI before the server responded. See [Optimistic updates](../optimistic-updates.mdx). | Never |
22
+ | Cache hit rate | Share of object reads, including revalidations, served from the cache. Shows `N/A` until the session has 20 reads. | Green above 70%, amber above 40% up to 70%, red at 40% or below |
23
+ | Avg response time | Average response time across cache and network reads. Cache reads typically take under 1 ms, so network reads dominate. | Never |
24
+ | Errors & warnings | `console.error` and `console.warn` entries captured this session. | Red when above 0 |
25
+ | Overfetching | Mounted `@osdk/react` hooks whose fetched fields are mostly unread. A hook counts when less than 70% of its fetched fields are read. | Red when above 0 |
26
+
27
+ Optimistic coverage shows `N/A` until 3 actions have run, and Avg response time until 5 reads.
28
+
29
+ Select the help icon on a metric for its definition and thresholds. Three metrics link to the tab with the detail behind them:
30
+
31
+ | Metric | Link | Opens |
32
+ | --- | --- | --- |
33
+ | Cache hit rate | **View in Cache** | [Cache](./cache.mdx) |
34
+ | Errors & warnings | **View in Console** | [Console](./console.mdx) |
35
+ | Overfetching | **View in Components** | [Components](./components.mdx) |
36
+
37
+ ## Recommendations
38
+
39
+ Recommendations turn the metrics and component observations into specific fixes, such as a query that fetches unused fields. Each has a **Copy fix prompt** button that copies a prompt you can paste into a coding assistant, and a **Dismiss** button. **Copy all** copies the prompts for every recommendation. With nothing to suggest, the section reads `No recommendations right now.`
40
+
41
+ ## Measure one flow
42
+
43
+ 1. Select **Reset metrics** in the panel header. This clears Requests saved, Optimistic coverage, Cache hit rate, Avg response time, and Cache history, without touching app data or the cache. To also zero Errors & warnings, select **Clear logs** on the Console tab. Dismiss recommendations you have already handled.
44
+ 2. Run the flow you want to measure in your app.
45
+ 3. Read the metrics for that flow. Overfetching and Ontology always reflect the components mounted now.