Skip to content
Source
Sign inSign up
TanStack/db

fix(db): preserve explicit gcTime of 0 on live query collections #1660

Mergedspokodev(GitHub profile, opens in a new tab)merged 2 commits intomain fromrefs/pull/1660/headmerged by KyleAMathews(GitHub profile, opens in a new tab)

Showing 3 changed files with 21 additions and 1 deletion.

x
0 of 3 viewed, 3 left
5 additions and 0 deletions.changeset/live-query-gctime-zero.mdAdded
View file
@@ -0,0 +1,5 @@
+---
+'@tanstack/db': patch
+---
+​
+Preserve an explicit `gcTime: 0` on live query collections. The live query config builder used `this.config.gcTime || 5000`, so a `gcTime` of `0` (which disables garbage collection) was treated as unset and silently replaced by the 5s default, causing the collection to be garbage collected instead of kept alive. Use `??` so only `undefined` falls back to the default.
1 addition and 1 deletionpackages/db/src/query/live/collection-config-builder.tsModified
View file
@@ -248,7 +248,7 @@
sync: this.getSyncConfig(),
compare: this.compare,
defaultStringCollation: this.compareOptions,
- gcTime: this.config.gcTime || 5000, // 5 seconds by default for live queries
+ gcTime: this.config.gcTime ?? 5000, // 5 seconds by default for live queries
schema: this.config.schema,
onInsert: this.config.onInsert,
onUpdate: this.config.onUpdate,
15 additions and 0 deletionspackages/db/tests/query/live-query-collection.test.tsModified
View file
@@ -449,6 +449,21 @@