Skip to content

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

Open
spokodev wants to merge 1 commit into
TanStack:mainfrom
spokodev:fix/live-query-gctime-zero
Open

fix(db): preserve explicit gcTime of 0 on live query collections#1660
spokodev wants to merge 1 commit into
TanStack:mainfrom
spokodev:fix/live-query-gctime-zero

Conversation

@spokodev

@spokodev spokodev commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

The live query config builder built its collection options with gcTime: this.config.gcTime || 5000. A gcTime of 0 disables garbage collection (the core lifecycle treats gcTime <= 0 as "never GC"), but 0 || 5000 evaluates to 5000, so an explicit gcTime: 0 on a live query collection is silently replaced by the 5s default and the collection is garbage collected 5s after its last subscriber unsubscribes.

Use ?? so only undefined falls back to the default; an explicit 0 is forwarded and GC is disabled as documented.

Repro: liveQueryCollectionOptions({ query, gcTime: 0 }).gcTime returns 5000 instead of 0. Added a regression test.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed live query settings so an explicitly set gcTime: 0 is preserved instead of being replaced with the default timeout.
    • Live query behavior now respects disabled garbage collection as intended.
    • Added coverage to verify that gcTime: 0 continues to work correctly.

The live query config builder used `this.config.gcTime || 5000`, which
treats an explicit `gcTime: 0` (disable GC) as unset and replaces it with
the 5s default. The collection is then garbage collected instead of being
kept alive. Use `??` so only `undefined` falls back to the default.
@coderabbitai

coderabbitai Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 09101176-28b1-45f3-b1b1-f6284f180fd3

📥 Commits

Reviewing files that changed from the base of the PR and between a93abf6 and f9be1a6.

📒 Files selected for processing (3)
  • .changeset/live-query-gctime-zero.md
  • packages/db/src/query/live/collection-config-builder.ts
  • packages/db/tests/query/live-query-collection.test.ts

📝 Walkthrough

Walkthrough

This PR fixes a bug in @tanstack/db's live query collection config where an explicit gcTime: 0 was incorrectly replaced with a 5000ms default due to falsy-value coercion via ||. The fix switches to ?? so only undefined triggers the default.

Changes

gcTime Default Fix

Layer / File(s) Summary
Nullish-coalescing fix for gcTime default
packages/db/src/query/live/collection-config-builder.ts
Changes this.config.gcTime || 5000 to this.config.gcTime ?? 5000 so gcTime: 0 is preserved instead of falling back to the default.
Test coverage and changeset
packages/db/tests/query/live-query-collection.test.ts, .changeset/live-query-gctime-zero.md
Adds a test asserting liveQueryCollectionOptions returns gcTime: 0 when explicitly configured, and adds a changeset documenting the patch.

Estimated code review effort: 1 (Trivial) | ~3 minutes

Possibly related PRs

  • TanStack/db#1568: Also touches gcTime plumbing in the live/query collection configuration path.

Suggested reviewers: kevin-dp

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main fix: preserving an explicit gcTime of 0 for live query collections.
Description check ✅ Passed The description explains the bug, fix, and regression test, but it does not follow the repository template sections exactly.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant