@nkzw/fate-indexeddb 2.0.0 → 2.1.0
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.
- package/README.md +139 -0
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -759,6 +759,29 @@ fate.hydrate(loaderData.fate, { merge: 'replace' });
|
|
|
759
759
|
|
|
760
760
|
Snapshots from different hydration scopes cannot be combined. Keep each user's server client and snapshot separate.
|
|
761
761
|
|
|
762
|
+
#### Selective Hydration in React
|
|
763
|
+
|
|
764
|
+
If your server-rendered app uses Suspense boundaries that can hydrate at different times, pass the original snapshot to the React provider as well:
|
|
765
|
+
|
|
766
|
+
```tsx
|
|
767
|
+
const state = loaderData.fate;
|
|
768
|
+
const fate = createFateClient();
|
|
769
|
+
fate.hydrate(state);
|
|
770
|
+
|
|
771
|
+
hydrateRoot(
|
|
772
|
+
document,
|
|
773
|
+
<FateClient client={fate} hydrationState={state}>
|
|
774
|
+
<App />
|
|
775
|
+
</FateClient>,
|
|
776
|
+
);
|
|
777
|
+
```
|
|
778
|
+
|
|
779
|
+
If the live cache changes before a boundary hydrates, that boundary first reads the original snapshot to match its server HTML. Once it hydrates, it reads the live cache and applies any changes. Request policies that fetch from the network resume after the component hydrates.
|
|
780
|
+
|
|
781
|
+
Keep the same snapshot on the provider for the lifetime of the hydrated tree. The provider retains a separate copy of the server cache so delayed boundaries can still read it. This works with preloaded SSR data that covers the rendered content.
|
|
782
|
+
|
|
783
|
+
The snapshot applies to the React request and view hooks. If you pass an explicit client to a view hook, an enclosing provider for that client supplies its snapshot. Direct reads from the client or its store still read the live cache.
|
|
784
|
+
|
|
762
785
|
### Observing Request State
|
|
763
786
|
|
|
764
787
|
Outside React or Vue components, `fate.observeRequest(request, options)` provides request state through `getSnapshot()` and `subscribe(listener)`:
|
|
@@ -2153,6 +2176,122 @@ Use Vue refs or your application state library to track pending and error state.
|
|
|
2153
2176
|
|
|
2154
2177
|
Views, requests, caching, and mutations work the same way in both adapters. Vue composables return reactive resources; await `ready()` to use Suspense, or read their pending and error state. For mutations, use `fate.mutations` and Vue refs for local state instead of React Actions.
|
|
2155
2178
|
|
|
2179
|
+
## Devtools
|
|
2180
|
+
|
|
2181
|
+
_fate_ comes with devtools that show what your client is doing while you build your app. They run as a panel in [Vite DevTools](https://devtools.vite.dev/), next to the other tools for your app.
|
|
2182
|
+
|
|
2183
|
+
<p align="center">
|
|
2184
|
+
<img alt="The fate devtools panel in Vite DevTools" src="/public/devtools.png#gh-light-mode-only" width="100%">
|
|
2185
|
+
<img alt="The fate devtools panel in Vite DevTools" src="/public/devtools-dark.png#gh-dark-mode-only" width="100%">
|
|
2186
|
+
</p>
|
|
2187
|
+
|
|
2188
|
+
The panel shows:
|
|
2189
|
+
|
|
2190
|
+
- **Cache:** every normalized record, grouped by type. For each record you can see the fields fate has loaded, which fields are stale, which lists contain it, and which records refer to it. Click a reference to jump to that record.
|
|
2191
|
+
- **Requests:** the requests your screens keep alive, their roots and arguments, the fields they select, and how many components are observing them.
|
|
2192
|
+
- **Network:** every call fate makes through its transport (`byId`, `list`, `query`, mutations, and live subscriptions), with timing, selections, arguments, and responses or errors.
|
|
2193
|
+
- **Lists:** connection and list state, including items, cursors, and pagination.
|
|
2194
|
+
- **Changes:** a log of cache writes, including invalidations and optimistic updates.
|
|
2195
|
+
|
|
2196
|
+
From the panel you can invalidate or remove a record, log a record to the browser console (as `$fate`), and run garbage collection.
|
|
2197
|
+
|
|
2198
|
+
### Installation
|
|
2199
|
+
|
|
2200
|
+
Install the devtools and Vite DevTools as development dependencies of your client:
|
|
2201
|
+
|
|
2202
|
+
::: code-group
|
|
2203
|
+
|
|
2204
|
+
```bash [npm]
|
|
2205
|
+
npm add -D @nkzw/fate-devtools @vitejs/devtools
|
|
2206
|
+
```
|
|
2207
|
+
|
|
2208
|
+
```bash [pnpm]
|
|
2209
|
+
pnpm add -D @nkzw/fate-devtools @vitejs/devtools
|
|
2210
|
+
```
|
|
2211
|
+
|
|
2212
|
+
```bash [yarn]
|
|
2213
|
+
yarn add -D @nkzw/fate-devtools @vitejs/devtools
|
|
2214
|
+
```
|
|
2215
|
+
|
|
2216
|
+
:::
|
|
2217
|
+
|
|
2218
|
+
### Vite Plugin
|
|
2219
|
+
|
|
2220
|
+
Enable Vite DevTools and add the devtools plugin to your Vite config:
|
|
2221
|
+
|
|
2222
|
+
```ts
|
|
2223
|
+
import { fateDevtools } from '@nkzw/fate-devtools/vite';
|
|
2224
|
+
import { fate } from 'react-fate/vite';
|
|
2225
|
+
import { defineConfig } from 'vite';
|
|
2226
|
+
|
|
2227
|
+
export default defineConfig({
|
|
2228
|
+
devtools: true,
|
|
2229
|
+
plugins: [
|
|
2230
|
+
fate({
|
|
2231
|
+
module: '@your-org/server/trpc/router.ts',
|
|
2232
|
+
}),
|
|
2233
|
+
fateDevtools(),
|
|
2234
|
+
],
|
|
2235
|
+
});
|
|
2236
|
+
```
|
|
2237
|
+
|
|
2238
|
+
The plugin only runs during development. It adds a _fate_ entry to the Vite DevTools dock and serves the panel at `/__fate-devtools/`. You can also open that URL in its own tab, which is handy when you don't use Vite DevTools or want the panel on a second screen.
|
|
2239
|
+
|
|
2240
|
+
### Connecting a Client
|
|
2241
|
+
|
|
2242
|
+
With React, render `<FateDevtools />` inside your `<FateClient>`. It connects the client from context and renders nothing:
|
|
2243
|
+
|
|
2244
|
+
```tsx
|
|
2245
|
+
import { FateDevtools } from '@nkzw/fate-devtools/react';
|
|
2246
|
+
import { FateClient } from 'react-fate';
|
|
2247
|
+
|
|
2248
|
+
export function App() {
|
|
2249
|
+
return (
|
|
2250
|
+
<FateClient client={fate}>
|
|
2251
|
+
{import.meta.env.DEV && <FateDevtools />}
|
|
2252
|
+
<Root />
|
|
2253
|
+
</FateClient>
|
|
2254
|
+
);
|
|
2255
|
+
}
|
|
2256
|
+
```
|
|
2257
|
+
|
|
2258
|
+
For Vue or other setups, call `connectFateDevtools` with your client. It returns a function that disconnects the client again:
|
|
2259
|
+
|
|
2260
|
+
```ts
|
|
2261
|
+
import { connectFateDevtools } from '@nkzw/fate-devtools';
|
|
2262
|
+
|
|
2263
|
+
if (import.meta.env.DEV) {
|
|
2264
|
+
connectFateDevtools(fate);
|
|
2265
|
+
}
|
|
2266
|
+
```
|
|
2267
|
+
|
|
2268
|
+
Guard the devtools with `import.meta.env.DEV` so they are not included in production builds. If your app creates more than one client, pass a `name` to tell them apart in the panel:
|
|
2269
|
+
|
|
2270
|
+
```tsx
|
|
2271
|
+
<FateDevtools name="admin" />
|
|
2272
|
+
```
|
|
2273
|
+
|
|
2274
|
+
### Server-Rendered Apps
|
|
2275
|
+
|
|
2276
|
+
Vite DevTools adds its dock to pages through Vite's HTML transform. Frameworks that render HTML on the server, such as [Void](/docs/integrations/void.md), don't run that transform, so load the dock yourself in development:
|
|
2277
|
+
|
|
2278
|
+
```ts
|
|
2279
|
+
if (import.meta.env.DEV && typeof document !== 'undefined') {
|
|
2280
|
+
const script = document.createElement('script');
|
|
2281
|
+
script.type = 'module';
|
|
2282
|
+
script.src = '/__devtools/embedded.js';
|
|
2283
|
+
document.head.append(script);
|
|
2284
|
+
}
|
|
2285
|
+
```
|
|
2286
|
+
|
|
2287
|
+
The first time you open Vite DevTools in a browser, it asks you to authorize that browser with a code printed in your terminal.
|
|
2288
|
+
|
|
2289
|
+
### How It Works
|
|
2290
|
+
|
|
2291
|
+
The devtools don't change how _fate_ behaves. When you connect a client, the devtools wrap its transport to record network activity and listen to cache changes. The page then sends snapshots to the panel over a [`BroadcastChannel`](https://developer.mozilla.org/en-US/docs/Web/API/BroadcastChannel). Snapshots are only sent while a panel is open. When you disconnect, the client's original transport is restored.
|
|
2292
|
+
|
|
2293
|
+
Because the panel and your app talk over a `BroadcastChannel`, the panel works anywhere on the same origin: in the Vite DevTools dock, in a separate tab, or in a popup. When more than one page or client is connected, use the picker in the panel's toolbar to switch between them.
|
|
2294
|
+
|
|
2156
2295
|
## GraphQL Integration
|
|
2157
2296
|
|
|
2158
2297
|
If your backend already exposes GraphQL, you can use it with fate. Define views and call requests and mutations as usual; fate builds the GraphQL operations for you.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nkzw/fate-indexeddb",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "Optional IndexedDB persistence adapter for fate.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"files": [
|
|
@@ -19,12 +19,12 @@
|
|
|
19
19
|
"idb": "^8.0.4"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
|
-
"@nkzw/fate": "2.
|
|
22
|
+
"@nkzw/fate": "2.1.0",
|
|
23
23
|
"fake-indexeddb": "^6.2.8",
|
|
24
24
|
"vite": "npm:@voidzero-dev/vite-plus-core@1.6.0",
|
|
25
25
|
"vite-plus": "1.6.0"
|
|
26
26
|
},
|
|
27
27
|
"peerDependencies": {
|
|
28
|
-
"@nkzw/fate": "^
|
|
28
|
+
"@nkzw/fate": "^2.0.0"
|
|
29
29
|
}
|
|
30
30
|
}
|