@tanstack/svelte-db 0.5.5 → 0.5.8

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.
@@ -1,4 +1,4 @@
1
- import { assertLiveQueryWindowManyResult, compareLiveQueryWindowDependencies, createLiveQueryCollection, createLiveQueryWindowController, fetchNextLiveQueryWindowPage, getLiveQueryWindowCollectionWarning, normalizeLiveQueryWindowPageSize, resolveLiveQueryWindowInput, shouldPreserveLiveQueryWindowPageCount, } from '@tanstack/db';
1
+ import { assertLiveQueryWindowManyResult, compareLiveQueryWindowDependencies, createLiveQueryCollection, createLiveQueryWindowController, fetchNextLiveQueryWindowPage, getLiveQueryWindowCollectionWarning, liveQueryWindowMatches, normalizeLiveQueryWindowPageSize, resolveLiveQueryWindowInput, shouldPreserveLiveQueryWindowPageCount, } from '@tanstack/db';
2
2
  import { tick, untrack } from 'svelte';
3
3
  const DEFAULT_GC_TIME_MS = 1;
4
4
  export function useLiveInfiniteQuery(queryFnOrCollection, config, deps = []) {
@@ -37,6 +37,8 @@ export function useLiveInfiniteQuery(queryFnOrCollection, config, deps = []) {
37
37
  ? Math.max(1, previousController.getSnapshot().pages.length)
38
38
  : 1;
39
39
  const initialPageCount = canPreservePageCount ? previousPageCount : 1;
40
+ // The peek-ahead window for every retained page.
41
+ const requiredLimit = initialPageCount * pageSize + 1;
40
42
  previousInput = input;
41
43
  previousDependencies = [...dependencies];
42
44
  previousPageSize = pageSize;
@@ -49,6 +51,12 @@ export function useLiveInfiniteQuery(queryFnOrCollection, config, deps = []) {
49
51
  if (warning)
50
52
  console.warn(warning);
51
53
  }
54
+ // Like useLiveQuery, start a supplied collection during construction when
55
+ // its rows are already correct. A window the controller must still adjust
56
+ // waits for the subscription.
57
+ if (liveQueryWindowMatches(collection, requiredLimit)) {
58
+ collection.startSyncImmediate();
59
+ }
52
60
  const currentController = createLiveQueryWindowController(collection, {
53
61
  pageSize,
54
62
  initialPageParam,
@@ -58,11 +66,16 @@ export function useLiveInfiniteQuery(queryFnOrCollection, config, deps = []) {
58
66
  return currentController;
59
67
  }
60
68
  const collection = createLiveQueryCollection({
61
- query: input.query.limit(pageSize + 1).offset(0),
62
- startSync: false,
69
+ // Size the window for every retained page, so a collection that starts
70
+ // syncing now never publishes fewer rows than the controller's pages.
71
+ query: input.query.limit(requiredLimit).offset(0),
63
72
  gcTime: DEFAULT_GC_TIME_MS,
64
73
  });
65
74
  assertLiveQueryWindowManyResult(collection);
75
+ // Like useLiveQuery, start sync during construction once the query is
76
+ // valid. Construction reads only rows the sources already hold and sends
77
+ // no request until the subscribing effect attaches.
78
+ collection.startSyncImmediate();
66
79
  const currentController = createLiveQueryWindowController(collection, {
67
80
  pageSize,
68
81
  initialPageParam,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/svelte-db",
3
- "version": "0.5.5",
3
+ "version": "0.5.8",
4
4
  "description": "Svelte integration for @tanstack/db",
5
5
  "author": "Kyle Mathews",
6
6
  "license": "MIT",
@@ -35,7 +35,7 @@
35
35
  "skills"
36
36
  ],
37
37
  "dependencies": {
38
- "@tanstack/db": "0.12.1"
38
+ "@tanstack/db": "0.13.0"
39
39
  },
40
40
  "peerDependencies": {
41
41
  "svelte": "^5.0.0"