@octanejs/livestore 0.0.26 → 0.0.28
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/UPSTREAM.md +15 -0
- package/package.json +4 -4
- package/src/useStore.ts +20 -2
package/UPSTREAM.md
CHANGED
|
@@ -83,3 +83,18 @@ ownership in `audit/test-classifications.json`.
|
|
|
83
83
|
- Public query instrumentation uses the label `octane`. The framework-neutral
|
|
84
84
|
toolkit's internal refresh tag remains `react` because that released core API
|
|
85
85
|
is reused unchanged.
|
|
86
|
+
- Once a `useStore()` call site has suspended, it keeps calling `use()` on the
|
|
87
|
+
promise it suspended on after the store loads. Upstream calls `React.use()`
|
|
88
|
+
only while `getOrLoadPromise()` returns a promise. `use()` is positional in
|
|
89
|
+
both frameworks, and a replay reuses the thenable already stored at a
|
|
90
|
+
position, so skipping it gives a following `useStore()` in the same
|
|
91
|
+
component the loaded store instead of suspending on its own. React 19.2.3
|
|
92
|
+
hits this only when it replays a suspended component in place, for example
|
|
93
|
+
a transition that switches a mounted component to two unloaded stores and
|
|
94
|
+
the first loads while React waits: it commits the first store for both
|
|
95
|
+
calls. Octane replays a Suspense body after every settle, so without the
|
|
96
|
+
guard every such component would get the wrong store. The call still
|
|
97
|
+
returns the store that `getOrLoadPromise()` returns synchronously, and
|
|
98
|
+
`getOrLoadPromise()` still runs on every render.
|
|
99
|
+
`tests/conformance/sequential-stores.test.ts` covers mount, transition, a
|
|
100
|
+
real `StoreRegistry`, and `useActionState` commits after a Suspense load.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@octanejs/livestore",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.28",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"@opentelemetry/api": "1.9.0"
|
|
50
50
|
},
|
|
51
51
|
"peerDependencies": {
|
|
52
|
-
"octane": "^0.
|
|
52
|
+
"octane": "^0.8.0"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
55
|
"@livestore/adapter-web": "0.4.0",
|
|
@@ -68,12 +68,12 @@
|
|
|
68
68
|
"react-window": "1.8.11",
|
|
69
69
|
"vite": "7.3.1",
|
|
70
70
|
"vitest": "^4.1.10",
|
|
71
|
-
"octane": "0.
|
|
71
|
+
"octane": "0.8.0"
|
|
72
72
|
},
|
|
73
73
|
"scripts": {
|
|
74
74
|
"test": "vitest run --config vitest.config.ts && vitest run --config vitest.ssr.config.ts",
|
|
75
75
|
"test:upstream": "node ../../scripts/react-parity/run-pristine.mjs livestore",
|
|
76
|
-
"typecheck": "
|
|
76
|
+
"typecheck": "octane-tsc -p tsconfig.json -p typetests/tsconfig.json",
|
|
77
77
|
"upstream:verify": "node ../../scripts/react-port/materialize.mjs run --check --package-dir ."
|
|
78
78
|
}
|
|
79
79
|
}
|
package/src/useStore.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { LiveStoreSchema } from '@livestore/common/schema';
|
|
|
2
2
|
import { SessionIdSymbol } from '@livestore/common';
|
|
3
3
|
import type { RegistryStoreOptions, Store, SyncStatus } from '@livestore/livestore';
|
|
4
4
|
import type { Schema } from '@livestore/utils/effect';
|
|
5
|
-
import { use, useEffect } from 'octane';
|
|
5
|
+
import { use, useEffect, useMemo } from 'octane';
|
|
6
6
|
import { useStoreRegistry } from './StoreRegistryContext.tsrx';
|
|
7
7
|
import { splitSlot, subSlot } from './internal';
|
|
8
8
|
import { useClientDocument } from './useClientDocument';
|
|
@@ -32,8 +32,26 @@ export function useStore<
|
|
|
32
32
|
): Store<TSchema, TContext> & ReactApi {
|
|
33
33
|
const [, slot] = splitSlot(rest);
|
|
34
34
|
const storeRegistry = useStoreRegistry();
|
|
35
|
+
// Called on every render, as upstream does: a loaded store returns synchronously.
|
|
35
36
|
const storeOrPromise = storeRegistry.getOrLoadPromise(options);
|
|
36
|
-
const
|
|
37
|
+
const loading = useMemo<{ promise: PromiseLike<unknown> | undefined }>(
|
|
38
|
+
() => ({ promise: undefined }),
|
|
39
|
+
[storeRegistry, options.storeId],
|
|
40
|
+
subSlot(slot, 'store:loading'),
|
|
41
|
+
);
|
|
42
|
+
let store: Store<TSchema, TContext>;
|
|
43
|
+
if (storeOrPromise instanceof Promise) {
|
|
44
|
+
loading.promise = storeOrPromise;
|
|
45
|
+
store = use(storeOrPromise);
|
|
46
|
+
} else {
|
|
47
|
+
// use() is positional. Once this call site has suspended, keep reading the
|
|
48
|
+
// promise it suspended on after the store loads, so the call keeps its
|
|
49
|
+
// position when the boundary replays. Skipping use() here would hand this
|
|
50
|
+
// call's position to the next useStore() in the component, and the replay
|
|
51
|
+
// would return this store to that call instead of suspending on its own.
|
|
52
|
+
if (loading.promise !== undefined) use(loading.promise);
|
|
53
|
+
store = storeOrPromise;
|
|
54
|
+
}
|
|
37
55
|
useEffect(
|
|
38
56
|
() => storeRegistry.retain(options),
|
|
39
57
|
[storeRegistry, options],
|