You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(db): track loadSubset promise for on-demand live queries (#1192)
* fix(db): track loadSubset promise for non-ordered on-demand live queries
When a live query without orderBy/limit subscribes to an on-demand
collection, the subscription was passing includeInitialState: true to
subscribeChanges, which internally called requestSnapshot with
trackLoadSubsetPromise: false. This prevented the subscription status
from transitioning to 'loadingSubset', causing the live query to be
marked ready before data actually loaded.
The fix changes subscribeToMatchingChanges to manually call
requestSnapshot() after creating the subscription (with default
tracking enabled), ensuring the loadSubset promise is properly
tracked and the live query waits for data before becoming ready.
Co-Authored-By: Claude Opus 4.5 <[email protected]>
* fix(db): handle cleanup and cache edge cases for on-demand live queries
This follow-up fix addresses edge cases that caused tests to fail after
the initial isReady fix:
1. lifecycle.ts: Call pending onFirstReady callbacks during cleanup
- Prevents preload() promises from hanging when cleanup happens
- Ensures clean termination of pending preload operations
2. query.ts: Add fallback cache checks in createQueryFromOpts
- Check QueryClient cache when observer state is out of sync
- Handle cases where observer was deleted but data is still cached
- Prevents hangs during cleanup/recreate cycles
3. Test updates:
- Updated where clause tests to use synchronous loadSubset
- These tests verify where clause passing, not async loading behavior
Co-Authored-By: Claude Opus 4.5 <[email protected]>
* chore: add changeset for on-demand isReady fix
Co-Authored-By: Claude Opus 4.5 <[email protected]>
* ci: apply automated fixes
* fix(db): address review feedback - cleanup and error handling
- Fix potential memory leak in trackCollectionLoading by registering
cleanup callback for early unsubscribe scenarios
- Add error handling for onFirstReady callbacks during cleanup to
ensure all callbacks are attempted even if one throws
Co-Authored-By: Claude Opus 4.5 <[email protected]>
* fix: concurrent live queries now independently track loading state
Previously, when multiple live queries subscribed to the same source
collection, only the first would correctly track loading state due to
the `!wasLoadingBefore` guard. This caused subsequent live queries to
incorrectly report `isReady` before data finished loading.
The fix removes this guard since each live query needs its own loading
state tracking regardless of whether another query already triggered
loading.
Also adds a regression test for this scenario.
Co-Authored-By: Claude Opus 4.5 <[email protected]>
* Fix ordered live query paging offset tracking
* ci: apply automated fixes
* Add regression coverage for ordered on-demand paging
* Avoid passing cross-alias orderBy to loadSubset
* Avoid redundant ordered loads while snapshot pending
* Refactor subscription loading tracking
* refactor: simplify subscription and collection-subscriber code
- Remove redundant has() check before Set.add() (idempotent operation)
- Replace nested ternary with clearer if-statement for minValues
Co-Authored-By: Claude Opus 4.5 <[email protected]>
---------
Co-authored-by: Claude Opus 4.5 <[email protected]>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Fix `isReady` tracking for on-demand live queries without orderBy. Previously, non-ordered live queries using `syncMode: 'on-demand'` were incorrectly marked as ready before data finished loading. Also fix `preload()` promises hanging when cleanup occurs before the collection becomes ready. Additionally, fix concurrent live queries subscribing to the same source collection - each now independently tracks loading state.
0 commit comments