@livestore/react 0.3.0-dev.11 → 0.3.0-dev.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.
Files changed (80) hide show
  1. package/dist/.tsbuildinfo +1 -1
  2. package/dist/LiveStoreContext.d.ts +3 -5
  3. package/dist/LiveStoreContext.d.ts.map +1 -1
  4. package/dist/LiveStoreContext.js +3 -7
  5. package/dist/LiveStoreContext.js.map +1 -1
  6. package/dist/LiveStoreProvider.d.ts +1 -2
  7. package/dist/LiveStoreProvider.d.ts.map +1 -1
  8. package/dist/LiveStoreProvider.js +20 -5
  9. package/dist/LiveStoreProvider.js.map +1 -1
  10. package/dist/__tests__/fixture.d.ts +9 -6
  11. package/dist/__tests__/fixture.d.ts.map +1 -1
  12. package/dist/__tests__/fixture.js +7 -6
  13. package/dist/__tests__/fixture.js.map +1 -1
  14. package/dist/experimental/components/LiveList.d.ts +2 -2
  15. package/dist/experimental/components/LiveList.d.ts.map +1 -1
  16. package/dist/experimental/components/LiveList.js +4 -5
  17. package/dist/experimental/components/LiveList.js.map +1 -1
  18. package/dist/mod.d.ts +1 -0
  19. package/dist/mod.d.ts.map +1 -1
  20. package/dist/mod.js +1 -0
  21. package/dist/mod.js.map +1 -1
  22. package/dist/useAtom.d.ts +2 -4
  23. package/dist/useAtom.d.ts.map +1 -1
  24. package/dist/useAtom.js +28 -32
  25. package/dist/useAtom.js.map +1 -1
  26. package/dist/useQuery.d.ts +3 -26
  27. package/dist/useQuery.d.ts.map +1 -1
  28. package/dist/useQuery.js +45 -60
  29. package/dist/useQuery.js.map +1 -1
  30. package/dist/useQuery.test.js +16 -70
  31. package/dist/useQuery.test.js.map +1 -1
  32. package/dist/useRow.d.ts +7 -10
  33. package/dist/useRow.d.ts.map +1 -1
  34. package/dist/useRow.js +19 -16
  35. package/dist/useRow.js.map +1 -1
  36. package/dist/useRow.test.js +96 -74
  37. package/dist/useRow.test.js.map +1 -1
  38. package/dist/useScopedQuery.d.ts +4 -10
  39. package/dist/useScopedQuery.d.ts.map +1 -1
  40. package/dist/useScopedQuery.js +52 -97
  41. package/dist/useScopedQuery.js.map +1 -1
  42. package/dist/useScopedQuery.test.js +12 -13
  43. package/dist/useScopedQuery.test.js.map +1 -1
  44. package/dist/utils/useStateRefWithReactiveInput.d.ts +1 -1
  45. package/dist/utils/useStateRefWithReactiveInput.d.ts.map +1 -1
  46. package/dist/utils/useStateRefWithReactiveInput.js.map +1 -1
  47. package/package.json +17 -18
  48. package/src/LiveStoreContext.ts +6 -10
  49. package/src/LiveStoreProvider.tsx +21 -7
  50. package/src/__snapshots__/useRow.test.tsx.snap +149 -337
  51. package/src/__tests__/fixture.tsx +10 -7
  52. package/src/experimental/components/LiveList.tsx +7 -8
  53. package/src/mod.ts +1 -0
  54. package/src/useAtom.ts +11 -22
  55. package/src/useQuery.test.tsx +67 -165
  56. package/src/useQuery.ts +54 -84
  57. package/src/useRow.test.tsx +163 -130
  58. package/src/useRow.ts +35 -32
  59. package/src/useScopedQuery.test.tsx +96 -0
  60. package/src/useScopedQuery.ts +142 -0
  61. package/src/utils/useStateRefWithReactiveInput.ts +1 -1
  62. package/dist/useRcRef.d.ts +0 -72
  63. package/dist/useRcRef.d.ts.map +0 -1
  64. package/dist/useRcRef.js +0 -146
  65. package/dist/useRcRef.js.map +0 -1
  66. package/dist/useRcRef.test.d.ts +0 -2
  67. package/dist/useRcRef.test.d.ts.map +0 -1
  68. package/dist/useRcRef.test.js +0 -128
  69. package/dist/useRcRef.test.js.map +0 -1
  70. package/dist/useRcResource.d.ts +0 -76
  71. package/dist/useRcResource.d.ts.map +0 -1
  72. package/dist/useRcResource.js +0 -150
  73. package/dist/useRcResource.js.map +0 -1
  74. package/dist/useRcResource.test.d.ts +0 -2
  75. package/dist/useRcResource.test.d.ts.map +0 -1
  76. package/dist/useRcResource.test.js +0 -122
  77. package/dist/useRcResource.test.js.map +0 -1
  78. package/src/__snapshots__/useQuery.test.tsx.snap +0 -2011
  79. package/src/useRcResource.test.tsx +0 -167
  80. package/src/useRcResource.ts +0 -180
@@ -1,20 +1,19 @@
1
1
  import * as LiveStore from '@livestore/livestore';
2
2
  import { queryDb } from '@livestore/livestore';
3
3
  import { Effect, Schema } from '@livestore/utils/effect';
4
- import { Vitest } from '@livestore/utils/node-vitest';
5
4
  import { render, renderHook } from '@testing-library/react';
6
5
  import React from 'react';
7
6
  // @ts-expect-error no types
8
7
  import * as ReactWindow from 'react-window';
9
- import { expect } from 'vitest';
8
+ import { describe, expect, it } from 'vitest';
10
9
  import { makeTodoMvcReact, tables, todos } from './__tests__/fixture.js';
11
10
  import * as LiveStoreReact from './mod.js';
12
- Vitest.describe('useScopedQuery', () => {
13
- Vitest.scopedLive('simple', () => Effect.gen(function* () {
14
- const { wrapper, store, renderCount } = yield* makeTodoMvcReact();
11
+ describe('useScopedQuery', () => {
12
+ it('simple', () => Effect.gen(function* () {
13
+ const { wrapper, store, makeRenderCount } = yield* makeTodoMvcReact();
14
+ const renderCount = makeRenderCount();
15
15
  store.mutate(todos.insert({ id: 't1', text: 'buy milk', completed: false }), todos.insert({ id: 't2', text: 'buy bread', completed: false }));
16
16
  const queryMap = new Map();
17
- const getRuns = (key) => store.reactivityGraph.context.liveQueryRCMap.get(queryMap.get(key).hash).query$.runs;
18
17
  const { rerender, result, unmount } = renderHook((id) => {
19
18
  renderCount.inc();
20
19
  return LiveStoreReact.useScopedQuery(() => {
@@ -29,20 +28,20 @@ Vitest.describe('useScopedQuery', () => {
29
28
  expect(result.current.length).toBe(1);
30
29
  expect(result.current[0].text).toBe('buy milk');
31
30
  expect(renderCount.val).toBe(1);
32
- expect(getRuns('t1')).toBe(1);
31
+ expect(queryMap.get('t1').runs).toBe(1);
33
32
  rerender('t2');
34
33
  expect(result.current.length).toBe(1);
35
34
  expect(result.current[0].text).toBe('buy bread');
36
35
  expect(renderCount.val).toBe(2);
37
- expect(getRuns('t1')).toBe(1);
38
- expect(getRuns('t2')).toBe(1);
36
+ expect(queryMap.get('t1').runs).toBe(1);
37
+ expect(queryMap.get('t2').runs).toBe(1);
39
38
  unmount();
40
- expect(getRuns('t2')).toBe(1);
41
- }));
39
+ expect(queryMap.get('t2').runs).toBe(1);
40
+ }).pipe(Effect.scoped, Effect.tapCauseLogPretty, Effect.runPromise));
42
41
  // NOTE this test covers some special react lifecyle paths which I couldn't easily reproduce without react-window
43
42
  // it basically causes a "query swap" in the `useMemo` and both a `useEffect` cleanup call.
44
43
  // To handle this properly we introduced the `_tag: 'destroyed'` state in the `spanAlreadyStartedCache`.
45
- Vitest.scopedLive('should work for a list with react-window', () => Effect.gen(function* () {
44
+ it('should work for a list with react-window', () => Effect.gen(function* () {
46
45
  const { wrapper } = yield* makeTodoMvcReact();
47
46
  const ListWrapper = ({ numItems }) => {
48
47
  return (React.createElement(ReactWindow.FixedSizeList, { height: 100, width: 100, itemSize: 10, itemCount: numItems, itemData: Array.from({ length: numItems }, (_, i) => i).reverse() }, ListItem));
@@ -56,6 +55,6 @@ Vitest.describe('useScopedQuery', () => {
56
55
  expect(renderResult.container.textContent).toBe('0');
57
56
  renderResult.rerender(React.createElement(ListWrapper, { numItems: 2 }));
58
57
  expect(renderResult.container.textContent).toBe('10');
59
- }));
58
+ }).pipe(Effect.scoped, Effect.tapCauseLogPretty, Effect.runPromise));
60
59
  });
61
60
  //# sourceMappingURL=useScopedQuery.test.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useScopedQuery.test.js","sourceRoot":"","sources":["../src/useScopedQuery.test.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,SAAS,MAAM,sBAAsB,CAAA;AACjD,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAA;AAC9C,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;AACxD,OAAO,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAA;AACrD,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AAC3D,OAAO,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
- export declare const useStateRefWithReactiveInput: <T>(inputState: T) => [React.RefObject<T>, (newState: T | ((prev: T) => T)) => void];
12
+ export declare const useStateRefWithReactiveInput: <T>(inputState: T) => [React.MutableRefObject<T>, (newState: T | ((prev: T) => T)) => void];
13
13
  //# sourceMappingURL=useStateRefWithReactiveInput.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useStateRefWithReactiveInput.d.ts","sourceRoot":"","sources":["../../src/utils/useStateRefWithReactiveInput.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB;;;;;;;;;GASG;AACH,eAAO,MAAM,4BAA4B,GAAI,CAAC,cAChC,CAAC,KACZ,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,QAAQ,EAAE,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,IAAI,CAwB/D,CAAA"}
1
+ {"version":3,"file":"useStateRefWithReactiveInput.d.ts","sourceRoot":"","sources":["../../src/utils/useStateRefWithReactiveInput.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB;;;;;;;;;GASG;AACH,eAAO,MAAM,4BAA4B,GAAI,CAAC,cAChC,CAAC,KACZ,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC,CAAC,EAAE,CAAC,QAAQ,EAAE,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,IAAI,CAwBtE,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"useStateRefWithReactiveInput.js","sourceRoot":"","sources":["../../src/utils/useStateRefWithReactiveInput.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,4BAA4B,GAAG,CAC1C,UAAa,EACmD,EAAE;IAClE,MAAM,CAAC,CAAC,EAAE,QAAQ,CAAC,GAAG,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AQ,CAAC,CAAC,CAAC,CAAA;IAEvC,MAAM,sBAAsB,GAAG,KAAK,CAAC,MAAM,CAAI,UAAU,CAAC,CAAA;IAC1D,MAAM,QAAQ,GAAG,KAAK,CAAC,MAAM,CAAI,UAAU,CAAC,CAAA;IAE5C,IAAI,sBAAsB,CAAC,OAAO,KAAK,UAAU,EAAE,CAAC;QAClD,sBAAsB,CAAC,OAAO,GAAG,UAAU,CAAA;QAE3C,qHAAqH;QACrH,QAAQ,CAAC,OAAO,GAAG,UAAU,CAAA;IAC/B,CAAC;IAED,MAAM,mBAAmB,GAAG,KAAK,CAAC,WAAW,CAC3C,CAAC,QAA8B,EAAE,EAAE;QACjC,wEAAwE;QACxE,MAAM,GAAG,GAAG,OAAO,QAAQ,KAAK,UAAU,CAAC,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAA;QAClF,QAAQ,CAAC,OAAO,GAAG,GAAG,CAAA;QACtB,QAAQ,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAA;IACxB,CAAC,EACD,CAAC,QAAQ,CAAC,CACX,CAAA;IAED,OAAO,CAAC,QAAQ,EAAE,mBAAmB,CAAC,CAAA;AACxC,CAAC,CAAA;AAED,yGAAyG;AACzG,iFAAiF;AACjF,4GAA4G;AAC5G,yEAAyE;AAEzE,wCAAwC;AACxC,mCAAmC;AACnC,MAAM;AAEN,6CAA6C;AAC7C,IAAI"}
package/package.json CHANGED
@@ -1,8 +1,7 @@
1
1
  {
2
2
  "name": "@livestore/react",
3
- "version": "0.3.0-dev.11",
3
+ "version": "0.3.0-dev.5",
4
4
  "type": "module",
5
- "sideEffects": false,
6
5
  "exports": {
7
6
  ".": {
8
7
  "types": "./dist/mod.d.ts",
@@ -22,28 +21,28 @@
22
21
  }
23
22
  },
24
23
  "dependencies": {
25
- "@opentelemetry/api": "1.9.0",
26
- "@livestore/common": "0.3.0-dev.11",
27
- "@livestore/livestore": "0.3.0-dev.11",
28
- "@livestore/db-schema": "0.3.0-dev.11",
29
- "@livestore/utils": "0.3.0-dev.11"
24
+ "@opentelemetry/api": "^1.9.0",
25
+ "@livestore/common": "0.3.0-dev.5",
26
+ "@livestore/utils": "0.3.0-dev.5",
27
+ "@livestore/livestore": "0.3.0-dev.5",
28
+ "@livestore/db-schema": "0.3.0-dev.5"
30
29
  },
31
30
  "devDependencies": {
32
- "@opentelemetry/sdk-trace-base": "^1.30.1",
31
+ "@opentelemetry/sdk-trace-base": "1.30.0",
33
32
  "@testing-library/react": "^16.0.1",
34
- "@types/react": "^19.0.8",
35
- "@types/react-dom": "^19.0.3",
36
- "jsdom": "^26.0.0",
37
- "react": "^19.0.0",
38
- "react-dom": "^19.0.0",
39
- "react-window": "^1.8.11",
40
- "typescript": "^5.7.2",
41
- "vite": "^6.0.11",
33
+ "@types/react": "^18.3.12",
34
+ "@types/react-dom": "^18.3.1",
35
+ "jsdom": "^25.0.1",
36
+ "react": "18.3.1",
37
+ "react-dom": "^18.3.1",
38
+ "react-window": "^1.8.10",
39
+ "typescript": "5.7.2",
40
+ "vite": "5.4.10",
42
41
  "vitest": "^2.1.4",
43
- "@livestore/web": "0.3.0-dev.11"
42
+ "@livestore/web": "0.3.0-dev.5"
44
43
  },
45
44
  "peerDependencies": {
46
- "react": "~19.0.0"
45
+ "react": "18.3.1"
47
46
  },
48
47
  "publishConfig": {
49
48
  "access": "public"
@@ -1,15 +1,11 @@
1
- import type { LiveStoreContextRunning, Store } from '@livestore/livestore'
2
- import React from 'react'
1
+ import type { Store } from '@livestore/livestore'
2
+ import type { LiveStoreContextRunning as LiveStoreContext_ } from '@livestore/livestore/effect'
3
+ import React, { useContext } from 'react'
3
4
 
4
- export const LiveStoreContext = React.createContext<LiveStoreContextRunning | undefined>(undefined)
5
+ export const LiveStoreContext = React.createContext<LiveStoreContext_ | undefined>(undefined)
5
6
 
6
- export const useStore = (options?: { store?: Store }): { store: Store } => {
7
- if (options?.store !== undefined) {
8
- return { store: options.store }
9
- }
10
-
11
- // eslint-disable-next-line react-hooks/rules-of-hooks
12
- const storeContext = React.useContext(LiveStoreContext)
7
+ export const useStore = (): { store: Store } => {
8
+ const storeContext = useContext(LiveStoreContext)
13
9
 
14
10
  if (storeContext === undefined) {
15
11
  throw new Error(`useStore can only be used inside StoreContext.Provider`)
@@ -11,9 +11,9 @@ import type {
11
11
  Store,
12
12
  } from '@livestore/livestore'
13
13
  import { createStore, StoreAbort, StoreInterrupted } from '@livestore/livestore'
14
- import { errorToString, LS_DEV } from '@livestore/utils'
14
+ import { errorToString } from '@livestore/utils'
15
15
  import type { OtelTracer } from '@livestore/utils/effect'
16
- import { Deferred, Effect, Exit, identity, Logger, LogLevel, Schema, Scope, TaskTracing } from '@livestore/utils/effect'
16
+ import { Deferred, Effect, Exit, Logger, LogLevel, Schema, Scope } from '@livestore/utils/effect'
17
17
  import type * as otel from '@opentelemetry/api'
18
18
  import type { ReactElement, ReactNode } from 'react'
19
19
  import React from 'react'
@@ -92,7 +92,7 @@ export const LiveStoreProvider = <GraphQLContext extends BaseGraphQLContext>({
92
92
  batchUpdates,
93
93
  disableDevtools,
94
94
  signal,
95
- }: LiveStoreProviderProps<GraphQLContext> & { children?: ReactNode }): React.ReactElement => {
95
+ }: LiveStoreProviderProps<GraphQLContext> & { children?: ReactNode }): JSX.Element => {
96
96
  const storeCtx = useCreateStore({
97
97
  storeId,
98
98
  schema,
@@ -147,6 +147,7 @@ const useCreateStore = <GraphQLContext extends BaseGraphQLContext>({
147
147
  adapter,
148
148
  batchUpdates,
149
149
  disableDevtools,
150
+ reactivityGraph,
150
151
  signal,
151
152
  }: CreateStoreOptions<GraphQLContext, LiveStoreSchema> & {
152
153
  signal?: AbortSignal
@@ -175,6 +176,7 @@ const useCreateStore = <GraphQLContext extends BaseGraphQLContext>({
175
176
  adapter,
176
177
  batchUpdates,
177
178
  disableDevtools,
179
+ reactivityGraph,
178
180
  signal,
179
181
  })
180
182
 
@@ -200,6 +202,7 @@ const useCreateStore = <GraphQLContext extends BaseGraphQLContext>({
200
202
  inputPropsCacheRef.current.adapter !== adapter ||
201
203
  inputPropsCacheRef.current.batchUpdates !== batchUpdates ||
202
204
  inputPropsCacheRef.current.disableDevtools !== disableDevtools ||
205
+ inputPropsCacheRef.current.reactivityGraph !== reactivityGraph ||
203
206
  inputPropsCacheRef.current.signal !== signal
204
207
  ) {
205
208
  inputPropsCacheRef.current = {
@@ -210,6 +213,7 @@ const useCreateStore = <GraphQLContext extends BaseGraphQLContext>({
210
213
  adapter,
211
214
  batchUpdates,
212
215
  disableDevtools,
216
+ reactivityGraph,
213
217
  signal,
214
218
  }
215
219
  if (ctxValueRef.current.componentScope !== undefined && ctxValueRef.current.shutdownDeferred !== undefined) {
@@ -263,6 +267,7 @@ const useCreateStore = <GraphQLContext extends BaseGraphQLContext>({
263
267
  graphQLOptions,
264
268
  boot,
265
269
  adapter,
270
+ reactivityGraph,
266
271
  batchUpdates,
267
272
  disableDevtools,
268
273
  shutdownDeferred,
@@ -292,10 +297,8 @@ const useCreateStore = <GraphQLContext extends BaseGraphQLContext>({
292
297
  // shutdown before a new one is created - especially when shutdown logic is async. You can't trust `React.useEffect`.
293
298
  // Thank you to Mattia Manzati for this idea.
294
299
  withSemaphore(storeId),
295
- Effect.withSpan('@livestore/react:useCreateStore'),
296
- LS_DEV ? TaskTracing.withAsyncTaggingTracing((name: string) => (console as any).createTask(name)) : identity,
297
- provideOtel({ parentSpanContext: otelOptions?.rootSpanContext, otelTracer: otelOptions?.tracer }),
298
300
  Effect.tapCauseLogPretty,
301
+ provideOtel({ parentSpanContext: otelOptions?.rootSpanContext, otelTracer: otelOptions?.tracer }),
299
302
  Effect.annotateLogs({ thread: 'window' }),
300
303
  Effect.provide(Logger.prettyWithThread('window')),
301
304
  Logger.withMinimumLogLevel(LogLevel.Debug),
@@ -309,7 +312,18 @@ const useCreateStore = <GraphQLContext extends BaseGraphQLContext>({
309
312
  ctxValueRef.current.shutdownDeferred = undefined
310
313
  }
311
314
  }
312
- }, [schema, graphQLOptions, otelOptions, boot, adapter, batchUpdates, disableDevtools, signal, storeId])
315
+ }, [
316
+ schema,
317
+ graphQLOptions,
318
+ otelOptions,
319
+ boot,
320
+ adapter,
321
+ batchUpdates,
322
+ disableDevtools,
323
+ signal,
324
+ reactivityGraph,
325
+ storeId,
326
+ ])
313
327
 
314
328
  return ctxValueRef.current.value
315
329
  }