@softistx/riva-react 0.0.0-stage → 0.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/LICENSE +21 -0
- package/README.md +220 -2
- package/dist/chunks/index-gzs9smr9.js +42 -0
- package/dist/chunks/index-gzs9smr9.js.map +10 -0
- package/dist/chunks/index-zww0a7j9.js +20 -0
- package/dist/chunks/index-zww0a7j9.js.map +10 -0
- package/dist/context.d.ts +12 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/entities/index.d.ts +2 -0
- package/dist/entities/index.d.ts.map +1 -0
- package/dist/entities/index.js +21 -0
- package/dist/entities/index.js.map +10 -0
- package/dist/entities/use-fragment.d.ts +7 -0
- package/dist/entities/use-fragment.d.ts.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +111 -0
- package/dist/index.js.map +13 -0
- package/dist/infinite/index.d.ts +2 -0
- package/dist/infinite/index.d.ts.map +1 -0
- package/dist/infinite/index.js +21 -0
- package/dist/infinite/index.js.map +10 -0
- package/dist/infinite/use-infinite-query.d.ts +19 -0
- package/dist/infinite/use-infinite-query.d.ts.map +1 -0
- package/dist/query-state.d.ts +18 -0
- package/dist/query-state.d.ts.map +1 -0
- package/dist/store/index.d.ts +2 -0
- package/dist/store/index.d.ts.map +1 -0
- package/dist/store/index.js +75 -0
- package/dist/store/index.js.map +10 -0
- package/dist/store/use-store.d.ts +12 -0
- package/dist/store/use-store.d.ts.map +1 -0
- package/dist/suspend.d.ts +8 -0
- package/dist/suspend.d.ts.map +1 -0
- package/dist/use-mutation.d.ts +18 -0
- package/dist/use-mutation.d.ts.map +1 -0
- package/dist/use-query.d.ts +25 -0
- package/dist/use-query.d.ts.map +1 -0
- package/dist/use-signal.d.ts +6 -0
- package/dist/use-signal.d.ts.map +1 -0
- package/docs/README.md +20 -0
- package/docs/guide/entities.md +25 -0
- package/docs/guide/infinite.md +35 -0
- package/docs/guide/mutations.md +41 -0
- package/docs/guide/provider.md +34 -0
- package/docs/guide/queries.md +41 -0
- package/docs/guide/signals.md +27 -0
- package/docs/guide/ssr.md +27 -0
- package/docs/guide/store.md +27 -0
- package/docs/guide/suspense.md +38 -0
- package/docs/troubleshooting.md +102 -0
- package/package.json +82 -5
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
# Troubleshooting
|
|
2
|
+
|
|
3
|
+
Each entry is headed by the message you will see.
|
|
4
|
+
|
|
5
|
+
## `No RivaClient in scope: wrap the tree in <RivaProvider client={client}>`
|
|
6
|
+
|
|
7
|
+
Code: `RIVA_SCOPE` (`RivaScopeError`).
|
|
8
|
+
|
|
9
|
+
The full message: `No RivaClient in scope: wrap the tree in <RivaProvider client={client}>. On the server, create one client per request.`
|
|
10
|
+
|
|
11
|
+
**When:** a hook (`useSignal`, `useValue`, `useQuery`, `useMutation`, `useInfiniteQuery`, `useFragment` or `useClient`) rendered with no `RivaProvider` above it.
|
|
12
|
+
|
|
13
|
+
**Why:** definitions are stateless and values live in a `RivaClient`. The hooks take it from the provider, never from a module-level default, so two server requests can never share one.
|
|
14
|
+
|
|
15
|
+
**Fix:** wrap the tree in a provider. On the server, create the client per request.
|
|
16
|
+
|
|
17
|
+
```tsx
|
|
18
|
+
import { createRivaClient } from '@softistx/riva';
|
|
19
|
+
import { RivaProvider } from '@softistx/riva-react';
|
|
20
|
+
|
|
21
|
+
export const Root = () => (
|
|
22
|
+
<RivaProvider client={createRivaClient() /* inside the request handler on the server */}>
|
|
23
|
+
<App />
|
|
24
|
+
</RivaProvider>
|
|
25
|
+
);
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
This is not the core's "No RivaClient in scope: read through client.get(def)…" error, which `signal.get()` and the like throw outside React: see the [core troubleshooting](https://github.com/softistx/riva/blob/develop/packages/riva/docs/troubleshooting.md#no-rivaclient-in-scope).
|
|
29
|
+
|
|
30
|
+
## A query fetches twice around Suspense
|
|
31
|
+
|
|
32
|
+
**When:** you mount the same query once with `suspense: true` and once without (or under `Suspense` with `enabled` toggled), and the network shows a second request.
|
|
33
|
+
|
|
34
|
+
**Why:** a `suspense: true` mount trusts what a Suspense render just fetched for one second, whatever the query's `staleTime`. A mount without it follows the query's own `staleTime`, `0` by default, so it fetches stale data again.
|
|
35
|
+
|
|
36
|
+
**Fix:** give the query a `staleTime`, or use `suspense: true` on every reader of that query.
|
|
37
|
+
|
|
38
|
+
```ts
|
|
39
|
+
const patients = query({ id: 'patients', staleTime: '30s', fetch });
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## The error boundary shows the error again after a reset
|
|
43
|
+
|
|
44
|
+
**When:** a `suspense: true` query failed, the boundary shows its fallback, and resetting the boundary shows the same error at once.
|
|
45
|
+
|
|
46
|
+
**Why:** the error is the query's state, and nothing refetches it: the component that would observe it was never mounted.
|
|
47
|
+
|
|
48
|
+
**Fix:** start the fetch again before resetting the boundary. The component then suspends and renders the new result.
|
|
49
|
+
|
|
50
|
+
```tsx
|
|
51
|
+
import { Suspense } from 'react';
|
|
52
|
+
import { ErrorBoundary } from 'react-error-boundary';
|
|
53
|
+
import { useClient } from '@softistx/riva-react';
|
|
54
|
+
|
|
55
|
+
export function Page({ school }: { school: string }) {
|
|
56
|
+
const client = useClient();
|
|
57
|
+
return (
|
|
58
|
+
<ErrorBoundary
|
|
59
|
+
onReset={() => patients.prefetch(client, { school })}
|
|
60
|
+
fallbackRender={({ resetErrorBoundary }) => (
|
|
61
|
+
<button onClick={resetErrorBoundary}>Retry</button>
|
|
62
|
+
)}
|
|
63
|
+
>
|
|
64
|
+
<Suspense fallback={<p>Loading…</p>}>
|
|
65
|
+
<PatientList school={school} />
|
|
66
|
+
</Suspense>
|
|
67
|
+
</ErrorBoundary>
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
`ErrorBoundary` is the one of [react-error-boundary](https://www.npmjs.com/package/react-error-boundary).
|
|
73
|
+
|
|
74
|
+
## Unhandled rejection from `run`
|
|
75
|
+
|
|
76
|
+
**When:** `useMutation`'s `run(vars)` fails and the console reports an unhandled promise rejection.
|
|
77
|
+
|
|
78
|
+
**Why:** `run` rejects with the error, as the definition's own `run` does, besides setting `error` in the hook's state.
|
|
79
|
+
|
|
80
|
+
**Fix:** catch it where you call it, or read `error` and ignore the rejection.
|
|
81
|
+
|
|
82
|
+
```tsx
|
|
83
|
+
function Rename({ id, name }: { id: string; name: string }) {
|
|
84
|
+
const { run, error } = useMutation(rename);
|
|
85
|
+
return <button onClick={() => run({ id, name }).catch(() => {})}>Rename</button>;
|
|
86
|
+
}
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## `Store "<name>": "<key>" is read-only here; write it in an action.`
|
|
90
|
+
|
|
91
|
+
Code: `RIVA_STORE` (`RivaError`).
|
|
92
|
+
|
|
93
|
+
**When:** a component assigns to the `s` that `useStore(def)` returns (`s.filter = 'x'`).
|
|
94
|
+
|
|
95
|
+
**Why:** `s` is a read-only, tracked view of the store's state and computeds: the component re-renders only when a key it read changes. Only the store's actions write.
|
|
96
|
+
|
|
97
|
+
**Fix:** call the action from `a`.
|
|
98
|
+
|
|
99
|
+
```tsx
|
|
100
|
+
const [s, a] = useStore(BookStore);
|
|
101
|
+
a.filterBy('x'); // not s.filter = 'x'
|
|
102
|
+
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,83 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
"name": "@softistx/riva-react",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "React adapter for riva: RivaProvider, hooks, Suspense and SSR support.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"sideEffects": false,
|
|
10
|
+
"files": [
|
|
11
|
+
"dist",
|
|
12
|
+
"docs",
|
|
13
|
+
"README.md",
|
|
14
|
+
"package.json",
|
|
15
|
+
"LICENSE"
|
|
16
|
+
],
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
20
|
+
"import": "./dist/index.js",
|
|
21
|
+
"default": "./dist/index.js"
|
|
22
|
+
},
|
|
23
|
+
"./infinite": {
|
|
24
|
+
"types": "./dist/infinite/index.d.ts",
|
|
25
|
+
"import": "./dist/infinite/index.js",
|
|
26
|
+
"default": "./dist/infinite/index.js"
|
|
27
|
+
},
|
|
28
|
+
"./entities": {
|
|
29
|
+
"types": "./dist/entities/index.d.ts",
|
|
30
|
+
"import": "./dist/entities/index.js",
|
|
31
|
+
"default": "./dist/entities/index.js"
|
|
32
|
+
},
|
|
33
|
+
"./store": {
|
|
34
|
+
"types": "./dist/store/index.d.ts",
|
|
35
|
+
"import": "./dist/store/index.js",
|
|
36
|
+
"default": "./dist/store/index.js"
|
|
37
|
+
},
|
|
38
|
+
"./package.json": "./package.json"
|
|
39
|
+
},
|
|
40
|
+
"keywords": [
|
|
41
|
+
"state",
|
|
42
|
+
"signals",
|
|
43
|
+
"cache",
|
|
44
|
+
"graphql",
|
|
45
|
+
"rest",
|
|
46
|
+
"ssr"
|
|
47
|
+
],
|
|
48
|
+
"repository": {
|
|
49
|
+
"type": "git",
|
|
50
|
+
"url": "git+https://github.com/softistx/riva.git",
|
|
51
|
+
"directory": "packages/riva-react"
|
|
52
|
+
},
|
|
53
|
+
"publishConfig": {
|
|
54
|
+
"registry": "https://registry.npmjs.org/",
|
|
55
|
+
"access": "public"
|
|
56
|
+
},
|
|
57
|
+
"scripts": {
|
|
58
|
+
"build": "bun run ../../build.ts",
|
|
59
|
+
"test": "bun test src",
|
|
60
|
+
"typecheck": "bun check"
|
|
61
|
+
},
|
|
62
|
+
"devDependencies": {
|
|
63
|
+
"@happy-dom/global-registrator": "^20.0.0",
|
|
64
|
+
"@softistx/riva": "0.1.0",
|
|
65
|
+
"@types/bun": "^1.4.5",
|
|
66
|
+
"@types/react": "^19.0.0",
|
|
67
|
+
"@types/react-dom": "^19.0.0",
|
|
68
|
+
"react": "^19.0.0",
|
|
69
|
+
"react-dom": "^19.0.0"
|
|
70
|
+
},
|
|
71
|
+
"peerDependencies": {
|
|
72
|
+
"react": "^19.0.0",
|
|
73
|
+
"@softistx/riva": "^0.1.0"
|
|
74
|
+
},
|
|
75
|
+
"nxgt": {
|
|
76
|
+
"entrypoints": [
|
|
77
|
+
"src/index.ts",
|
|
78
|
+
"src/infinite/index.ts",
|
|
79
|
+
"src/entities/index.ts",
|
|
80
|
+
"src/store/index.ts"
|
|
81
|
+
]
|
|
82
|
+
}
|
|
83
|
+
}
|