@livestore/react 0.3.0-dev.50 → 0.3.0-dev.52
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/dist/.tsbuildinfo +1 -1
- package/dist/LiveStoreProvider.js +5 -9
- package/dist/LiveStoreProvider.js.map +1 -1
- package/dist/LiveStoreProvider.test.js +14 -35
- package/dist/LiveStoreProvider.test.js.map +1 -1
- package/dist/__tests__/fixture.d.ts +1 -2
- package/dist/__tests__/fixture.d.ts.map +1 -1
- package/dist/__tests__/fixture.js +2 -2
- package/dist/__tests__/fixture.js.map +1 -1
- package/dist/experimental/components/LiveList.js +3 -2
- package/dist/experimental/components/LiveList.js.map +1 -1
- package/dist/useClientDocument.test.js +5 -10
- package/dist/useClientDocument.test.js.map +1 -1
- package/dist/useQuery.d.ts.map +1 -1
- package/dist/useQuery.js +5 -4
- package/dist/useQuery.js.map +1 -1
- package/dist/useQuery.test.js +14 -4
- package/dist/useQuery.test.js.map +1 -1
- package/dist/useRcResource.d.ts +1 -1
- package/dist/useRcResource.d.ts.map +1 -1
- package/dist/useRcResource.js +2 -0
- package/dist/useRcResource.js.map +1 -1
- package/package.json +6 -6
- package/src/useQuery.test.tsx +16 -0
- package/src/useQuery.ts +8 -4
- package/src/useRcResource.ts +3 -1
package/dist/useRcResource.js
CHANGED
|
@@ -73,6 +73,7 @@ import * as React from 'react';
|
|
|
73
73
|
export const useRcResource = (key, create, dispose, _options) => {
|
|
74
74
|
const keyRef = React.useRef(undefined);
|
|
75
75
|
const didDisposeInMemo = React.useRef(false);
|
|
76
|
+
// biome-ignore lint/correctness/useExhaustiveDependencies: <explanation>
|
|
76
77
|
const resource = React.useMemo(() => {
|
|
77
78
|
// console.debug('useMemo', key)
|
|
78
79
|
if (didDisposeInMemo.current) {
|
|
@@ -114,6 +115,7 @@ export const useRcResource = (key, create, dispose, _options) => {
|
|
|
114
115
|
// Dependency is deliberately limited to `key` to avoid unintended re-creations.
|
|
115
116
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
116
117
|
}, [key]);
|
|
118
|
+
// biome-ignore lint/correctness/useExhaustiveDependencies: <explanation>
|
|
117
119
|
React.useEffect(() => {
|
|
118
120
|
return () => {
|
|
119
121
|
if (didDisposeInMemo.current) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useRcResource.js","sourceRoot":"","sources":["../src/useRcResource.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsEG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAC3B,GAAW,EACX,MAAe,EACf,OAAuC,EACvC,QAAwE,
|
|
1
|
+
{"version":3,"file":"useRcResource.js","sourceRoot":"","sources":["../src/useRcResource.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsEG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAC3B,GAAW,EACX,MAAe,EACf,OAAuC,EACvC,QAAwE,EACrE,EAAE;IACL,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,CAAqB,SAAS,CAAC,CAAA;IAC1D,MAAM,gBAAgB,GAAG,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;IAE5C,yEAAyE;IACzE,MAAM,QAAQ,GAAG,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE;QAClC,gCAAgC;QAChC,IAAI,gBAAgB,CAAC,OAAO,EAAE,CAAC;YAC7B,wCAAwC;YACxC,MAAM,UAAU,GAAG,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;YACjC,IAAI,UAAU,KAAK,SAAS,IAAI,UAAU,CAAC,IAAI,KAAK,QA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ev.52",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"exports": {
|
|
@@ -23,9 +23,9 @@
|
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"@opentelemetry/api": "1.9.0",
|
|
26
|
-
"@livestore/
|
|
27
|
-
"@livestore/
|
|
28
|
-
"@livestore/
|
|
26
|
+
"@livestore/common": "0.3.0-dev.52",
|
|
27
|
+
"@livestore/livestore": "0.3.0-dev.52",
|
|
28
|
+
"@livestore/utils": "0.3.0-dev.52"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"@opentelemetry/sdk-trace-base": "^2.0.0",
|
|
@@ -40,8 +40,8 @@
|
|
|
40
40
|
"typescript": "^5.8.3",
|
|
41
41
|
"vite": "^6.3.4",
|
|
42
42
|
"vitest": "^3.1.2",
|
|
43
|
-
"@livestore/utils-dev": "0.3.0-dev.
|
|
44
|
-
"@livestore/adapter-web": "0.3.0-dev.
|
|
43
|
+
"@livestore/utils-dev": "0.3.0-dev.52",
|
|
44
|
+
"@livestore/adapter-web": "0.3.0-dev.52"
|
|
45
45
|
},
|
|
46
46
|
"files": [
|
|
47
47
|
"package.json",
|
package/src/useQuery.test.tsx
CHANGED
|
@@ -161,6 +161,7 @@ Vitest.describe.each([{ strictMode: true }, { strictMode: false }] as const)(
|
|
|
161
161
|
const ListItem: React.FC<{ data: ReadonlyArray<number>; index: number }> = ({ data: ids, index }) => {
|
|
162
162
|
const id = ids[index]!
|
|
163
163
|
const res = store.useQuery(LiveStore.computed(() => id, { label: `ListItem.${id}`, deps: id }))
|
|
164
|
+
// biome-ignore lint/a11y/useSemanticElements: <explanation>
|
|
164
165
|
return <div role="listitem">{res}</div>
|
|
165
166
|
}
|
|
166
167
|
|
|
@@ -173,5 +174,20 @@ Vitest.describe.each([{ strictMode: true }, { strictMode: false }] as const)(
|
|
|
173
174
|
expect(renderResult.container.textContent).toBe('10')
|
|
174
175
|
}),
|
|
175
176
|
)
|
|
177
|
+
|
|
178
|
+
Vitest.scopedLive('should work with signal', () =>
|
|
179
|
+
Effect.gen(function* () {
|
|
180
|
+
const { wrapper, store } = yield* makeTodoMvcReact({ strictMode })
|
|
181
|
+
const num$ = signal(0)
|
|
182
|
+
|
|
183
|
+
const { result } = ReactTesting.renderHook(() => store.useQuery(num$), { wrapper })
|
|
184
|
+
|
|
185
|
+
expect(result.current).toBe(0)
|
|
186
|
+
|
|
187
|
+
ReactTesting.act(() => store.setSignal(num$, 1))
|
|
188
|
+
|
|
189
|
+
expect(result.current).toBe(1)
|
|
190
|
+
}),
|
|
191
|
+
)
|
|
176
192
|
},
|
|
177
193
|
)
|
package/src/useQuery.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/* eslint-disable react-hooks/rules-of-hooks */
|
|
1
2
|
import type { LiveQuery, LiveQueryDef, Store } from '@livestore/livestore'
|
|
2
3
|
import { extractStackInfoFromStackTrace, stackInfoToString } from '@livestore/livestore'
|
|
3
4
|
import type { LiveQueries } from '@livestore/livestore/internal'
|
|
@@ -42,10 +43,7 @@ export const useQueryRef = <TQuery extends LiveQueryDef.Any>(
|
|
|
42
43
|
queryRcRef: LiveQueries.RcRef<LiveQuery<LiveQueries.GetResult<TQuery>>>
|
|
43
44
|
} => {
|
|
44
45
|
const store =
|
|
45
|
-
options?.store ??
|
|
46
|
-
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
47
|
-
React.useContext(LiveStoreContext)?.store ??
|
|
48
|
-
shouldNeverHappen(`No store provided to useQuery`)
|
|
46
|
+
options?.store ?? React.useContext(LiveStoreContext)?.store ?? shouldNeverHappen(`No store provided to useQuery`)
|
|
49
47
|
|
|
50
48
|
// It's important to use all "aspects" of a store instance here, otherwise we get unexpected cache mappings
|
|
51
49
|
const rcRefKey = `${store.storeId}_${store.clientId}_${store.sessionId}_${queryDef.hash}`
|
|
@@ -79,6 +77,11 @@ export const useQueryRef = <TQuery extends LiveQueryDef.Any>(
|
|
|
79
77
|
// which takes care of disposing the queryRcRef
|
|
80
78
|
() => {},
|
|
81
79
|
)
|
|
80
|
+
|
|
81
|
+
// if (queryRcRef.value._tag === 'signal') {
|
|
82
|
+
// const queryRcRef.value.get()
|
|
83
|
+
// }
|
|
84
|
+
|
|
82
85
|
const query$ = queryRcRef.value as LiveQuery<LiveQueries.GetResult<TQuery>>
|
|
83
86
|
|
|
84
87
|
React.useDebugValue(`LiveStore:useQuery:${query$.id}:${query$.label}`)
|
|
@@ -96,6 +99,7 @@ export const useQueryRef = <TQuery extends LiveQueryDef.Any>(
|
|
|
96
99
|
},
|
|
97
100
|
})
|
|
98
101
|
} catch (cause: any) {
|
|
102
|
+
console.error('[@livestore/react:useQuery] Error running query', cause)
|
|
99
103
|
throw new Error(
|
|
100
104
|
`\
|
|
101
105
|
[@livestore/react:useQuery] Error running query: ${cause.name}
|
package/src/useRcResource.ts
CHANGED
|
@@ -76,10 +76,11 @@ export const useRcResource = <T>(
|
|
|
76
76
|
create: () => T,
|
|
77
77
|
dispose: (resource: NoInfer<T>) => void,
|
|
78
78
|
_options?: { debugPrint?: (resource: NoInfer<T>) => ReadonlyArray<any> },
|
|
79
|
-
) => {
|
|
79
|
+
): T => {
|
|
80
80
|
const keyRef = React.useRef<string | undefined>(undefined)
|
|
81
81
|
const didDisposeInMemo = React.useRef(false)
|
|
82
82
|
|
|
83
|
+
// biome-ignore lint/correctness/useExhaustiveDependencies: <explanation>
|
|
83
84
|
const resource = React.useMemo(() => {
|
|
84
85
|
// console.debug('useMemo', key)
|
|
85
86
|
if (didDisposeInMemo.current) {
|
|
@@ -128,6 +129,7 @@ export const useRcResource = <T>(
|
|
|
128
129
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
129
130
|
}, [key])
|
|
130
131
|
|
|
132
|
+
// biome-ignore lint/correctness/useExhaustiveDependencies: <explanation>
|
|
131
133
|
React.useEffect(() => {
|
|
132
134
|
return () => {
|
|
133
135
|
if (didDisposeInMemo.current) {
|