@livestore/react 0.4.0-dev.21 → 0.4.0-dev.22

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 (97) hide show
  1. package/dist/.tsbuildinfo +1 -1
  2. package/dist/StoreRegistryContext.d.ts +56 -0
  3. package/dist/StoreRegistryContext.d.ts.map +1 -0
  4. package/dist/StoreRegistryContext.js +61 -0
  5. package/dist/StoreRegistryContext.js.map +1 -0
  6. package/dist/__tests__/fixture.d.ts.map +1 -1
  7. package/dist/__tests__/fixture.js +1 -6
  8. package/dist/__tests__/fixture.js.map +1 -1
  9. package/dist/experimental/components/LiveList.d.ts +4 -2
  10. package/dist/experimental/components/LiveList.d.ts.map +1 -1
  11. package/dist/experimental/components/LiveList.js +6 -5
  12. package/dist/experimental/components/LiveList.js.map +1 -1
  13. package/dist/experimental/mod.d.ts +0 -1
  14. package/dist/experimental/mod.d.ts.map +1 -1
  15. package/dist/experimental/mod.js +0 -1
  16. package/dist/experimental/mod.js.map +1 -1
  17. package/dist/mod.d.ts +4 -3
  18. package/dist/mod.d.ts.map +1 -1
  19. package/dist/mod.js +3 -2
  20. package/dist/mod.js.map +1 -1
  21. package/dist/useClientDocument.d.ts.map +1 -1
  22. package/dist/useClientDocument.js +1 -4
  23. package/dist/useClientDocument.js.map +1 -1
  24. package/dist/useQuery.d.ts +1 -1
  25. package/dist/useQuery.d.ts.map +1 -1
  26. package/dist/useQuery.js +2 -5
  27. package/dist/useQuery.js.map +1 -1
  28. package/dist/useStore.d.ts +50 -46
  29. package/dist/useStore.d.ts.map +1 -1
  30. package/dist/useStore.js +66 -59
  31. package/dist/useStore.js.map +1 -1
  32. package/dist/useStore.test.d.ts.map +1 -0
  33. package/dist/{experimental/multi-store/useStore.test.js → useStore.test.js} +20 -22
  34. package/dist/useStore.test.js.map +1 -0
  35. package/package.json +7 -7
  36. package/src/StoreRegistryContext.tsx +69 -0
  37. package/src/__tests__/fixture.tsx +1 -13
  38. package/src/experimental/components/LiveList.tsx +13 -4
  39. package/src/experimental/mod.ts +0 -1
  40. package/src/mod.ts +4 -3
  41. package/src/useClientDocument.ts +1 -5
  42. package/src/useQuery.ts +2 -6
  43. package/src/{experimental/multi-store/useStore.test.tsx → useStore.test.tsx} +32 -30
  44. package/src/useStore.ts +94 -66
  45. package/dist/LiveStoreContext.d.ts +0 -40
  46. package/dist/LiveStoreContext.d.ts.map +0 -1
  47. package/dist/LiveStoreContext.js +0 -21
  48. package/dist/LiveStoreContext.js.map +0 -1
  49. package/dist/LiveStoreProvider.d.ts +0 -73
  50. package/dist/LiveStoreProvider.d.ts.map +0 -1
  51. package/dist/LiveStoreProvider.js +0 -233
  52. package/dist/LiveStoreProvider.js.map +0 -1
  53. package/dist/LiveStoreProvider.test.d.ts +0 -2
  54. package/dist/LiveStoreProvider.test.d.ts.map +0 -1
  55. package/dist/LiveStoreProvider.test.js +0 -117
  56. package/dist/LiveStoreProvider.test.js.map +0 -1
  57. package/dist/experimental/multi-store/StoreRegistry.d.ts +0 -105
  58. package/dist/experimental/multi-store/StoreRegistry.d.ts.map +0 -1
  59. package/dist/experimental/multi-store/StoreRegistry.js +0 -184
  60. package/dist/experimental/multi-store/StoreRegistry.js.map +0 -1
  61. package/dist/experimental/multi-store/StoreRegistry.test.d.ts +0 -2
  62. package/dist/experimental/multi-store/StoreRegistry.test.d.ts.map +0 -1
  63. package/dist/experimental/multi-store/StoreRegistry.test.js +0 -381
  64. package/dist/experimental/multi-store/StoreRegistry.test.js.map +0 -1
  65. package/dist/experimental/multi-store/StoreRegistryContext.d.ts +0 -10
  66. package/dist/experimental/multi-store/StoreRegistryContext.d.ts.map +0 -1
  67. package/dist/experimental/multi-store/StoreRegistryContext.js +0 -15
  68. package/dist/experimental/multi-store/StoreRegistryContext.js.map +0 -1
  69. package/dist/experimental/multi-store/mod.d.ts +0 -6
  70. package/dist/experimental/multi-store/mod.d.ts.map +0 -1
  71. package/dist/experimental/multi-store/mod.js +0 -6
  72. package/dist/experimental/multi-store/mod.js.map +0 -1
  73. package/dist/experimental/multi-store/storeOptions.d.ts +0 -4
  74. package/dist/experimental/multi-store/storeOptions.d.ts.map +0 -1
  75. package/dist/experimental/multi-store/storeOptions.js +0 -4
  76. package/dist/experimental/multi-store/storeOptions.js.map +0 -1
  77. package/dist/experimental/multi-store/types.d.ts +0 -25
  78. package/dist/experimental/multi-store/types.d.ts.map +0 -1
  79. package/dist/experimental/multi-store/types.js +0 -2
  80. package/dist/experimental/multi-store/types.js.map +0 -1
  81. package/dist/experimental/multi-store/useStore.d.ts +0 -11
  82. package/dist/experimental/multi-store/useStore.d.ts.map +0 -1
  83. package/dist/experimental/multi-store/useStore.js +0 -16
  84. package/dist/experimental/multi-store/useStore.js.map +0 -1
  85. package/dist/experimental/multi-store/useStore.test.d.ts.map +0 -1
  86. package/dist/experimental/multi-store/useStore.test.js.map +0 -1
  87. package/src/LiveStoreContext.ts +0 -41
  88. package/src/LiveStoreProvider.test.tsx +0 -248
  89. package/src/LiveStoreProvider.tsx +0 -430
  90. package/src/experimental/multi-store/StoreRegistry.test.ts +0 -518
  91. package/src/experimental/multi-store/StoreRegistry.ts +0 -253
  92. package/src/experimental/multi-store/StoreRegistryContext.tsx +0 -23
  93. package/src/experimental/multi-store/mod.ts +0 -5
  94. package/src/experimental/multi-store/storeOptions.ts +0 -8
  95. package/src/experimental/multi-store/types.ts +0 -37
  96. package/src/experimental/multi-store/useStore.ts +0 -26
  97. /package/dist/{experimental/multi-store/useStore.test.d.ts → useStore.test.d.ts} +0 -0
@@ -1 +0,0 @@
1
- {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../../src/experimental/multi-store/mod.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAA;AAClC,cAAc,4BAA4B,CAAA;AAC1C,cAAc,mBAAmB,CAAA;AACjC,cAAc,YAAY,CAAA;AAC1B,cAAc,eAAe,CAAA"}
@@ -1,6 +0,0 @@
1
- export * from "./StoreRegistry.js";
2
- export * from "./StoreRegistryContext.js";
3
- export * from "./storeOptions.js";
4
- export * from "./types.js";
5
- export * from "./useStore.js";
6
- //# sourceMappingURL=mod.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"mod.js","sourceRoot":"","sources":["../../../src/experimental/multi-store/mod.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAA;AAClC,cAAc,2BAA4B,CAAA;AAC1C,cAAc,mBAAmB,CAAA;AACjC,cAAc,YAAY,CAAA;AAC1B,cAAc,eAAe,CAAA"}
@@ -1,4 +0,0 @@
1
- import type { LiveStoreSchema } from '@livestore/common/schema';
2
- import type { CachedStoreOptions } from './types.ts';
3
- export declare function storeOptions<TSchema extends LiveStoreSchema>(options: CachedStoreOptions<TSchema>): CachedStoreOptions<TSchema>;
4
- //# sourceMappingURL=storeOptions.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"storeOptions.d.ts","sourceRoot":"","sources":["../../../src/experimental/multi-store/storeOptions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAA;AAC/D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAEpD,wBAAgB,YAAY,CAAC,OAAO,SAAS,eAAe,EAC1D,OAAO,EAAE,kBAAkB,CAAC,OAAO,CAAC,GACnC,kBAAkB,CAAC,OAAO,CAAC,CAE7B"}
@@ -1,4 +0,0 @@
1
- export function storeOptions(options) {
2
- return options;
3
- }
4
- //# sourceMappingURL=storeOptions.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"storeOptions.js","sourceRoot":"","sources":["../../../src/experimental/multi-store/storeOptions.ts"],"names":[],"mappings":"AAGA,MAAM,UAAU,YAAY,CAC1B,OAAoC;IAEpC,OAAO,OAAO,CAAA;AAChB,CAAC"}
@@ -1,25 +0,0 @@
1
- import type { LiveStoreSchema } from '@livestore/common/schema';
2
- import type { CreateStoreOptions, OtelOptions } from '@livestore/livestore';
3
- export type CachedStoreOptions<TSchema extends LiveStoreSchema = LiveStoreSchema.Any, TContext = {}> = Pick<CreateStoreOptions<TSchema, TContext>, 'storeId' | 'schema' | 'adapter' | 'boot' | 'batchUpdates' | 'disableDevtools' | 'confirmUnsavedChanges' | 'syncPayload' | 'debug' | 'shutdownDeferred'> & {
4
- signal?: AbortSignal;
5
- otelOptions?: Partial<OtelOptions>;
6
- /**
7
- * The time in milliseconds that this store should remain
8
- * in memory after becoming unused. When this store becomes
9
- * unused (no active retentions), it will be disposed after this duration.
10
- *
11
- * Stores transition to the unused state as soon as they have no
12
- * active retentions, so when all components which use that store
13
- * have unmounted.
14
- *
15
- * @remarks
16
- * - When different `unusedCacheTime` values are used for the same store, the longest one will be used.
17
- * - If set to `Infinity`, will disable automatic disposal
18
- * - The maximum allowed time is about {@link https://developer.mozilla.org/en-US/docs/Web/API/Window/setTimeout#maximum_delay_value | 24 days}
19
- *
20
- * @defaultValue `60_000` (60 seconds) or `Infinity` during SSR to avoid
21
- * disposing stores before server render completes.
22
- */
23
- unusedCacheTime?: number;
24
- };
25
- //# sourceMappingURL=types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/experimental/multi-store/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAA;AAC/D,OAAO,KAAK,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAE3E,MAAM,MAAM,kBAAkB,CAAC,OAAO,SAAS,eAAe,GAAG,eAAe,CAAC,GAAG,EAAE,QAAQ,GAAG,EAAE,IAAI,IAAI,CACzG,kBAAkB,CAAC,OAAO,EAAE,QAAQ,CAAC,EACnC,SAAS,GACT,QAAQ,GACR,SAAS,GACT,MAAM,GACN,cAAc,GACd,iBAAiB,GACjB,uBAAuB,GACvB,aAAa,GACb,OAAO,GACP,kBAAkB,CACrB,GAAG;IACF,MAAM,CAAC,EAAE,WAAW,CAAA;IACpB,WAAW,CAAC,EAAE,OAAO,CAAC,WAAW,CAAC,CAAA;IAClC;;;;;;;;;;;;;;;;OAgBG;IACH,eAAe,CAAC,EAAE,MAAM,CAAA;CACzB,CAAA"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=types.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/experimental/multi-store/types.ts"],"names":[],"mappings":""}
@@ -1,11 +0,0 @@
1
- import type { LiveStoreSchema } from '@livestore/common/schema';
2
- import type { Store } from '@livestore/livestore';
3
- import type { ReactApi } from '../../LiveStoreContext.ts';
4
- import type { CachedStoreOptions } from './types.ts';
5
- /**
6
- * Suspense and Error Boundary friendly hook.
7
- * - Returns data or throws (Promise|Error).
8
- * - No loading or error states are returned.
9
- */
10
- export declare const useStore: <TSchema extends LiveStoreSchema>(options: CachedStoreOptions<TSchema>) => Store<TSchema> & ReactApi;
11
- //# sourceMappingURL=useStore.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useStore.d.ts","sourceRoot":"","sources":["../../../src/experimental/multi-store/useStore.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAA;AAC/D,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAA;AAEjD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAA;AAGzD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAEpD;;;;GAIG;AACH,eAAO,MAAM,QAAQ,GAAI,OAAO,SAAS,eAAe,EACtD,SAAS,kBAAkB,CAAC,OAAO,CAAC,KACnC,KAAK,CAAC,OAAO,CAAC,GAAG,QAUnB,CAAA"}
@@ -1,16 +0,0 @@
1
- import * as React from 'react';
2
- import { withReactApi } from "../../useStore.js";
3
- import { useStoreRegistry } from "./StoreRegistryContext.js";
4
- /**
5
- * Suspense and Error Boundary friendly hook.
6
- * - Returns data or throws (Promise|Error).
7
- * - No loading or error states are returned.
8
- */
9
- export const useStore = (options) => {
10
- const storeRegistry = useStoreRegistry();
11
- React.useEffect(() => storeRegistry.retain(options), [storeRegistry, options]);
12
- const storeOrPromise = React.useMemo(() => storeRegistry.getOrLoadPromise(options), [storeRegistry, options]);
13
- const store = storeOrPromise instanceof Promise ? React.use(storeOrPromise) : storeOrPromise;
14
- return withReactApi(store);
15
- };
16
- //# sourceMappingURL=useStore.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useStore.js","sourceRoot":"","sources":["../../../src/experimental/multi-store/useStore.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAChD,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA4B,CAAA;AAG7D;;;;GAIG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,CACtB,OAAoC,EACT,EAAE;IAC7B,MAAM,aAAa,GAAG,gBAAgB,EAAE,CAAA;IAExC,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE,CAAC,aAAa,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC,CAAA;IAE9E,MAAM,cAAc,GAAG,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,aAAa,CAAC,gBAAgB,CAAC,OAAO,CAAC,EAAE,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC,CAAA;IAE7G,MAAM,KAAK,GAAG,cAAc,YAAY,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,cAAc,CAAA;IAE5F,OAAO,YAAY,CAAC,KAAK,CAAC,CAAA;AAC5B,CAAC,CAAA"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"useStore.test.d.ts","sourceRoot":"","sources":["../../../src/experimental/multi-store/useStore.test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AAO,OAAO,CAAA;AAChB,CAAC,CAAA;AAEH,IAAI,gBAAgB,GAAG,CAAC,CAAA;AAExB,MAAM,gBAAgB,GAAG,CAAC,YAAwD,EAAE,EAAE,EAAE,CACtF,YAAY,CAAC;IACX,OAAO,EAAE,SAAS,CAAC,OAAO,IAAI,cAAc,gBAAgB,EAAE,EAAE;IAChE,MAAM;IACN,OAAO,EAAE,mBAAmB,EAAE;IAC9B,GAAG,SAAS;CACb,CAAC,CAAA;AAEJ;;;;;GAKG;AACH,MAAM,mBAAmB,GAAG,KAAK,EAAE,OAAmB,EAAiB,EAAE;IACvE,OAAO,EAAE,CAAA;IACT,gDAAgD;IAChD,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,CAAA;AAC1D,CAAC,CAAA;AAED;;GAEG;AACH,MAAM,uBAAuB,GAAG,KAAK,EAAE,IAAkB,EAAiB,EAAE;IAC1E,MAAM,OAAO,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAA;AACxE,CAAC,CAAA;AAED;;;GAGG;AACH,MAAM,iBAAiB,GAAG,KAAK,EAAE,MAA+B,EAAiB,EAAE;IACjF,MAAM,OAAO,CAAC,GAAG,EAAE;QACjB,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAA;QACrC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,oBAAoB,CAAC,CAAC,aAAa,CAAC,CAAC,WAAW,EAAE,CAAA;IAC1E,CAAC,CAAC,CAAA;AACJ,CAAC,CAAA"}
@@ -1,41 +0,0 @@
1
- import type { LiveStoreContextRunning } from '@livestore/livestore'
2
- import React from 'react'
3
-
4
- import type { useClientDocument } from './useClientDocument.ts'
5
- import type { useQuery } from './useQuery.ts'
6
-
7
- /**
8
- * React-specific methods added to the Store when used via React hooks.
9
- *
10
- * These methods are attached by `withReactApi()` and `useStore()`, allowing you
11
- * to call `store.useQuery()` and `store.useClientDocument()` directly on the
12
- * Store instance.
13
- */
14
- export type ReactApi = {
15
- /** Hook version of query subscription—re-renders component when query result changes */
16
- useQuery: typeof useQuery
17
- /** Hook for reading and writing client-document tables with React state semantics */
18
- useClientDocument: typeof useClientDocument
19
- }
20
-
21
- /**
22
- * React context for accessing the LiveStore instance.
23
- *
24
- * This context is provided by `<LiveStoreProvider>` and consumed by hooks like
25
- * `useStore()`, `useQuery()`, and `useClientDocument()`.
26
- *
27
- * The context value is `undefined` until the Store has finished booting,
28
- * then transitions to `{ stage: 'running', store: ... }`.
29
- *
30
- * @example
31
- * ```tsx
32
- * // Typically you don't use this directly—use useStore() instead
33
- * const context = React.useContext(LiveStoreContext)
34
- * if (context?.stage === 'running') {
35
- * console.log('Store ready:', context.store.storeId)
36
- * }
37
- * ```
38
- */
39
- export const LiveStoreContext = React.createContext<
40
- { stage: 'running'; store: LiveStoreContextRunning['store'] & ReactApi } | undefined
41
- >(undefined)
@@ -1,248 +0,0 @@
1
- /** biome-ignore-all lint/a11y: test files need a11y disabled */
2
- import { makeInMemoryAdapter } from '@livestore/adapter-web'
3
- import { queryDb, type Store, StoreInternalsSymbol } from '@livestore/livestore'
4
- import { Schema } from '@livestore/utils/effect'
5
- import * as ReactTesting from '@testing-library/react'
6
- import React from 'react'
7
- import { unstable_batchedUpdates as batchUpdates } from 'react-dom'
8
- import { describe, expect, it } from 'vitest'
9
-
10
- import { events, schema, tables } from './__tests__/fixture.tsx'
11
- import { LiveStoreProvider } from './LiveStoreProvider.tsx'
12
- import * as LiveStoreReact from './mod.ts'
13
-
14
- describe.each([true, false])('LiveStoreProvider (strictMode: %s)', (strictMode) => {
15
- const WithStrictMode = strictMode ? React.StrictMode : React.Fragment
16
-
17
- it('simple', async () => {
18
- let appRenderCount = 0
19
-
20
- const allTodos$ = queryDb({ query: `select * from todos`, schema: Schema.Array(tables.todos.rowSchema) })
21
-
22
- const App = () => {
23
- appRenderCount++
24
- const { store } = LiveStoreReact.useStore()
25
-
26
- const todos = store.useQuery(allTodos$)
27
-
28
- return <div>{JSON.stringify(todos)}</div>
29
- }
30
-
31
- const abortController = new AbortController()
32
-
33
- const Root = ({ forceUpdate }: { forceUpdate: number }) => {
34
- const bootCb = React.useCallback(
35
- (store: Store) => store.commit(events.todoCreated({ id: 't1', text: 'buy milk', completed: false })),
36
- [],
37
- )
38
-
39
- // biome-ignore lint/correctness/useExhaustiveDependencies: forceUpdate is used to force a re-render
40
- const adapterMemo = React.useMemo(() => makeInMemoryAdapter(), [forceUpdate])
41
- return (
42
- <WithStrictMode>
43
- <LiveStoreProvider
44
- schema={schema}
45
- renderLoading={(status) => <div>Loading LiveStore: {status.stage}</div>}
46
- adapter={adapterMemo}
47
- boot={bootCb}
48
- signal={abortController.signal}
49
- batchUpdates={batchUpdates}
50
- >
51
- <App />
52
- </LiveStoreProvider>
53
- </WithStrictMode>
54
- )
55
- }
56
-
57
- const { rerender } = ReactTesting.render(<Root forceUpdate={1} />)
58
-
59
- expect(appRenderCount).toBe(0)
60
-
61
- await ReactTesting.waitForElementToBeRemoved(() =>
62
- ReactTesting.screen.getByText((_) => _.startsWith('Loading LiveStore')),
63
- )
64
-
65
- expect(appRenderCount).toBe(strictMode ? 2 : 1)
66
-
67
- rerender(<Root forceUpdate={2} />)
68
-
69
- await ReactTesting.waitFor(() => ReactTesting.screen.getByText('Loading LiveStore: loading'))
70
- await ReactTesting.waitFor(() => ReactTesting.screen.getByText((_) => _.includes('buy milk')))
71
-
72
- expect(appRenderCount).toBe(strictMode ? 4 : 2)
73
-
74
- abortController.abort()
75
-
76
- await ReactTesting.waitFor(() =>
77
- ReactTesting.screen.getByText('LiveStore Shutdown due to interrupted', { exact: false }),
78
- )
79
- })
80
-
81
- // TODO test aborting during boot
82
-
83
- it('error during boot', async () => {
84
- let appRenderCount = 0
85
-
86
- const App = () => {
87
- appRenderCount++
88
-
89
- return <div>hello world</div>
90
- }
91
-
92
- const Root = ({ forceUpdate }: { forceUpdate: number }) => {
93
- const bootCb = React.useCallback((_store: Store) => {
94
- // This should trigger an error because we're trying to insert invalid data
95
- throw new Error('Simulated boot error')
96
- }, [])
97
- // biome-ignore lint/correctness/useExhaustiveDependencies: forceUpdate is used to force a re-render
98
- const adapterMemo = React.useMemo(() => makeInMemoryAdapter(), [forceUpdate])
99
- return (
100
- <WithStrictMode>
101
- <LiveStoreProvider
102
- schema={schema}
103
- renderLoading={(status) => <div>Loading LiveStore: {status.stage}</div>}
104
- adapter={adapterMemo}
105
- boot={bootCb}
106
- batchUpdates={batchUpdates}
107
- >
108
- <App />
109
- </LiveStoreProvider>
110
- </WithStrictMode>
111
- )
112
- }
113
-
114
- ReactTesting.render(<Root forceUpdate={1} />)
115
-
116
- expect(appRenderCount).toBe(0)
117
-
118
- await ReactTesting.waitFor(() => ReactTesting.screen.getByText((_) => _.startsWith('LiveStore.UnknownError')))
119
- })
120
-
121
- it('unmounts when store is shutdown', async () => {
122
- let appRenderCount = 0
123
-
124
- const allTodos$ = queryDb({ query: `select * from todos`, schema: Schema.Array(tables.todos.rowSchema) })
125
-
126
- const shutdownDeferred = Promise.withResolvers<void>()
127
-
128
- const App = () => {
129
- appRenderCount++
130
- const { store } = LiveStoreReact.useStore()
131
-
132
- React.useEffect(() => {
133
- shutdownDeferred.promise.then(() => {
134
- console.log('shutdown')
135
- return store.shutdown()
136
- })
137
- }, [store])
138
-
139
- const todos = store.useQuery(allTodos$)
140
-
141
- return <div>{JSON.stringify(todos)}</div>
142
- }
143
-
144
- const adapter = makeInMemoryAdapter()
145
-
146
- const Root = () => {
147
- return (
148
- <WithStrictMode>
149
- <LiveStoreProvider
150
- schema={schema}
151
- renderLoading={(status) => <div>Loading LiveStore: {status.stage}</div>}
152
- adapter={adapter}
153
- batchUpdates={batchUpdates}
154
- >
155
- <App />
156
- </LiveStoreProvider>
157
- </WithStrictMode>
158
- )
159
- }
160
-
161
- ReactTesting.render(<Root />)
162
-
163
- expect(appRenderCount).toBe(0)
164
-
165
- await ReactTesting.waitFor(() => ReactTesting.screen.getByText('[]'))
166
-
167
- React.act(() => shutdownDeferred.resolve())
168
-
169
- expect(appRenderCount).toBe(strictMode ? 2 : 1)
170
-
171
- await ReactTesting.waitFor(() =>
172
- ReactTesting.screen.getByText('LiveStore Shutdown due to manual shutdown', { exact: false }),
173
- )
174
- })
175
- })
176
-
177
- it('should work two stores with the same storeId', async () => {
178
- const allTodos$ = queryDb({ query: `select * from todos`, schema: Schema.Array(tables.todos.rowSchema) })
179
-
180
- const appRenderCount = {
181
- store1: 0,
182
- store2: 0,
183
- }
184
-
185
- const App = () => {
186
- const { store } = LiveStoreReact.useStore()
187
- const instanceId = store[StoreInternalsSymbol].clientSession.debugInstanceId as 'store1' | 'store2'
188
- appRenderCount[instanceId]!++
189
-
190
- const todos = store.useQuery(allTodos$)
191
-
192
- return (
193
- <div id={instanceId}>
194
- <div role="heading">{instanceId}</div>
195
- <div role="content">{JSON.stringify(todos)}</div>
196
- <button onClick={() => store.commit(events.todoCreated({ id: 't1', text: 'buy milk', completed: false }))}>
197
- create todo {instanceId}
198
- </button>
199
- </div>
200
- )
201
- }
202
-
203
- const Root = () => {
204
- const storeId = 'fixed-store-id'
205
- return (
206
- <div>
207
- <LiveStoreProvider
208
- storeId={storeId}
209
- debug={{ instanceId: 'store1' }}
210
- schema={schema}
211
- adapter={makeInMemoryAdapter()}
212
- batchUpdates={batchUpdates}
213
- >
214
- <App />
215
- </LiveStoreProvider>
216
- <LiveStoreProvider
217
- storeId={storeId}
218
- debug={{ instanceId: 'store2' }}
219
- schema={schema}
220
- adapter={makeInMemoryAdapter()}
221
- batchUpdates={batchUpdates}
222
- >
223
- <App />
224
- </LiveStoreProvider>
225
- </div>
226
- )
227
- }
228
-
229
- const { container } = ReactTesting.render(<Root />)
230
-
231
- await ReactTesting.waitFor(() => ReactTesting.screen.getByRole('heading', { name: 'store1' }))
232
- await ReactTesting.waitFor(() => ReactTesting.screen.getByRole('heading', { name: 'store2' }))
233
-
234
- expect(appRenderCount.store1).toBe(1)
235
- expect(appRenderCount.store2).toBe(1)
236
-
237
- ReactTesting.fireEvent.click(ReactTesting.screen.getByText('create todo store1'))
238
-
239
- expect(appRenderCount.store1).toBe(2)
240
-
241
- expect(container.querySelector('#store1 > div[role="content"]')?.textContent).toBe(
242
- '[{"id":"t1","text":"buy milk","completed":false}]',
243
- )
244
-
245
- expect(container.querySelector('#store2 > div[role="content"]')?.textContent).toBe('[]')
246
- })
247
-
248
- // TODO test that checks that there are no two exact same instances (i.e. same storeId, clientId, sessionId)