test(query-db-collection): characterize cancellation and subset cleanup#1673
Conversation
📝 WalkthroughWalkthroughThis change tracks temporary query-readiness subscriptions, reuses centralized readiness waiting, cleans pending listeners during query cleanup, and adds lifecycle tests covering cancellation, subset unloading, remounting, invalidation, and observer release. ChangesQuery readiness cleanup
Estimated code review effort: 3 (Moderate) | ~25 minutes Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint install failed. For unrecoverable errors, disable the tool in CodeRabbit configuration. 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: |
|
Size Change: 0 B Total Size: 125 kB ℹ️ View Unchanged
|
|
Size Change: 0 B Total Size: 4.22 kB ℹ️ View Unchanged
|
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/query-db-collection/tests/query.test.ts (1)
2430-2467: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winCover the readiness-error cleanup path.
This suite only settles deferred queries with
resolve, whilewaitForQueryReadyhas separate error cleanup logic. Add a rejected-preload case that verifies rejection and observer release, unless equivalent coverage already exists.As per coding guidelines, “Always add unit tests that reproduce a bug before fixing it” and test async race conditions.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/query-db-collection/tests/query.test.ts` around lines 2430 - 2467, Add a rejected-preload test alongside the existing late-result test, using a deferred query that rejects after liveQuery.cleanup(). Verify preload rejects, the query observer count is released while the request is pending and after rejection, and retain cleanup assertions for the collection. Exercise the waitForQueryReady error-cleanup path rather than only the successful resolution path.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@packages/query-db-collection/tests/query.test.ts`:
- Around line 2430-2467: Add a rejected-preload test alongside the existing
late-result test, using a deferred query that rejects after liveQuery.cleanup().
Verify preload rejects, the query observer count is released while the request
is pending and after rejection, and retain cleanup assertions for the
collection. Exercise the waitForQueryReady error-cleanup path rather than only
the successful resolution path.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 196919b7-0cf0-4153-9d50-081591630eb5
📒 Files selected for processing (3)
.changeset/characterize-query-cleanup.mdpackages/query-db-collection/src/query.tspackages/query-db-collection/tests/query.test.ts
Summary
Characterizes query cancellation and subset cleanup across aborts, late results, cache removal, rapid remounts, and invalidation cycles. It also fixes temporary readiness listeners so in-flight subset unload and collection cleanup do not retain stale Query Core observers.
Root cause
The temporary
QueryObserver.subscribelisteners used to settle subset readiness promises were not tracked separately. During an in-flight unload, those listeners keptobserver.hasListeners()true, preventing idle subset cleanup and leaving a stale observer behind.Approach
waitForQueryReadyhelper.Key invariants
Non-goals
Trade-offs
This uses private listener bookkeeping rather than introducing a broader ownership abstraction. It is intentionally narrow and regression-tested; a larger lifecycle state machine can be considered separately.
Verification
The lifecycle subset passed five consecutive runs. The package suite passed 236 tests with no type errors.
Files changed
packages/query-db-collection/src/query.ts— track and release temporary readiness listeners and centralize their lifecycle.packages/query-db-collection/tests/query.test.ts— add focused cancellation and cleanup characterization coverage..changeset/characterize-query-cleanup.md— record the patch-level cleanup fix.Summary by CodeRabbit