@molecule/app-react 1.6.4 → 1.6.5
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 +35 -5
- package/dist/hooks/useStore.d.ts +11 -1
- package/dist/hooks/useStore.d.ts.map +1 -1
- package/dist/hooks/useStore.js +26 -4
- package/dist/hooks/useStore.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -3,15 +3,11 @@ AUTO-GENERATED — DO NOT EDIT THIS FILE.
|
|
|
3
3
|
Generated by `mlcl sync-docs` from the package's src/index.ts JSDoc + mlcl/registry.json.
|
|
4
4
|
Edits here are overwritten on the next commit (molecule's pre-commit hook regenerates).
|
|
5
5
|
To change this document, edit the module-level JSDoc in src/index.ts.
|
|
6
|
-
Generated: 2026-10-
|
|
6
|
+
Generated: 2026-10-17T00:35:27.553Z
|
|
7
7
|
-->
|
|
8
8
|
|
|
9
9
|
# @molecule/app-react
|
|
10
10
|
|
|
11
|
-
> **Auto-generated, AI-first package reference** for the [molecule.dev](https://molecule.dev) ecosystem.
|
|
12
|
-
> It is written to be read by coding agents as much as by people, and is generated from this
|
|
13
|
-
> package's source — edit `src/index.ts` JSDoc, not this file.
|
|
14
|
-
|
|
15
11
|
React framework bindings for the Molecule app stack.
|
|
16
12
|
|
|
17
13
|
Provides React hooks, contexts, and provider components for all molecule
|
|
@@ -19,6 +15,10 @@ core interfaces (auth, i18n, theme, routing, state, http, storage, logger,
|
|
|
19
15
|
chat, workspace, editor, preview), so framework-agnostic providers plug
|
|
20
16
|
into React idioms.
|
|
21
17
|
|
|
18
|
+
> **Auto-generated, AI-first package reference** for the [molecule.dev](https://molecule.dev) ecosystem.
|
|
19
|
+
> It is written to be read by coding agents as much as by people, and is generated from this
|
|
20
|
+
> package's source — edit `src/index.ts` JSDoc, not this file.
|
|
21
|
+
|
|
22
22
|
## Quick Start
|
|
23
23
|
|
|
24
24
|
```tsx
|
|
@@ -188,6 +188,27 @@ interface AuthClient<T = UserProfile> {
|
|
|
188
188
|
* Initializes auth state (e.g., from stored tokens).
|
|
189
189
|
*/
|
|
190
190
|
initialize(): Promise<void>
|
|
191
|
+
/**
|
|
192
|
+
* Resolves when the session restore started by `initialize()` has settled — the point
|
|
193
|
+
* after which the client knows whether this visitor is signed in.
|
|
194
|
+
*
|
|
195
|
+
* Resolves IMMEDIATELY when no restore is in flight: before `initialize()` is ever
|
|
196
|
+
* called, and after it has finished. A restore that failed resolves too (it settled the
|
|
197
|
+
* question), so an HTTP client can await this before every request without risking one
|
|
198
|
+
* held forever. That is what makes the fetch-before-restore race impossible: a page that
|
|
199
|
+
* fetches viewer-dependent data on mount waits here instead of going out anonymously
|
|
200
|
+
* (see `setAuthGate` in `@molecule/app-http`).
|
|
201
|
+
*
|
|
202
|
+
* Optional: a provider that restores no session has nothing to wait for. Without it, an
|
|
203
|
+
* HTTP client bonded to that provider sends first-paint requests unauthenticated.
|
|
204
|
+
*
|
|
205
|
+
* A provider whose restore sends a request THROUGH the gated HTTP client must send that
|
|
206
|
+
* request with `skipAuthGate: true` (`RequestConfig` in `@molecule/app-http`): the gate
|
|
207
|
+
* waits on this promise, so holding the restore's own request makes the gate wait on
|
|
208
|
+
* itself and stalls every request it holds until it times out. `createJWTAuthClient`'s
|
|
209
|
+
* restore does not need it — it uses `fetch`, not the bonded client.
|
|
210
|
+
*/
|
|
211
|
+
whenRestored?(): Promise<void>
|
|
191
212
|
/**
|
|
192
213
|
* Subscribes to auth state changes.
|
|
193
214
|
*/
|
|
@@ -2225,6 +2246,9 @@ The context comes from `<StateProvider provider={…}>` or from
|
|
|
2225
2246
|
`<MoleculeProvider>` — which supplies the provider bonded under
|
|
2226
2247
|
`@molecule/app-state` by default, so a scaffolded app needs no `state` prop.
|
|
2227
2248
|
|
|
2249
|
+
Only hooks that read the context call this; `useStore(store)` takes its store
|
|
2250
|
+
as an argument and works with no provider at all.
|
|
2251
|
+
|
|
2228
2252
|
```typescript
|
|
2229
2253
|
function useStateProvider(): StateProvider
|
|
2230
2254
|
```
|
|
@@ -2235,6 +2259,12 @@ function useStateProvider(): StateProvider
|
|
|
2235
2259
|
|
|
2236
2260
|
Hook to subscribe to a store with optional selector and equality function.
|
|
2237
2261
|
|
|
2262
|
+
The store is the argument, so this hook needs NO `StateProvider`: it reads
|
|
2263
|
+
`store.getState()` and subscribes with `store.subscribe()`, and never touches
|
|
2264
|
+
the state context. A store minted outside the `state` bond — the direct
|
|
2265
|
+
`createStoreWithActions()` / `createStore()` a provider package exports — is
|
|
2266
|
+
therefore as valid here as one `@molecule/app-state`'s `createStore()` made.
|
|
2267
|
+
|
|
2238
2268
|
```typescript
|
|
2239
2269
|
function useStore(store: Store<T>, options?: UseStoreOptions<T, S>): S
|
|
2240
2270
|
```
|
package/dist/hooks/useStore.d.ts
CHANGED
|
@@ -12,13 +12,23 @@ import type { UseStoreOptions } from '../types.js';
|
|
|
12
12
|
* `<MoleculeProvider>` — which supplies the provider bonded under
|
|
13
13
|
* `@molecule/app-state` by default, so a scaffolded app needs no `state` prop.
|
|
14
14
|
*
|
|
15
|
+
* Only hooks that read the context call this; `useStore(store)` takes its store
|
|
16
|
+
* as an argument and works with no provider at all.
|
|
17
|
+
*
|
|
15
18
|
* @returns The state provider from context
|
|
16
|
-
* @throws {Error}
|
|
19
|
+
* @throws {Error} when no `StateProvider` is above the component — the message
|
|
20
|
+
* names the fix (which provider to render, and the import for it).
|
|
17
21
|
*/
|
|
18
22
|
export declare function useStateProvider(): StateProvider;
|
|
19
23
|
/**
|
|
20
24
|
* Hook to subscribe to a store with optional selector and equality function.
|
|
21
25
|
*
|
|
26
|
+
* The store is the argument, so this hook needs NO `StateProvider`: it reads
|
|
27
|
+
* `store.getState()` and subscribes with `store.subscribe()`, and never touches
|
|
28
|
+
* the state context. A store minted outside the `state` bond — the direct
|
|
29
|
+
* `createStoreWithActions()` / `createStore()` a provider package exports — is
|
|
30
|
+
* therefore as valid here as one `@molecule/app-state`'s `createStore()` made.
|
|
31
|
+
*
|
|
22
32
|
* @param store - The store to subscribe to
|
|
23
33
|
* @param options - Hook options (selector, equalityFn)
|
|
24
34
|
* @returns The selected state
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useStore.d.ts","sourceRoot":"","sources":["../../src/hooks/useStore.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAKH,OAAO,KAAK,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAG/D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"useStore.d.ts","sourceRoot":"","sources":["../../src/hooks/useStore.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAKH,OAAO,KAAK,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAG/D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAkBlD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,gBAAgB,IAAI,aAAa,CAUhD;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,EAAE,eAAe,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,CA6BtF;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAEpE;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,IAAI,SAAS,OAAO,EAAE,EAAE,CAAC,EACzD,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,EACf,MAAM,EAAE,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,KAAK,CAAC,GAAG,IAAI,EAAE,IAAI,KAAK,CAAC,GAC/F,CAAC,GAAG,IAAI,EAAE,IAAI,KAAK,CAAC,CAKtB"}
|
package/dist/hooks/useStore.js
CHANGED
|
@@ -6,6 +6,20 @@
|
|
|
6
6
|
import { useCallback, useContext, useRef, useSyncExternalStore } from 'react';
|
|
7
7
|
import { t } from '@molecule/app-i18n';
|
|
8
8
|
import { StateContext } from '../contexts.js';
|
|
9
|
+
/**
|
|
10
|
+
* The fix, appended to the error below — this hook is the one place that READS
|
|
11
|
+
* the context, so it is the one place that has to say where the context comes
|
|
12
|
+
* from. The sentences are code (an import, a component, a bond call), so they
|
|
13
|
+
* are appended in English rather than translated.
|
|
14
|
+
*/
|
|
15
|
+
const STATE_CONTEXT_FIX = ' To fix: render a state provider above this component — ' +
|
|
16
|
+
"`import { MoleculeProvider, StateProvider } from '@molecule/app-react'`; " +
|
|
17
|
+
'<MoleculeProvider> passes the provider bonded under `@molecule/app-state` ' +
|
|
18
|
+
'(bond one with `setupAllDefaultBonds()` from `@molecule/app-bonds-default-react`, ' +
|
|
19
|
+
'or `setProvider(provider)` from `@molecule/app-state`), and ' +
|
|
20
|
+
'<StateProvider provider={provider}> passes one you hold. ' +
|
|
21
|
+
'To read a store you already have, call useStore(store) instead — it subscribes to the ' +
|
|
22
|
+
'store it is given and needs no provider.';
|
|
9
23
|
/**
|
|
10
24
|
* Hook to access the state provider from context.
|
|
11
25
|
*
|
|
@@ -13,21 +27,31 @@ import { StateContext } from '../contexts.js';
|
|
|
13
27
|
* `<MoleculeProvider>` — which supplies the provider bonded under
|
|
14
28
|
* `@molecule/app-state` by default, so a scaffolded app needs no `state` prop.
|
|
15
29
|
*
|
|
30
|
+
* Only hooks that read the context call this; `useStore(store)` takes its store
|
|
31
|
+
* as an argument and works with no provider at all.
|
|
32
|
+
*
|
|
16
33
|
* @returns The state provider from context
|
|
17
|
-
* @throws {Error}
|
|
34
|
+
* @throws {Error} when no `StateProvider` is above the component — the message
|
|
35
|
+
* names the fix (which provider to render, and the import for it).
|
|
18
36
|
*/
|
|
19
37
|
export function useStateProvider() {
|
|
20
38
|
const provider = useContext(StateContext);
|
|
21
39
|
if (!provider) {
|
|
22
40
|
throw new Error(t('react.error.useStoreOutsideProvider', undefined, {
|
|
23
41
|
defaultValue: 'useStateProvider must be used within a StateProvider',
|
|
24
|
-
}));
|
|
42
|
+
}) + STATE_CONTEXT_FIX);
|
|
25
43
|
}
|
|
26
44
|
return provider;
|
|
27
45
|
}
|
|
28
46
|
/**
|
|
29
47
|
* Hook to subscribe to a store with optional selector and equality function.
|
|
30
48
|
*
|
|
49
|
+
* The store is the argument, so this hook needs NO `StateProvider`: it reads
|
|
50
|
+
* `store.getState()` and subscribes with `store.subscribe()`, and never touches
|
|
51
|
+
* the state context. A store minted outside the `state` bond — the direct
|
|
52
|
+
* `createStoreWithActions()` / `createStore()` a provider package exports — is
|
|
53
|
+
* therefore as valid here as one `@molecule/app-state`'s `createStore()` made.
|
|
54
|
+
*
|
|
31
55
|
* @param store - The store to subscribe to
|
|
32
56
|
* @param options - Hook options (selector, equalityFn)
|
|
33
57
|
* @returns The selected state
|
|
@@ -39,8 +63,6 @@ export function useStateProvider() {
|
|
|
39
63
|
* ```
|
|
40
64
|
*/
|
|
41
65
|
export function useStore(store, options) {
|
|
42
|
-
// Validate that we're within a StateProvider
|
|
43
|
-
useStateProvider();
|
|
44
66
|
const { selector, equalityFn } = options ?? {};
|
|
45
67
|
// Use a ref to track the previous selected value for equality comparison
|
|
46
68
|
const prevSelectedRef = useRef(undefined);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useStore.js","sourceRoot":"","sources":["../../src/hooks/useStore.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAA;AAE7E,OAAO,EAAE,CAA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CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAE,KAAsB,CAAA;QAErE,uEAAuE;QACvE,IAAI,UAAU,IAAI,eAAe,CAAC,OAAO,KAAK,SAAS,EAAE,CAAC;YACxD,IAAI,UAAU,CAAC,eAAe,CAAC,OAAO,EAAE,QAAQ,CAAC,EAAE,CAAC;gBAClD,OAAO,eAAe,CAAC,OAAO,CAAA;YAChC,CAAC;QACH,CAAC;QAED,eAAe,CAAC,OAAO,GAAG,QAAQ,CAAA;QAClC,OAAO,QAAQ,CAAA;IACjB,CAAC,EAAE,CAAC,KAAK,EAAE,QAAQ,EAAE,UAAU,CAAC,CAAC,CAAA;IAEjC,MAAM,SAAS,GAAG,WAAW,CAC3B,CAAC,aAAyB,EAAE,EAAE;QAC5B,OAAO,KAAK,CAAC,SAAS,CAAC,aAAa,CAAC,CAAA;IACvC,CAAC,EACD,CAAC,KAAK,CAAC,CACR,CAAA;IAED,OAAO,oBAAoB,CAAC,SAAS,EAAE,WAAW,EAAE,WAAW,CAAC,CAAA;AAClE,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,WAAW,CAAI,KAAe;IAC5C,OAAO,KAAK,CAAC,QAAQ,CAAA;AACvB,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,cAAc,CAC5B,KAAe,EACf,MAAgG;IAEhG,OAAO,WAAW,CAChB,CAAC,GAAG,IAAU,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAC,GAAG,IAAI,CAAC,EAClE,CAAC,KAAK,EAAE,MAAM,CAAC,CAChB,CAAA;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@molecule/app-react",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.5",
|
|
4
4
|
"description": "React framework bindings for molecule.dev",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
},
|
|
60
60
|
"devDependencies": {
|
|
61
61
|
"@molecule/app-ai-models": "1.4.0",
|
|
62
|
-
"@molecule/app-bonds-default-react": "1.1.
|
|
62
|
+
"@molecule/app-bonds-default-react": "1.1.2",
|
|
63
63
|
"@molecule/app-i18n": "1.0.3",
|
|
64
64
|
"@testing-library/dom": "10.4.1",
|
|
65
65
|
"@testing-library/react": "16.3.2",
|