Skip to content

Add explicit collection readiness detection with isReady() and markReady()#270

Merged
KyleAMathews merged 3 commits intomainfrom
mark-is-ready
Jul 16, 2025
Merged

Add explicit collection readiness detection with isReady() and markReady()#270
KyleAMathews merged 3 commits intomainfrom
mark-is-ready

Conversation

@KyleAMathews
Copy link
Copy Markdown
Collaborator

Summary

This PR implements explicit collection readiness detection as requested in #266, replacing the previous approach of using commits as readiness signals.

Changes Made

  • Add isReady() method to check if a collection is ready for use
  • Add onFirstReady() method to register callbacks for when collection becomes ready (replaces onFirstCommit())
  • Add markReady() to SyncConfig interface for sync implementations to explicitly signal readiness
  • Update status state machine to allow loadingready transition for cases with no data to commit
  • Update all sync implementations (Electric, Query, Local-only, Local-storage) to use markReady()
  • Improve error handling by allowing collections to be marked ready even when sync errors occur

Benefits

  • More intuitive API for determining collection readiness
  • Better handling of edge cases (empty backends, network errors)
  • Eliminates the need for awkward empty commits just to signal readiness
  • Maintains full backwards compatibility with existing code

Test Coverage

All tests pass (716 tests), including new lifecycle tests that verify the readiness detection works correctly in various scenarios.

Fixes #266

🤖 Generated with Claude Code

KyleAMathews and others added 2 commits July 16, 2025 10:44
…ady()

- Add isReady() method to check if a collection is ready for use
- Add onFirstReady() method to register callbacks for when collection becomes ready
- Add markReady() to SyncConfig interface for sync implementations to explicitly signal readiness
- Replace onFirstCommit() with onFirstReady() for better semantics
- Update status state machine to allow loading → ready transition for cases with no data to commit
- Update all sync implementations (Electric, Query, Local-only, Local-storage) to use markReady()
- Improve error handling by allowing collections to be marked ready even when sync errors occur

This provides a more intuitive and ergonomic API for determining collection readiness,
replacing the previous approach of using commits as a readiness signal.

Fixes #266

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Jul 16, 2025

🦋 Changeset detected

Latest commit: 56c0a2e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 6 packages
Name Type
@tanstack/electric-db-collection Patch
@tanstack/query-db-collection Patch
@tanstack/db Patch
@tanstack/db-example-react-todo Patch
@tanstack/react-db Patch
@tanstack/vue-db Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Jul 16, 2025

@tanstack/db-example-react-todo

@tanstack/db

npm i https://pkg.pr.new/@tanstack/db@270

@tanstack/electric-db-collection

npm i https://pkg.pr.new/@tanstack/electric-db-collection@270

@tanstack/query-db-collection

npm i https://pkg.pr.new/@tanstack/query-db-collection@270

@tanstack/react-db

npm i https://pkg.pr.new/@tanstack/react-db@270

@tanstack/vue-db

npm i https://pkg.pr.new/@tanstack/vue-db@270

commit: 56c0a2e

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Jul 16, 2025

Size Change: +295 B (+0.78%)

Total Size: 38.2 kB

Filename Size Change
./packages/db/dist/esm/collection.js 8.71 kB +256 B (+3.03%)
./packages/db/dist/esm/local-only.js 827 B +12 B (+1.47%)
./packages/db/dist/esm/local-storage.js 2.09 kB +16 B (+0.77%)
./packages/db/dist/esm/query/live-query-collection.js 2.07 kB +11 B (+0.54%)
ℹ️ View Unchanged
Filename Size
./packages/db/dist/esm/deferred.js 230 B
./packages/db/dist/esm/errors.js 150 B
./packages/db/dist/esm/index.js 568 B
./packages/db/dist/esm/optimistic-action.js 294 B
./packages/db/dist/esm/proxy.js 3.79 kB
./packages/db/dist/esm/query/builder/functions.js 531 B
./packages/db/dist/esm/query/builder/index.js 3.68 kB
./packages/db/dist/esm/query/builder/ref-proxy.js 842 B
./packages/db/dist/esm/query/compiler/evaluators.js 1.34 kB
./packages/db/dist/esm/query/compiler/group-by.js 2.09 kB
./packages/db/dist/esm/query/compiler/index.js 1.75 kB
./packages/db/dist/esm/query/compiler/joins.js 1.2 kB
./packages/db/dist/esm/query/compiler/order-by.js 933 B
./packages/db/dist/esm/query/compiler/select.js 657 B
./packages/db/dist/esm/query/ir.js 318 B
./packages/db/dist/esm/query/optimizer.js 2.24 kB
./packages/db/dist/esm/SortedMap.js 1.24 kB
./packages/db/dist/esm/transactions.js 2.29 kB
./packages/db/dist/esm/utils.js 419 B

compressed-size-action::db-package-size

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Jul 16, 2025

Size Change: 0 B

Total Size: 1.05 kB

ℹ️ View Unchanged
Filename Size
./packages/react-db/dist/esm/index.js 152 B
./packages/react-db/dist/esm/useLiveQuery.js 902 B

compressed-size-action::react-db-package-size

@KyleAMathews KyleAMathews requested a review from samwillis July 16, 2025 17:04
…markReady() methods

- Add isReady() method to collections returning boolean readiness state
- Add markReady() method to sync configurations for explicit readiness signaling
- Update all sync implementations (Electric, Query, Local-only, Local-storage, Live query) to call markReady()
- Fix test utilities to properly call markReady() after initial sync
- Enable direct loading → ready state transitions without requiring commits
- Replace commit-based readiness detection with explicit markReady() calls

Fixes #266

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Copy link
Copy Markdown
Collaborator

@samwillis samwillis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@KyleAMathews KyleAMathews merged commit 20f810e into main Jul 16, 2025
5 checks passed
@KyleAMathews KyleAMathews deleted the mark-is-ready branch July 16, 2025 17:32
@github-actions github-actions bot mentioned this pull request Jul 16, 2025
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.

Collections are ready when sync interface marks it ready

2 participants