fix(db): preserve explicit gcTime of 0 on live query collections#1660
Conversation
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.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughThis PR fixes a bug in ChangesgcTime Default Fix
Estimated code review effort: 1 (Trivial) | ~3 minutes Possibly related PRs
Suggested reviewers: 🚥 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. Comment |
More templates
@tanstack/angular-db
@tanstack/browser-db-sqlite-persistence
@tanstack/capacitor-db-sqlite-persistence
@tanstack/cloudflare-durable-objects-db-sqlite-persistence
@tanstack/db
@tanstack/db-ivm
@tanstack/db-sqlite-persistence-core
@tanstack/electric-db-collection
@tanstack/electron-db-sqlite-persistence
@tanstack/expo-db-sqlite-persistence
@tanstack/node-db-sqlite-persistence
@tanstack/offline-transactions
@tanstack/powersync-db-collection
@tanstack/query-db-collection
@tanstack/react-db
@tanstack/react-native-db-sqlite-persistence
@tanstack/rxdb-db-collection
@tanstack/solid-db
@tanstack/svelte-db
@tanstack/tauri-db-sqlite-persistence
@tanstack/trailbase-db-collection
@tanstack/vue-db
commit: |
The live query config builder built its collection options with
gcTime: this.config.gcTime || 5000. AgcTimeof0disables garbage collection (the core lifecycle treatsgcTime <= 0as "never GC"), but0 || 5000evaluates to5000, so an explicitgcTime: 0on 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 onlyundefinedfalls back to the default; an explicit0is forwarded and GC is disabled as documented.Repro:
liveQueryCollectionOptions({ query, gcTime: 0 }).gcTimereturns5000instead of0. Added a regression test.Summary by CodeRabbit
gcTime: 0is preserved instead of being replaced with the default timeout.gcTime: 0continues to work correctly.