@tanstack/svelte-db 0.1.3 → 0.1.4

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 { untrack } from "svelte";
1
+ import { flushSync, untrack } from "svelte";
2
2
  import { createLiveQueryCollection } from "@tanstack/db";
3
3
  import { SvelteMap } from "svelte/reactivity";
4
4
  function toValue(value) {
@@ -31,7 +31,10 @@ export function useLiveQuery(configOrQueryOrCollection, deps = []) {
31
31
  typeof unwrappedParam.id === `string`;
32
32
  if (isCollection) {
33
33
  // It's already a collection, ensure sync is started for Svelte helpers
34
- unwrappedParam.startSyncImmediate();
34
+ // Only start sync if the collection is in idle state
35
+ if (unwrappedParam.status === `idle`) {
36
+ unwrappedParam.startSyncImmediate();
37
+ }
35
38
  return unwrappedParam;
36
39
  }
37
40
  // Reference deps to make computed reactive to them
@@ -83,6 +86,14 @@ export function useLiveQuery(configOrQueryOrCollection, deps = []) {
83
86
  });
84
87
  // Initialize data array in correct order
85
88
  syncDataFromCollection(currentCollection);
89
+ // Listen for the first ready event to catch status transitions
90
+ // that might not trigger change events (fixes async status transition bug)
91
+ currentCollection.onFirstReady(() => {
92
+ // Use flushSync to ensure Svelte reactivity updates properly
93
+ flushSync(() => {
94
+ status = currentCollection.status;
95
+ });
96
+ });
86
97
  // Subscribe to collection changes with granular updates
87
98
  currentUnsubscribe = currentCollection.subscribeChanges((changes) => {
88
99
  // Apply each change individually to the reactive state
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@tanstack/svelte-db",
3
3
  "description": "Svelte integration for @tanstack/db",
4
- "version": "0.1.3",
4
+ "version": "0.1.4",
5
5
  "dependencies": {
6
- "@tanstack/db": "0.1.3"
6
+ "@tanstack/db": "0.1.4"
7
7
  },
8
8
  "devDependencies": {
9
9
  "@sveltejs/package": "^2.4.0",