Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/live-query-gctime-zero.md
Original file line number Diff line number Diff line change
@@ -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.
2 changes: 1 addition & 1 deletion packages/db/src/query/live/collection-config-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ export class CollectionConfigBuilder<
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,
Expand Down
15 changes: 15 additions & 0 deletions packages/db/tests/query/live-query-collection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,21 @@ describe(`createLiveQueryCollection`, () => {
})
})

it(`should forward an explicit gcTime of 0 (disable GC) instead of coercing it to the default`, () => {
const options = liveQueryCollectionOptions({
query: (q) =>
q
.from({ user: usersCollection })
.where(({ user }) => eq(user.active, true)),
gcTime: 0,
})

// gcTime: 0 disables garbage collection. A `|| 5000` fallback treats the
// explicit 0 as unset and silently replaces it with the 5s default, so the
// collection is garbage collected instead of being kept alive.
expect(options.gcTime).toBe(0)
})

it(`should not reuse finalized graph after GC cleanup (resubscribe is safe)`, async () => {
const liveQuery = createLiveQueryCollection({
query: (q) =>
Expand Down