@ic-reactor/react 3.13.0 → 4.0.0-beta.2
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 +237 -787
- package/dist/index.d.ts +260 -16
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +471 -23
- package/dist/index.js.map +1 -1
- package/llms.txt +82 -278
- package/package.json +11 -39
- package/src/index.tsx +612 -0
- package/dist/auth/auth-client-compat.d.ts +0 -122
- package/dist/auth/auth-client-compat.d.ts.map +0 -1
- package/dist/auth/auth-client-compat.js +0 -162
- package/dist/auth/auth-client-compat.js.map +0 -1
- package/dist/auth/authentication-manager.d.ts +0 -405
- package/dist/auth/authentication-manager.d.ts.map +0 -1
- package/dist/auth/authentication-manager.js +0 -1537
- package/dist/auth/authentication-manager.js.map +0 -1
- package/dist/auth/constants.d.ts +0 -24
- package/dist/auth/constants.d.ts.map +0 -1
- package/dist/auth/constants.js +0 -24
- package/dist/auth/constants.js.map +0 -1
- package/dist/auth/createIdentityAttributeHooks.d.ts +0 -14
- package/dist/auth/createIdentityAttributeHooks.d.ts.map +0 -1
- package/dist/auth/createIdentityAttributeHooks.js +0 -122
- package/dist/auth/createIdentityAttributeHooks.js.map +0 -1
- package/dist/auth/identity-attributes-manager.d.ts +0 -27
- package/dist/auth/identity-attributes-manager.d.ts.map +0 -1
- package/dist/auth/identity-attributes-manager.js +0 -191
- package/dist/auth/identity-attributes-manager.js.map +0 -1
- package/dist/auth/identity-attributes.d.ts +0 -19
- package/dist/auth/identity-attributes.d.ts.map +0 -1
- package/dist/auth/identity-attributes.js +0 -227
- package/dist/auth/identity-attributes.js.map +0 -1
- package/dist/auth/index.d.ts +0 -8
- package/dist/auth/index.d.ts.map +0 -1
- package/dist/auth/index.js +0 -8
- package/dist/auth/index.js.map +0 -1
- package/dist/auth/local-ii-probe.d.ts +0 -57
- package/dist/auth/local-ii-probe.d.ts.map +0 -1
- package/dist/auth/local-ii-probe.js +0 -121
- package/dist/auth/local-ii-probe.js.map +0 -1
- package/dist/auth/types.d.ts +0 -222
- package/dist/auth/types.d.ts.map +0 -1
- package/dist/auth/types.js +0 -2
- package/dist/auth/types.js.map +0 -1
- package/dist/createActorHooks.d.ts +0 -41
- package/dist/createActorHooks.d.ts.map +0 -1
- package/dist/createActorHooks.js +0 -17
- package/dist/createActorHooks.js.map +0 -1
- package/dist/createInfiniteQuery.d.ts +0 -185
- package/dist/createInfiniteQuery.d.ts.map +0 -1
- package/dist/createInfiniteQuery.js +0 -198
- package/dist/createInfiniteQuery.js.map +0 -1
- package/dist/createMutation.d.ts +0 -33
- package/dist/createMutation.d.ts.map +0 -1
- package/dist/createMutation.js +0 -199
- package/dist/createMutation.js.map +0 -1
- package/dist/createQuery.d.ts +0 -63
- package/dist/createQuery.d.ts.map +0 -1
- package/dist/createQuery.js +0 -204
- package/dist/createQuery.js.map +0 -1
- package/dist/createReactorProvider.d.ts +0 -158
- package/dist/createReactorProvider.d.ts.map +0 -1
- package/dist/createReactorProvider.js +0 -256
- package/dist/createReactorProvider.js.map +0 -1
- package/dist/createSuspenseInfiniteQuery.d.ts +0 -154
- package/dist/createSuspenseInfiniteQuery.d.ts.map +0 -1
- package/dist/createSuspenseInfiniteQuery.js +0 -209
- package/dist/createSuspenseInfiniteQuery.js.map +0 -1
- package/dist/createSuspenseQuery.d.ts +0 -46
- package/dist/createSuspenseQuery.d.ts.map +0 -1
- package/dist/createSuspenseQuery.js +0 -158
- package/dist/createSuspenseQuery.js.map +0 -1
- package/dist/defineDisplayReactor.d.ts +0 -43
- package/dist/defineDisplayReactor.d.ts.map +0 -1
- package/dist/defineDisplayReactor.js +0 -42
- package/dist/defineDisplayReactor.js.map +0 -1
- package/dist/defineReactor.d.ts +0 -99
- package/dist/defineReactor.d.ts.map +0 -1
- package/dist/defineReactor.js +0 -15
- package/dist/defineReactor.js.map +0 -1
- package/dist/defineReactorShared.d.ts +0 -84
- package/dist/defineReactorShared.d.ts.map +0 -1
- package/dist/defineReactorShared.js +0 -139
- package/dist/defineReactorShared.js.map +0 -1
- package/dist/hooks/createAuthHooks.d.ts +0 -50
- package/dist/hooks/createAuthHooks.d.ts.map +0 -1
- package/dist/hooks/createAuthHooks.js +0 -291
- package/dist/hooks/createAuthHooks.js.map +0 -1
- package/dist/hooks/index.d.ts +0 -21
- package/dist/hooks/index.d.ts.map +0 -1
- package/dist/hooks/index.js +0 -24
- package/dist/hooks/index.js.map +0 -1
- package/dist/hooks/useActorInfiniteQuery.d.ts +0 -67
- package/dist/hooks/useActorInfiniteQuery.d.ts.map +0 -1
- package/dist/hooks/useActorInfiniteQuery.js +0 -89
- package/dist/hooks/useActorInfiniteQuery.js.map +0 -1
- package/dist/hooks/useActorMethod.d.ts +0 -148
- package/dist/hooks/useActorMethod.d.ts.map +0 -1
- package/dist/hooks/useActorMethod.js +0 -394
- package/dist/hooks/useActorMethod.js.map +0 -1
- package/dist/hooks/useActorMutation.d.ts +0 -51
- package/dist/hooks/useActorMutation.d.ts.map +0 -1
- package/dist/hooks/useActorMutation.js +0 -70
- package/dist/hooks/useActorMutation.js.map +0 -1
- package/dist/hooks/useActorQuery.d.ts +0 -45
- package/dist/hooks/useActorQuery.d.ts.map +0 -1
- package/dist/hooks/useActorQuery.js +0 -67
- package/dist/hooks/useActorQuery.js.map +0 -1
- package/dist/hooks/useActorSuspenseInfiniteQuery.d.ts +0 -51
- package/dist/hooks/useActorSuspenseInfiniteQuery.d.ts.map +0 -1
- package/dist/hooks/useActorSuspenseInfiniteQuery.js +0 -76
- package/dist/hooks/useActorSuspenseInfiniteQuery.js.map +0 -1
- package/dist/hooks/useActorSuspenseQuery.d.ts +0 -32
- package/dist/hooks/useActorSuspenseQuery.d.ts.map +0 -1
- package/dist/hooks/useActorSuspenseQuery.js +0 -58
- package/dist/hooks/useActorSuspenseQuery.js.map +0 -1
- package/dist/ownedAuthentication.d.ts +0 -52
- package/dist/ownedAuthentication.d.ts.map +0 -1
- package/dist/ownedAuthentication.js +0 -49
- package/dist/ownedAuthentication.js.map +0 -1
- package/dist/server.d.ts +0 -21
- package/dist/server.d.ts.map +0 -1
- package/dist/server.js +0 -23
- package/dist/server.js.map +0 -1
- package/dist/testing.d.ts +0 -19
- package/dist/testing.d.ts.map +0 -1
- package/dist/testing.js +0 -19
- package/dist/testing.js.map +0 -1
- package/dist/types.d.ts +0 -671
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -5
- package/dist/types.js.map +0 -1
- package/dist/utils.d.ts +0 -207
- package/dist/utils.d.ts.map +0 -1
- package/dist/utils.js +0 -405
- package/dist/utils.js.map +0 -1
- package/dist/validation.d.ts +0 -136
- package/dist/validation.d.ts.map +0 -1
- package/dist/validation.js +0 -144
- package/dist/validation.js.map +0 -1
- package/src/auth/auth-client-compat.ts +0 -273
- package/src/auth/authentication-manager.ts +0 -1682
- package/src/auth/constants.ts +0 -32
- package/src/auth/createIdentityAttributeHooks.ts +0 -169
- package/src/auth/identity-attributes-manager.ts +0 -226
- package/src/auth/identity-attributes.ts +0 -345
- package/src/auth/index.ts +0 -7
- package/src/auth/local-ii-probe.ts +0 -173
- package/src/auth/types.ts +0 -243
- package/src/createActorHooks.ts +0 -208
- package/src/createInfiniteQuery.ts +0 -670
- package/src/createMutation.ts +0 -324
- package/src/createQuery.ts +0 -369
- package/src/createReactorProvider.ts +0 -365
- package/src/createSuspenseInfiniteQuery.ts +0 -651
- package/src/createSuspenseQuery.ts +0 -304
- package/src/defineDisplayReactor.ts +0 -62
- package/src/defineReactor.ts +0 -142
- package/src/defineReactorShared.ts +0 -268
- package/src/hooks/createAuthHooks.ts +0 -371
- package/src/hooks/index.ts +0 -103
- package/src/hooks/useActorInfiniteQuery.ts +0 -278
- package/src/hooks/useActorMethod.ts +0 -710
- package/src/hooks/useActorMutation.ts +0 -205
- package/src/hooks/useActorQuery.ts +0 -157
- package/src/hooks/useActorSuspenseInfiniteQuery.ts +0 -248
- package/src/hooks/useActorSuspenseQuery.ts +0 -147
- package/src/index.ts +0 -31
- package/src/ownedAuthentication.ts +0 -81
- package/src/server.ts +0 -23
- package/src/testing.ts +0 -18
- package/src/types.ts +0 -948
- package/src/utils.ts +0 -505
- package/src/validation.ts +0 -226
package/dist/index.d.ts
CHANGED
|
@@ -1,17 +1,261 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
1
|
+
/**
|
|
2
|
+
* `@ic-reactor/react` 4: the `'use client'` bindings over `@ic-reactor/core`.
|
|
3
|
+
*
|
|
4
|
+
* A provider that gives a tree one client ({@link ReactorProvider}), a hook
|
|
5
|
+
* that reads it ({@link useClient}), and one that follows who is signed in
|
|
6
|
+
* ({@link useAuth}). Nothing here wraps `useQuery` or `useMutation`: an app
|
|
7
|
+
* calls TanStack Query's own hooks with the options the client builds. The
|
|
8
|
+
* package never re-exports `@ic-reactor/core`, so every name has one import
|
|
9
|
+
* path.
|
|
10
|
+
*
|
|
11
|
+
* The directive above makes this module a client boundary, so a framework
|
|
12
|
+
* that renders on a server (Next.js's App Router, for one) loads it as client
|
|
13
|
+
* code. A Server Component still cannot pass `ReactorProvider` its `client`
|
|
14
|
+
* prop, a function, across that boundary: render the provider from a client
|
|
15
|
+
* module of the app, which a Server Component then renders around its page.
|
|
16
|
+
*
|
|
17
|
+
* @packageDocumentation
|
|
18
|
+
*/
|
|
19
|
+
import type { AuthState, Client } from "@ic-reactor/core";
|
|
20
|
+
import { type ReactElement, type ReactNode } from "react";
|
|
21
|
+
/** Props of {@link ReactorProvider}. */
|
|
22
|
+
export interface ReactorProviderProps {
|
|
23
|
+
/**
|
|
24
|
+
* Returns the client of this tree. Either it creates one, such as
|
|
25
|
+
* `() => createClient({ network: "ic", auth: () => new AuthClient() })`, and
|
|
26
|
+
* the provider owns that client and disposes it when it unmounts; or it
|
|
27
|
+
* returns a client the app created before, at module scope, as
|
|
28
|
+
* `() => client`, and the provider borrows it and never disposes it.
|
|
29
|
+
*
|
|
30
|
+
* A factory, not a client, so that the provider decides when it runs: once
|
|
31
|
+
* per mounted provider, never per render. Give it no work beyond creating or
|
|
32
|
+
* returning the client (`createClient` does none until the client is used):
|
|
33
|
+
* React may call it twice in development and keep one result.
|
|
34
|
+
*
|
|
35
|
+
* Only the factory of the first render is used. A different function on a
|
|
36
|
+
* later render does not rebuild the client; to replace it, remount the
|
|
37
|
+
* provider by giving it another `key`.
|
|
38
|
+
*/
|
|
39
|
+
readonly client: () => Client;
|
|
40
|
+
/** The tree that reads the client with {@link useClient} and {@link useAuth}. */
|
|
41
|
+
readonly children: ReactNode;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Gives a tree one client: it gets it from `client` once, on the first
|
|
45
|
+
* render, makes it available to {@link useClient} and {@link useAuth}, renders
|
|
46
|
+
* TanStack Query's `QueryClientProvider` around the children with the
|
|
47
|
+
* client's `QueryClient`, and, if its factory created the client, disposes it
|
|
48
|
+
* when it unmounts.
|
|
49
|
+
*
|
|
50
|
+
* Put it at the root of the part of the app that calls canisters, in a
|
|
51
|
+
* client module (the examples below). On a server it renders inside the
|
|
52
|
+
* request, so a factory that creates the client runs once per request and no
|
|
53
|
+
* cache or caller is shared between two users, which a client at module scope
|
|
54
|
+
* would be.
|
|
55
|
+
*
|
|
56
|
+
* Who disposes the client depends on when it was created, not on where the
|
|
57
|
+
* factory is written. A client the factory call creates belongs to the
|
|
58
|
+
* provider. A client created before the call, such as one at module scope that
|
|
59
|
+
* code outside React uses too, is borrowed: the provider never disposes it,
|
|
60
|
+
* however many times it mounts and unmounts, and the app ends it with
|
|
61
|
+
* `client.dispose()` if it ever needs to. A factory that creates the shared
|
|
62
|
+
* client lazily on its first call (`() => (client ??= createClient(...))`)
|
|
63
|
+
* hands that first provider ownership, and the provider disposes it on
|
|
64
|
+
* unmount. It can also lose the client before any unmount: when React throws
|
|
65
|
+
* away the render that created it (see below), the client stays registered
|
|
66
|
+
* for disposal at collection until the next render gets it back from the
|
|
67
|
+
* factory, so a garbage collection while the fallback shows disposes the
|
|
68
|
+
* client the retry then mounts. Create a shared client eagerly instead. In
|
|
69
|
+
* development, a provider whose factory hands back a client that an earlier
|
|
70
|
+
* factory call created and no provider has committed yet, as a lazily shared
|
|
71
|
+
* factory does, logs a warning (under `StrictMode`, on its first render), and
|
|
72
|
+
* a provider that is given a borrowed client which is already disposed logs an
|
|
73
|
+
* error.
|
|
74
|
+
*
|
|
75
|
+
* Disposal is safe in React's development double-mount (`StrictMode` mounts,
|
|
76
|
+
* unmounts and mounts every component again at once): the cleanup only
|
|
77
|
+
* schedules the disposal for the next macrotask, and the second mount cancels
|
|
78
|
+
* it, so a client in use is never disposed. An unmount that is not followed
|
|
79
|
+
* by a mount disposes an owned client exactly once.
|
|
80
|
+
*
|
|
81
|
+
* React runs no cleanup for a render it throws away before committing it: the
|
|
82
|
+
* first render of a provider below a Suspense boundary that suspends, or the
|
|
83
|
+
* `useState` initializer call that `StrictMode` drops in development. An owned
|
|
84
|
+
* client built for such a render, whose auth a child's {@link useAuth} may
|
|
85
|
+
* already have built, is disposed once that render's state is garbage
|
|
86
|
+
* collected, through a `FinalizationRegistry`. That is later than an unmount
|
|
87
|
+
* would dispose it, at a moment no code chooses, but it is disposed, auth and
|
|
88
|
+
* listeners with it. A client that the factory returns again, or that a
|
|
89
|
+
* provider commits, is taken off the registry, whoever owns it. A runtime
|
|
90
|
+
* without `FinalizationRegistry` never disposes such a client, and a server
|
|
91
|
+
* never registers one: it builds no auth there, and the rest of the request
|
|
92
|
+
* still uses it.
|
|
93
|
+
*
|
|
94
|
+
* React also runs the effects of a subtree again when it shows a hidden
|
|
95
|
+
* `Activity` once more, and that can be long after they were cleaned up. If an
|
|
96
|
+
* owned client was disposed meanwhile, the provider builds another from the
|
|
97
|
+
* same factory, because a disposed client cannot call, sign in or cache any
|
|
98
|
+
* more. The cost is that hiding a provider inside an `Activity` drops its
|
|
99
|
+
* cache: disposing clears the `QueryClient`, and the client built on the next
|
|
100
|
+
* show starts empty. React cannot tell a hidden subtree from an unmounted one
|
|
101
|
+
* in the cleanup, so there is no way to keep it. To keep a cache across
|
|
102
|
+
* hiding, render the provider above the `Activity`, not inside it, or give it
|
|
103
|
+
* a borrowed client, which is never disposed.
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* A client per provider, owned and disposed by it (on a server, one per
|
|
107
|
+
* request):
|
|
108
|
+
* ```tsx
|
|
109
|
+
* "use client"
|
|
110
|
+
*
|
|
111
|
+
* import { createClient } from "@ic-reactor/core"
|
|
112
|
+
* import { ReactorProvider } from "@ic-reactor/react"
|
|
113
|
+
* import { AuthClient } from "@icp-sdk/auth/client"
|
|
114
|
+
* import type { ReactNode } from "react"
|
|
115
|
+
*
|
|
116
|
+
* export function Providers({ children }: { children: ReactNode }) {
|
|
117
|
+
* return (
|
|
118
|
+
* <ReactorProvider
|
|
119
|
+
* client={() =>
|
|
120
|
+
* createClient({ network: "ic", auth: () => new AuthClient() })
|
|
121
|
+
* }
|
|
122
|
+
* >
|
|
123
|
+
* {children}
|
|
124
|
+
* </ReactorProvider>
|
|
125
|
+
* )
|
|
126
|
+
* }
|
|
127
|
+
* ```
|
|
128
|
+
*
|
|
129
|
+
* @example
|
|
130
|
+
* One client per tab, created at module scope and used outside React too.
|
|
131
|
+
* The provider borrows it and never disposes it (browser-only: on a server a
|
|
132
|
+
* module-scope client is shared by every request):
|
|
133
|
+
* ```tsx
|
|
134
|
+
* "use client"
|
|
135
|
+
*
|
|
136
|
+
* import { createClient } from "@ic-reactor/core"
|
|
137
|
+
* import { ReactorProvider } from "@ic-reactor/react"
|
|
138
|
+
* import { AuthClient } from "@icp-sdk/auth/client"
|
|
139
|
+
* import type { ReactNode } from "react"
|
|
140
|
+
*
|
|
141
|
+
* export const client = createClient({
|
|
142
|
+
* network: "ic",
|
|
143
|
+
* auth: () => new AuthClient(),
|
|
144
|
+
* })
|
|
145
|
+
*
|
|
146
|
+
* export function Providers({ children }: { children: ReactNode }) {
|
|
147
|
+
* return <ReactorProvider client={() => client}>{children}</ReactorProvider>
|
|
148
|
+
* }
|
|
149
|
+
* ```
|
|
150
|
+
*/
|
|
151
|
+
export declare function ReactorProvider({ client: build, children, }: ReactorProviderProps): ReactElement;
|
|
152
|
+
/**
|
|
153
|
+
* The client of the nearest {@link ReactorProvider}: the one object that
|
|
154
|
+
* builds canister handles and query options, and that signs users in and out.
|
|
155
|
+
*
|
|
156
|
+
* Call it in the body of each component that builds keys or options, on
|
|
157
|
+
* every render, and build them from what it returns there, never from a
|
|
158
|
+
* client held at module scope: they are built for the caller this render
|
|
159
|
+
* shows. Do not keep what it returns past the render: while a page hydrates
|
|
160
|
+
* it is a view for the anonymous caller, and a view never moves on. An effect
|
|
161
|
+
* or a callback that uses it closes over its render's value and lists it in
|
|
162
|
+
* its dependencies (`react-hooks/exhaustive-deps`), so that it runs again with
|
|
163
|
+
* the client after hydrating. Kept from the hydrating render anywhere else
|
|
164
|
+
* (`useState(client)`, `useRef(client)`, a `useMemo` or `useCallback` with
|
|
165
|
+
* `[]`, a module variable), it stays that view: the component shows the
|
|
166
|
+
* anonymous caller's data, a read it starts while the user is signed in is
|
|
167
|
+
* cancelled, and a write through it still signs as the live caller. Nothing
|
|
168
|
+
* warns about it. A nested {@link ReactorProvider} given it
|
|
169
|
+
* (`client={() => client}`) holds the client the view was made over.
|
|
170
|
+
* It follows the client's caller with `useSyncExternalStore`, so a
|
|
171
|
+
* component that calls it renders again when the caller changes (a sign-in, a
|
|
172
|
+
* switch of account, a sign-out) and never otherwise: a change of status that
|
|
173
|
+
* leaves the caller as it is (a session that expired, or one signed in
|
|
174
|
+
* elsewhere, both call as the anonymous principal) renders nothing. In the
|
|
175
|
+
* steady state it returns the provider's client object itself.
|
|
176
|
+
*
|
|
177
|
+
* On a server, and while a page hydrates, the caller is the anonymous one, as
|
|
178
|
+
* for {@link useAuth}. In a browser that holds a session, the hydrating render
|
|
179
|
+
* gets a view of the client for the anonymous caller: its `queryKey`,
|
|
180
|
+
* `queryOptions`, `caller()` and `authState()` are the anonymous caller's, so
|
|
181
|
+
* the page finds what the server prefetched and dehydrated and matches its
|
|
182
|
+
* HTML; everything else (canisters, `mutationOptions`, `signIn`, `signOut`,
|
|
183
|
+
* the `QueryClient`) is the client's own, and a write signs as the caller
|
|
184
|
+
* current when it runs. Right after hydrating, React renders the component
|
|
185
|
+
* again with the client itself, for the user: a read with none of the user's
|
|
186
|
+
* data yet shows its loading state, and a `useSuspenseQuery` read its
|
|
187
|
+
* boundary's fallback, until that data arrives. A client built with
|
|
188
|
+
* `identity` keeps its caller for good and is always returned as it is.
|
|
189
|
+
*
|
|
190
|
+
* Three consequences of that move on a signed-in reload:
|
|
191
|
+
*
|
|
192
|
+
* - A Suspense boundary that is still dehydrated below a component that
|
|
193
|
+
* renders with the caller (this hook or {@link useAuth}), because its lazy
|
|
194
|
+
* code is still loading or its streamed HTML has not arrived, is rendered
|
|
195
|
+
* on the client when that component moves on: it shows its fallback
|
|
196
|
+
* instead of the server's HTML, and React 18 reports a recoverable error.
|
|
197
|
+
* Its data is still the user's. A `useAuth()` component also moves on in a
|
|
198
|
+
* tab whose session expired or is signed in elsewhere. Render such a boundary where no component
|
|
199
|
+
* that renders with the caller sits above it, or pass it in as `children`,
|
|
200
|
+
* which a component's own update does not render again.
|
|
201
|
+
* - A read the hydrating render built may still run once (TanStack Query
|
|
202
|
+
* refetches stale data on mount, and an effect may fetch with the view's
|
|
203
|
+
* options). It is cancelled before anything is sent. A key that holds data
|
|
204
|
+
* keeps it as it was, and a fetch of it resolves with that data. A key with
|
|
205
|
+
* none fails (`kind` `"cancelled"`, `code` `"caller_changed"`) until the
|
|
206
|
+
* anonymous caller is current again: the hydrating render's own reads never
|
|
207
|
+
* show that, but a listener of
|
|
208
|
+
* `client.queryClient.getQueryCache().subscribe()` (the client takes no
|
|
209
|
+
* `QueryCache` of yours), an effect that awaits the fetch and, for a
|
|
210
|
+
* `useSuspenseQuery` read the server rendered without dehydrating its
|
|
211
|
+
* data, React's `onRecoverableError` (as the reported error's `cause` on
|
|
212
|
+
* React 19) see it, so ignore `kind` `"cancelled"` there.
|
|
213
|
+
* - Put a Suspense boundary above every component that reads with
|
|
214
|
+
* `useSuspenseQuery`, on React 18 and 19 alike. The move is a synchronous
|
|
215
|
+
* update, which such a read suspends until the user's data arrives. With a
|
|
216
|
+
* boundary above, the boundary shows its fallback, then the user's data,
|
|
217
|
+
* and the rest of the page responds meanwhile. With none, React 18 refuses
|
|
218
|
+
* the update ("A component suspended while responding to synchronous
|
|
219
|
+
* input") and unmounts the root, so a signed-in reload renders nothing.
|
|
220
|
+
* React 19 keeps the server's HTML on screen, but until the user's data
|
|
221
|
+
* arrives, however long the read and its retries take, a click or any other
|
|
222
|
+
* update outside a transition commits nothing, and neither does a
|
|
223
|
+
* transition that renders the reading component again.
|
|
224
|
+
*
|
|
225
|
+
* @throws Error outside a `ReactorProvider`, naming it.
|
|
226
|
+
*/
|
|
227
|
+
export declare function useClient(): Client;
|
|
228
|
+
/**
|
|
229
|
+
* Who calls, and how to change it: the client's {@link AuthState} (`status`
|
|
230
|
+
* and `principal`) with `signIn` and `signOut` forwarded to the client.
|
|
231
|
+
*
|
|
232
|
+
* It follows the client with `useSyncExternalStore`, so a component renders
|
|
233
|
+
* again once per change of status or principal and never otherwise (a renewed
|
|
234
|
+
* delegation, or a parent that renders, does not). The object it returns is
|
|
235
|
+
* the same until the state changes, so it is safe in a dependency array or
|
|
236
|
+
* as a prop of a memoized child.
|
|
237
|
+
*
|
|
238
|
+
* On a server, and while a page hydrates, the state is `anonymous`: the
|
|
239
|
+
* server has no session, and rendering the browser's would not match the
|
|
240
|
+
* server's HTML. A browser whose state is another one (signed in, or a session
|
|
241
|
+
* that expired or is signed in elsewhere) renders the component again with its
|
|
242
|
+
* own state right after hydration; an anonymous one does not, and keeps the
|
|
243
|
+
* object. A component that reads `status` before then should show the same
|
|
244
|
+
* thing signed out and while the session is read. Whenever it moves on after
|
|
245
|
+
* hydrating (a signed-in reload, or a session that expired or is signed in
|
|
246
|
+
* elsewhere), it renders a Suspense boundary still dehydrated below it on the
|
|
247
|
+
* client, as for {@link useClient}.
|
|
248
|
+
*
|
|
249
|
+
* `signIn` and `signOut` reject like {@link Client.signIn} and
|
|
250
|
+
* {@link Client.signOut}: on a client built with `identity`, which has no
|
|
251
|
+
* sign-in, and on a server.
|
|
252
|
+
*
|
|
253
|
+
* @throws Error outside a {@link ReactorProvider}.
|
|
254
|
+
*/
|
|
255
|
+
export declare function useAuth(): AuthState & {
|
|
256
|
+
/** Signs in through the client's auth, passing `options` on. */
|
|
257
|
+
signIn(options?: unknown): Promise<void>;
|
|
258
|
+
/** Signs out through the client's auth. */
|
|
259
|
+
signOut(options?: unknown): Promise<void>;
|
|
260
|
+
};
|
|
17
261
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;GAiBG;AACH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;AAEzD,OAAO,EAQL,KAAK,YAAY,EACjB,KAAK,SAAS,EACf,MAAM,OAAO,CAAA;AAwNd,wCAAwC;AACxC,MAAM,WAAW,oBAAoB;IACnC;;;;;;;;;;;;;;;OAeG;IACH,QAAQ,CAAC,MAAM,EAAE,MAAM,MAAM,CAAA;IAC7B,iFAAiF;IACjF,QAAQ,CAAC,QAAQ,EAAE,SAAS,CAAA;CAC7B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2GG;AACH,wBAAgB,eAAe,CAAC,EAC9B,MAAM,EAAE,KAAK,EACb,QAAQ,GACT,EAAE,oBAAoB,GAAG,YAAY,CAmDrC;AAmBD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0EG;AACH,wBAAgB,SAAS,IAAI,MAAM,CAclC;AAgBD;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,OAAO,IAAI,SAAS,GAAG;IACrC,gEAAgE;IAChE,MAAM,CAAC,OAAO,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IACxC,2CAA2C;IAC3C,OAAO,CAAC,OAAO,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;CAC1C,CAsBA"}
|