Skip to content
Source
Sign inSign up
TanStack/db

fix(svelte-db): disabled useLiveQuery no longer crashes #1637

Mergedkevin-dp(GitHub profile, opens in a new tab)merged 1 commit intomain fromrefs/pull/1637/headmerged by kevin-dp(GitHub profile, opens in a new tab)

Showing 3 changed files with 15 additions and 7 deletions.

x
0 of 3 viewed, 3 left
7 additions and 0 deletions.changeset/svelte-disabled-query-fix.mdAdded
View file
@@ -0,0 +1,7 @@
+---
+'@tanstack/svelte-db': patch
+---
+​
+fix(svelte-db): a disabled `useLiveQuery` (query callback returning `null`/`undefined`) no longer crashes
+​
+The reactive-getter unwrapping (`toValue`) called the query callback and, when it returned `null`/`undefined` to signal a disabled query, passed the unwrapped `null` into `createLiveQueryCollection`, throwing in `getQueryIR`. A `null`/`undefined` resolved value is now treated as a disabled query (returns the `disabled` state) as it is in the other adapters.
7 additions and 0 deletionspackages/svelte-db/src/useLiveQuery.svelte.tsModified
View file
@@ -350,6 +350,13 @@
startSync: true,
} else {
+ // A reactive getter (or param-driven query fn) can resolve to null/undefined
+ // to mean "disabled". `toValue` above already called it, so guard here —
+ // otherwise `{ ...null }` reaches createLiveQueryCollection and throws.
+ if (unwrappedParam === undefined || unwrappedParam === null) {
+ return null
+ }
+​
return createLiveQueryCollection({
...unwrappedParam,
startSync: true,