fix(db): preserve explicit gcTime of 0 on live query collections #1660
main fromrefs/pull/1660/head·merged by KyleAMathews(GitHub profile, opens in a new tab) 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: 0is 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: 0continues to work correctly.
- Fixed live query settings so an explicitly set
- 1
More templates
@tanstack/angular-db
npm i https://pkg.pr.new/@tanstack/angular-db@1660@tanstack/browser-db-sqlite-persistence
npm i https://pkg.pr.new/@tanstack/browser-db-sqlite-persistence@1660@tanstack/capacitor-db-sqlite-persistence
npm i https://pkg.pr.new/@tanstack/capacitor-db-sqlite-persistence@1660@tanstack/cloudflare-durable-objects-db-sqlite-persistence
npm i https://pkg.pr.new/@tanstack/cloudflare-durable-objects-db-sqlite-persistence@1660@tanstack/db
npm i https://pkg.pr.new/@tanstack/db@1660@tanstack/db-ivm
npm i https://pkg.pr.new/@tanstack/db-ivm@1660@tanstack/db-sqlite-persistence-core
npm i https://pkg.pr.new/@tanstack/db-sqlite-persistence-core@1660@tanstack/electric-db-collection
npm i https://pkg.pr.new/@tanstack/electric-db-collection@1660@tanstack/electron-db-sqlite-persistence
npm i https://pkg.pr.new/@tanstack/electron-db-sqlite-persistence@1660@tanstack/expo-db-sqlite-persistence
npm i https://pkg.pr.new/@tanstack/expo-db-sqlite-persistence@1660@tanstack/node-db-sqlite-persistence
npm i https://pkg.pr.new/@tanstack/node-db-sqlite-persistence@1660@tanstack/offline-transactions
npm i https://pkg.pr.new/@tanstack/offline-transactions@1660@tanstack/powersync-db-collection
npm i https://pkg.pr.new/@tanstack/powersync-db-collection@1660@tanstack/query-db-collection
npm i https://pkg.pr.new/@tanstack/query-db-collection@1660@tanstack/react-db
npm i https://pkg.pr.new/@tanstack/react-db@1660@tanstack/react-native-db-sqlite-persistence
npm i https://pkg.pr.new/@tanstack/react-native-db-sqlite-persistence@1660@tanstack/rxdb-db-collection
npm i https://pkg.pr.new/@tanstack/rxdb-db-collection@1660@tanstack/solid-db
npm i https://pkg.pr.new/@tanstack/solid-db@1660@tanstack/svelte-db
npm i https://pkg.pr.new/@tanstack/svelte-db@1660@tanstack/tauri-db-sqlite-persistence
npm i https://pkg.pr.new/@tanstack/tauri-db-sqlite-persistence@1660@tanstack/trailbase-db-collection
npm i https://pkg.pr.new/@tanstack/trailbase-db-collection@1660@tanstack/vue-db
npm i https://pkg.pr.new/@tanstack/vue-db@1660commit:
82c4b13KyleAMathews(GitHub profile, opens in a new tab) approved these changes
thanks!
KyleAMathews(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.
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 a93abf66b1d6e2a5dcbab1f4686890eec7d41436 and f9be1a63f6b817a87aa4525f6d87f19700d3184b.
📒 Files selected for processing (3)
.changeset/live-query-gctime-zero.mdpackages/db/src/query/live/collection-config-builder.tspackages/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 explicitgcTime: 0was incorrectly replaced with a 5000ms default due to falsy-value coercion via||. The fix switches to??so onlyundefinedtriggers the default.Changes#
gcTime Default Fix
packages/db/src/query/live/collection-config-builder.tsthis.config.gcTime || 5000tothis.config.gcTime ?? 5000sogcTime: 0is preserved instead of falling back to the default.packages/db/tests/query/live-query-collection.test.ts,.changeset/live-query-gctime-zero.mdliveQueryCollectionOptionsreturnsgcTime: 0when explicitly configured, and adds a changeset documenting the patch.Estimated code review effort: 1 (Trivial) | ~3 minutes
Possibly related PRs
Suggested reviewers:
kevin-dp🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
✨ Finishing Touches
🧪 Generate unit tests (beta)
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