Open History to see the last commit
1/**
2 * Source ID reuse contract for React's derived live-query identity.
3 *
4 * A Collection ID names one source object for the lifetime of a mounted
5 * derived-identity hook in one DbClient scope. Re-rendering that hook with a different object under
6 * the same ID must reject before it can return rows from the old source.
7 * Unmounting and cleaning up the old scope permits the ID in a new hook. Two
8 * independent client scopes may use the same ID at the same time.
9 *
10 * Model: each mounted hook remembers the source object first seen for an ID
11 * in each client scope. Same object and fresh ID transitions are legal. A
12 * different object for a remembered ID is rejected. A new hook starts a new
13 * model; switching clients selects that client's remembered bindings.
14 * A render that starts a live query claims its source before a descendant
15 * suspends, because the live query may still own that source until cleanup.
16 * Separate hooks can use same-ID objects: their client-scoped Suspense cache
17 * entries must remain distinct, including before the first hook commits.
18 * A rejected render must release any sync-start deferral it acquired for a
19 * shared client descriptor, so a later direct reader can start that Collection.
20 * This remains true when earlier deferred sync starts throw: each pending
21 * Collection is attempted before the first startup error is rethrown.
22 * The bounded histories below distinguish this law from a hash-only check,
23 * which would miss A(id=x) -> C(id=y) -> B(id=x), a changed predicate, and
24 * two different same-ID sources in one query.
25 *
26 * Driver and observation: render the public hook, then rerender it with each
27 * source. At the rerender boundary, compare a thrown error or the public row.
28 * This does not assert a process-wide Collection registry, legacy dependency
29 * arrays, or explicit-key semantics; explicit queryKey callers own their key.
30 */
31import { act, render, renderHook, waitFor } from '@testing-library/react'
32import {
33 DbClient,
34 collectionOptions,
35 createCollection,
36 eq,
37 gt,
38} from '@tanstack/db'
39import { describe, expect, it, vi } from 'vitest'
40import { Component, Suspense } from 'react'
41import { DbProvider } from '../src/DbProvider'
42import { useLiveQuery } from '../src/useLiveQuery'
43import { useLiveInfiniteQuery } from '../src/useLiveInfiniteQuery'
44import { useLiveSuspenseQuery } from '../src/useLiveSuspenseQuery'
45import { mockSyncCollectionOptions } from '../../db/tests/utils'
46import type { Context, QueryBuilder } from '@tanstack/db'
47import type { ReactNode } from 'react'
48
49type Row = { id: string; value: string; rank: number }
50
51class TestErrorBoundary extends Component<
52 { children: ReactNode },
53 { error?: Error }
54> {
55 state: { error?: Error } = {}
56
57 static getDerivedStateFromError(error: Error) {
58 return { error }
59 }
60
61 render() {
62 return this.state.error ? <div>Rejected</div> : this.props.children
63 }
64}
65
66function source(id: string, value: string) {
67 return createCollection(
68 mockSyncCollectionOptions<Row>({
69 id,
70 getKey: (row) => row.id,
71 initialData: [{ id: `one`, value, rank: 1 }],
72 }),
73 )
74}
75
76type Binding = { source: ReturnType<typeof source>; client?: DbClient }
77
78// A prior source with the same ID in this client scope forbids a new object.
79// Pairwise history comparison is independent of the hook's token maps.
80function expectedCollision(history: ReadonlyArray<Binding>, next: Binding) {
81 return history.some(
82 (prior) =>
83 prior.client === next.client &&
84 prior.source.id === next.source.id &&
85 prior.source !== next.source,
86 )
87}
88
89function checkRerender(
90 history: ReadonlyArray<Binding>,
91 next: Binding,
92 rerender: () => void,
93) {
94 if (expectedCollision(history, next)) {
95 expect(rerender).toThrow(/source Collection .*same ID/i)
96 } else {
97 expect(rerender).not.toThrow()
98 }
99}
100
101describe(`React source ID reuse`, () => {
102 it(`releases a later shared source when earlier deferred sync starts fail`, async () => {
103 const client = new DbClient()
104 const first = source(`settings`, `first`)
105 const replacement = source(`settings`, `replacement`)
106 const failedStarts: [number, number] = [0, 0]
107 const failing = ([0, 1] as const).map((index) =>
108 collectionOptions(`failing-${index}`, () => ({
109 id: `failing-${index}`,
110 getKey: (row: Row) => row.id,
111 startSync: true,
112 sync: {
113 sync: () => {
114 failedStarts[index]++
115 throw new Error(`sync ${index} failed`)
116 },
117 },
118 })),
119 )
120 let healthyStarts = 0
121 const healthy = collectionOptions(`healthy-after-failures`, () => ({
122 id: `healthy-after-failures`,
123 getKey: (row: Row) => row.id,
124 startSync: true,
125 sync: {
126 sync: ({ begin, write, commit, markReady }) => {
127 healthyStarts++
128 begin()
129 write({
130 type: `insert`,
131 value: { id: `one`, value: `healthy`, rank: 1 },
132 })
133 commit()
134 markReady()
135 },
136 },
137 }))
138 const consoleError = vi.spyOn(console, `error`).mockImplementation(() => {})
139
140 function View({
141 current,
142 include,
143 }: {
144 current: typeof first
145 include: boolean
146 }) {
147 useLiveQuery({
148 client,
149 query: (q): QueryBuilder<Context> =>
150 include
151 ? q
152 .from({ failingA: failing[0]! })
153 .join({ failingB: failing[1]! }, ({ failingA, failingB }) =>
154 eq(failingA.id, failingB.id),
155 )
156 .join({ healthy }, ({ failingA, healthy }) =>
157 eq(failingA.id, healthy.id),
158 )
159 .join({ settings: current }, ({ failingA, settings }) =>
160 eq(failingA.id, settings.id),
161 )
162 : q.from({ settings: current }),
163 })
164 return <div>Query</div>
165 }
166
167 try {
168 const root = render(
169 <TestErrorBoundary>
170 <View current={first} include={false} />
171 </TestErrorBoundary>,
172 )
173 await act(async () => {})
174 root.rerender(
175 <TestErrorBoundary>
176 <View current={replacement} include={true} />
177 </TestErrorBoundary>,
178 )
179 expect(root.getByText(`Rejected`)).toBeDefined()
180 expect(failedStarts).toEqual([1, 1])
181
182 const shared = client.collection(healthy)
183 const reader = renderHook(() => useLiveQuery(shared))
184 await act(async () => {})
185 expect(reader.result.current.status).toBe(`ready`)
186 expect(reader.result.current.data[0]?.value).toBe(`healthy`)
187 expect(healthyStarts).toBe(1)
188 } finally {
189 consoleError.mockRestore()
190 }
191 })
192
193 it(`releases a shared descriptor's sync deferral when a collision tears down the hook`, async () => {
194 const client = new DbClient()
195 const first = source(`settings`, `first`)
196 const replacement = source(`settings`, `replacement`)
197 let syncStarts = 0
198 const descriptor = collectionOptions(`shared-after-collision`, () => ({
199 id: `shared-after-collision`,
200 getKey: (row: Row) => row.id,
201 sync: {
202 sync: ({ begin, write, commit, markReady }) => {
203 syncStarts++
204 begin()
205 write({
206 type: `insert`,
207 value: { id: `one`, value: `shared`, rank: 1 },
208 })
209 commit()
210 markReady()
211 },
212 },
213 }))
214 const consoleError = vi.spyOn(console, `error`).mockImplementation(() => {})
215
216 function View({
217 current,
218 includeShared,
219 }: {
220 current: typeof first
221 includeShared: boolean
222 }) {
223 useLiveQuery({
224 client,
225 query: (q) =>
226 includeShared
227 ? q
228 .from({ settings: current })
229 .join({ shared: descriptor }, ({ settings, shared }) =>
230 eq(settings.id, shared.id),
231 )
232 : q.from({ settings: current }),
233 })
234 return <div>Query</div>
235 }
236
237 try {
238 const root = render(
239 <TestErrorBoundary>
240 <View current={first} includeShared={false} />
241 </TestErrorBoundary>,
242 )
243 await act(async () => {})
244 root.rerender(
245 <TestErrorBoundary>
246 <View current={replacement} includeShared={true} />
247 </TestErrorBoundary>,
248 )
249 expect(root.getByText(`Rejected`)).toBeDefined()
250 expect(syncStarts).toBe(0)
251
252 const shared = client.collection(descriptor)
253 const reader = renderHook(() => useLiveQuery(shared))
254 await act(async () => {})
255 expect(reader.result.current.status).toBe(`ready`)
256 expect(reader.result.current.data[0]?.value).toBe(`shared`)
257 expect(syncStarts).toBe(1)
258 } finally {
259 consoleError.mockRestore()
260 }
261 })
262
263 it(`rejects a different active source with the same ID before exposing stale rows`, async () => {
264 const first = source(`settings`, `first`)
265 const second = source(`settings`, `second`)
266 const hook = renderHook(
267 ({ current }) =>
268 useLiveQuery({ query: (q) => q.from({ settings: current }) }),
269 { initialProps: { current: first } },
270 )
271
272 await waitFor(() =>
273 expect(hook.result.current.data[0]?.value).toBe(`first`),
274 )
275 checkRerender([{ source: first }], { source: second }, () =>
276 hook.rerender({ current: second }),
277 )
278 })
279
280 it(`rejects a previously used ID after another source and a query change`, async () => {
281 const first = source(`settings`, `first`)
282 const other = source(`other`, `other`)
283 const second = source(`settings`, `second`)
284 const hook = renderHook(
285 ({ current, minimum }) =>
286 useLiveQuery({
287 query: (q) =>
288 q
289 .from({ settings: current })
290 .where(({ settings }) => gt(settings.rank, minimum)),
291 }),
292 { initialProps: { current: first, minimum: 0 } },
293 )
294
295 await waitFor(() =>
296 expect(hook.result.current.data[0]?.value).toBe(`first`),
297 )
298 act(() => hook.rerender({ current: other, minimum: 0 }))
299 await waitFor(() =>
300 expect(hook.result.current.data[0]?.value).toBe(`other`),
301 )
302 checkRerender(
303 [{ source: first }, { source: other }],
304 { source: second },
305 () => hook.rerender({ current: second, minimum: -1 }),
306 )
307 })
308
309 it(`accepts the same source object and a different source ID`, async () => {
310 const first = source(`settings`, `first`)
311 const other = source(`other`, `other`)
312 const hook = renderHook(
313 ({ current }) =>
314 useLiveQuery({ query: (q) => q.from({ settings: current }) }),
315 { initialProps: { current: first } },
316 )
317
318 await waitFor(() =>
319 expect(hook.result.current.data[0]?.value).toBe(`first`),
320 )
321 checkRerender([{ source: first }], { source: first }, () =>
322 hook.rerender({ current: first }),
323 )
324 expect(hook.result.current.data[0]?.value).toBe(`first`)
325 checkRerender([{ source: first }], { source: other }, () =>
326 hook.rerender({ current: other }),
327 )
328 await waitFor(() =>
329 expect(hook.result.current.data[0]?.value).toBe(`other`),
330 )
331 })
332
333 it(`rejects two distinct source objects with one ID in a single query`, () => {
334 const leftSource = source(`settings`, `first`)
335 const rightSource = source(`settings`, `second`)
336 expect(() =>
337 renderHook(() =>
338 useLiveQuery({
339 query: (q) =>
340 q
341 .from({ first: leftSource })
342 .join({ second: rightSource }, ({ first, second }) =>
343 eq(first.id, second.id),
344 ),
345 }),
346 ),
347 ).toThrow(/source Collection .*same ID/i)
348 })
349
350 it(`keeps a mounted hook's ID binding after source cleanup`, async () => {
351 const first = source(`settings`, `first`)
352 const second = source(`settings`, `second`)
353 const hook = renderHook(
354 ({ current }) =>
355 useLiveQuery({ query: (q) => q.from({ settings: current }) }),
356 { initialProps: { current: first } },
357 )
358 await waitFor(() =>
359 expect(hook.result.current.data[0]?.value).toBe(`first`),
360 )
361 await act(async () => first.cleanup())
362 checkRerender([{ source: first }], { source: second }, () =>
363 hook.rerender({ current: second }),
364 )
365 })
366
367 it(`permits the same ID in a new hook after unmount and cleanup`, async () => {
368 const first = source(`settings`, `first`)
369 const oldHook = renderHook(() =>
370 useLiveQuery({ query: (q) => q.from({ settings: first }) }),
371 )
372 await waitFor(() =>
373 expect(oldHook.result.current.data[0]?.value).toBe(`first`),
374 )
375 const oldQuery = oldHook.result.current.collection
376 oldHook.unmount()
377 await waitFor(() => expect(oldQuery.status).toBe(`cleaned-up`))
378 await first.cleanup()
379
380 const second = source(`settings`, `second`)
381 const newHook = renderHook(() =>
382 useLiveQuery({ query: (q) => q.from({ settings: second }) }),
383 )
384 await waitFor(() =>
385 expect(newHook.result.current.data[0]?.value).toBe(`second`),
386 )
387 })
388
389 it(`permits independent client scopes to use the same ID`, async () => {
390 const firstClient = new DbClient()
391 const secondClient = new DbClient()
392 const first = source(`settings`, `first`)
393 const second = source(`settings`, `second`)
394 const firstHook = renderHook(() =>
395 useLiveQuery({
396 client: firstClient,
397 query: (q) => q.from({ settings: first }),
398 }),
399 )
400 const secondHook = renderHook(() =>
401 useLiveQuery({
402 client: secondClient,
403 query: (q) => q.from({ settings: second }),
404 }),
405 )
406
407 await waitFor(() => {
408 expect(firstHook.result.current.data[0]?.value).toBe(`first`)
409 expect(secondHook.result.current.data[0]?.value).toBe(`second`)
410 })
411 })
412
413 it(`keeps separate client-scoped Suspense hooks bound to their own sources`, async () => {
414 const client = new DbClient()
415 const first = source(`settings`, `first`)
416 const second = source(`settings`, `second`)
417 const View = ({ current }: { current: typeof first }) => {
418 const { data } = useLiveSuspenseQuery({
419 client,
420 query: (q) => q.from({ settings: current }),
421 })
422 return <div>{data[0]?.value}</div>
423 }
424 const firstView = render(
425 <Suspense fallback={<div>First loading</div>}>
426 <View current={first} />
427 </Suspense>,
428 )
429 await waitFor(() => expect(firstView.getByText(`first`)).toBeDefined())
430 const secondView = render(
431 <Suspense fallback={<div>Second loading</div>}>
432 <View current={second} />
433 </Suspense>,
434 )
435 await waitFor(() => expect(secondView.getByText(`second`)).toBeDefined())
436 })
437
438 it(`keeps a client-scoped Suspense retry bound to its new source`, async () => {
439 const client = new DbClient()
440 const first = source(`settings`, `first`)
441 const second = source(`settings`, `second`)
442 const never = new Promise<void>(() => {})
443 const View = ({
444 current,
445 suspend,
446 }: {
447 current: typeof first
448 suspend: boolean
449 }) => {
450 const { data } = useLiveSuspenseQuery({
451 client,
452 query: (q) => q.from({ settings: current }),
453 })
454 if (suspend) throw never
455 return <div>{data[0]?.value}</div>
456 }
457 const root = render(
458 <Suspense fallback={<div>Loading</div>}>
459 <View current={first} suspend={true} />
460 </Suspense>,
461 )
462 expect(root.getByText(`Loading`)).toBeDefined()
463 root.rerender(
464 <Suspense fallback={<div>Loading</div>}>
465 <View current={second} suspend={false} />
466 </Suspense>,
467 )
468 await waitFor(() => expect(root.getByText(`second`)).toBeDefined())
469 })
470
471 it(`remembers IDs across DbProvider client switches`, async () => {
472 const firstClient = new DbClient()
473 const secondClient = new DbClient()
474 const first = source(`settings`, `first`)
475 const otherScope = source(`settings`, `other`)
476 const replacement = source(`settings`, `replacement`)
477 const View = ({ current }: { current: typeof first }) => {
478 const { data } = useLiveQuery({
479 query: (q) => q.from({ settings: current }),
480 })
481 return <div>{data[0]?.value}</div>
482 }
483 const root = render(
484 <DbProvider client={firstClient}>
485 <View current={first} />
486 </DbProvider>,
487 )
488 await waitFor(() => expect(root.getByText(`first`)).toBeDefined())
489 root.rerender(
490 <DbProvider client={secondClient}>
491 <View current={otherScope} />
492 </DbProvider>,
493 )
494 await waitFor(() => expect(root.getByText(`other`)).toBeDefined())
495 expect(() =>
496 root.rerender(
497 <DbProvider client={firstClient}>
498 <View current={replacement} />
499 </DbProvider>,
500 ),
501 ).toThrow(/source Collection .*same ID/i)
502 })
503
504 it(`remembers each client scope when one mounted hook switches clients`, async () => {
505 const firstClient = new DbClient()
506 const secondClient = new DbClient()
507 const first = source(`settings`, `first`)
508 const otherScope = source(`settings`, `other`)
509 const replacement = source(`settings`, `replacement`)
510 const hook = renderHook(
511 ({ client, current }) =>
512 useLiveQuery({
513 client,
514 query: (q) => q.from({ settings: current }),
515 }),
516 { initialProps: { client: firstClient, current: first } },
517 )
518
519 await waitFor(() =>
520 expect(hook.result.current.data[0]?.value).toBe(`first`),
521 )
522 hook.rerender({ client: secondClient, current: otherScope })
523 await waitFor(() =>
524 expect(hook.result.current.data[0]?.value).toBe(`other`),
525 )
526 checkRerender(
527 [
528 { source: first, client: firstClient },
529 { source: otherScope, client: secondClient },
530 ],
531 { source: replacement, client: firstClient },
532 () => hook.rerender({ client: firstClient, current: replacement }),
533 )
534 })
535
536 it(`rejects same-ID reuse after a suspended render starts a source query`, async () => {
537 const first = source(`first`, `first`)
538 const abandoned = source(`candidate`, `abandoned`)
539 const replacement = source(`candidate`, `replacement`)
540 const never = new Promise<void>(() => {})
541 const View = ({
542 current,
543 suspend,
544 }: {
545 current: typeof first
546 suspend: boolean
547 }) => {
548 const { data } = useLiveQuery({
549 query: (q) => q.from({ settings: current }),
550 })
551 if (suspend) throw never
552 return <div>{data[0]?.value}</div>
553 }
554 const root = render(
555 <Suspense fallback={<div>Loading</div>}>
556 <View current={first} suspend={false} />
557 </Suspense>,
558 )
559 await waitFor(() => expect(root.getByText(`first`)).toBeDefined())
560
561 root.rerender(
562 <Suspense fallback={<div>Loading</div>}>
563 <View current={abandoned} suspend={true} />
564 </Suspense>,
565 )
566 checkRerender(
567 [{ source: first }, { source: abandoned }],
568 { source: replacement },
569 () =>
570 root.rerender(
571 <Suspense fallback={<div>Loading</div>}>
572 <View current={replacement} suspend={false} />
573 </Suspense>,
574 ),
575 )
576 })
577})
578
579/**
580 * ## useLiveInfiniteQuery
581 *
582 * The infinite hook derives its identity the same way, and keeps the window
583 * collection built by its latest render for a second render before commit.
584 * That cache is keyed by derived identity, which names sources by ID, so the
585 * same law applies: a different same-ID source must reject before the hook
586 * can publish the old source's rows, from a committed or a suspended render.
587 * This driver reuses the model above with the bounded histories that
588 * distinguish the law from a hash-only check.
589 */
590describe(`React source ID reuse: useLiveInfiniteQuery`, () => {
591 const useInfinite = (current: ReturnType<typeof source>) =>
592 useLiveInfiniteQuery(
593 (q) =>
594 q.from({ settings: current }).orderBy(({ settings }) => settings.rank),
595 { pageSize: 1 },
596 )
597
598 it(`rejects a different active source with the same ID before exposing stale rows`, async () => {
599 const first = source(`settings`, `first`)
600 const second = source(`settings`, `second`)
601 const hook = renderHook(({ current }) => useInfinite(current), {
602 initialProps: { current: first },
603 })
604 await waitFor(() =>
605 expect(hook.result.current.data[0]?.value).toBe(`first`),
606 )
607 checkRerender([{ source: first }], { source: second }, () =>
608 hook.rerender({ current: second }),
609 )
610 })
611
612 it(`rejects a previously used ID after another source`, async () => {
613 const first = source(`settings`, `first`)
614 const other = source(`other`, `other`)
615 const second = source(`settings`, `second`)
616 const hook = renderHook(({ current }) => useInfinite(current), {
617 initialProps: { current: first },
618 })
619 await waitFor(() =>
620 expect(hook.result.current.data[0]?.value).toBe(`first`),
621 )
622 act(() => hook.rerender({ current: other }))
623 await waitFor(() =>
624 expect(hook.result.current.data[0]?.value).toBe(`other`),
625 )
626 checkRerender(
627 [{ source: first }, { source: other }],
628 { source: second },
629 () => hook.rerender({ current: second }),
630 )
631 })
632
633 it(`accepts the same source object and a different source ID`, async () => {
634 const first = source(`settings`, `first`)
635 const other = source(`other`, `other`)
636 const hook = renderHook(({ current }) => useInfinite(current), {
637 initialProps: { current: first },
638 })
639 await waitFor(() =>
640 expect(hook.result.current.data[0]?.value).toBe(`first`),
641 )
642 checkRerender([{ source: first }], { source: first }, () =>
643 hook.rerender({ current: first }),
644 )
645 checkRerender([{ source: first }], { source: other }, () =>
646 hook.rerender({ current: other }),
647 )
648 await waitFor(() =>
649 expect(hook.result.current.data[0]?.value).toBe(`other`),
650 )
651 })
652
653 it(`rejects same-ID reuse after a suspended render starts a source query`, async () => {
654 const first = source(`first`, `first`)
655 const abandoned = source(`candidate`, `abandoned`)
656 const replacement = source(`candidate`, `replacement`)
657 const never = new Promise<void>(() => {})
658 const View = ({
659 current,
660 suspend,
661 }: {
662 current: typeof first
663 suspend: boolean
664 }) => {
665 const { data } = useInfinite(current)
666 if (suspend) throw never
667 return <div>{data[0]?.value}</div>
668 }
669 const root = render(
670 <Suspense fallback={<div>Loading</div>}>
671 <View current={first} suspend={false} />
672 </Suspense>,
673 )
674 await waitFor(() => expect(root.getByText(`first`)).toBeDefined())
675 root.rerender(
676 <Suspense fallback={<div>Loading</div>}>
677 <View current={abandoned} suspend={true} />
678 </Suspense>,
679 )
680 checkRerender(
681 [{ source: first }, { source: abandoned }],
682 { source: replacement },
683 () =>
684 root.rerender(
685 <Suspense fallback={<div>Loading</div>}>
686 <View current={replacement} suspend={false} />
687 </Suspense>,
688 ),
689 )
690 })
691
692 it(`releases a shared descriptor's sync deferral when a collision tears down the hook`, async () => {
693 const client = new DbClient()
694 const first = source(`settings`, `first`)
695 const replacement = source(`settings`, `replacement`)
696 let syncStarts = 0
697 const descriptor = collectionOptions(
698 `infinite-shared-after-collision`,
699 () => ({
700 id: `infinite-shared-after-collision`,
701 getKey: (row: Row) => row.id,
702 sync: {
703 sync: ({ begin, write, commit, markReady }) => {
704 syncStarts++
705 begin()
706 write({
707 type: `insert`,
708 value: { id: `one`, value: `shared`, rank: 1 },
709 })
710 commit()
711 markReady()
712 },
713 },
714 }),
715 )
716 const consoleError = vi.spyOn(console, `error`).mockImplementation(() => {})
717 function View({
718 current,
719 includeShared,
720 }: {
721 current: typeof first
722 includeShared: boolean
723 }) {
724 useLiveInfiniteQuery(
725 (q) =>
726 includeShared
727 ? q
728 .from({ settings: current })
729 .join({ shared: descriptor }, ({ settings, shared }) =>
730 eq(settings.id, shared.id),
731 )
732 .orderBy(({ settings }) => settings.rank)
733 : q
734 .from({ settings: current })
735 .orderBy(({ settings }) => settings.rank),
736 { pageSize: 1, client },
737 )
738 return <div>Query</div>
739 }
740 try {
741 const root = render(
742 <TestErrorBoundary>
743 <View current={first} includeShared={false} />
744 </TestErrorBoundary>,
745 )
746 await act(async () => {})
747 root.rerender(
748 <TestErrorBoundary>
749 <View current={replacement} includeShared={true} />
750 </TestErrorBoundary>,
751 )
752 expect(root.getByText(`Rejected`)).toBeDefined()
753 expect(syncStarts).toBe(0)
754 const shared = client.collection(descriptor)
755 const reader = renderHook(() => useLiveQuery(shared))
756 await act(async () => {})
757 expect(reader.result.current.data[0]?.value).toBe(`shared`)
758 expect(syncStarts).toBe(1)
759 } finally {
760 consoleError.mockRestore()
761 }
762 })
763})