diff --git a/.changeset/brave-foxes-dance.md b/.changeset/brave-foxes-dance.md deleted file mode 100644 index 8fade0d987..0000000000 --- a/.changeset/brave-foxes-dance.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -'@tanstack/offline-transactions': patch ---- - -Fix race condition that caused double replay of offline transactions on page load. The issue occurred when WebLocksLeader's async lock acquisition triggered the leadership callback after requestLeadership() had already returned, causing loadAndReplayTransactions() to be called twice. diff --git a/.changeset/export-extract-context.md b/.changeset/export-extract-context.md deleted file mode 100644 index 7557afe1db..0000000000 --- a/.changeset/export-extract-context.md +++ /dev/null @@ -1,18 +0,0 @@ ---- -'@tanstack/db': patch ---- - -Export `QueryResult` helper type for easily extracting query result types (similar to Zod's `z.infer`). - -```typescript -import { Query, QueryResult } from '@tanstack/db' - -const myQuery = new Query() - .from({ users }) - .select(({ users }) => ({ name: users.name })) - -// Extract the result type - clean and simple! -type MyQueryResult = QueryResult -``` - -Also exports `ExtractContext` for advanced use cases where you need the full context type. diff --git a/.changeset/fix-invalid-where-expression.md b/.changeset/fix-invalid-where-expression.md deleted file mode 100644 index 5ae372f7de..0000000000 --- a/.changeset/fix-invalid-where-expression.md +++ /dev/null @@ -1,14 +0,0 @@ ---- -'@tanstack/db': patch ---- - -Add validation for where() and having() expressions to catch JavaScript operator usage - -When users accidentally use JavaScript's comparison operators (`===`, `!==`, `<`, `>`, etc.) in `where()` or `having()` callbacks instead of query builder functions (`eq`, `gt`, etc.), the query builder now throws a helpful `InvalidWhereExpressionError` with clear guidance. - -Previously, this mistake would result in a confusing "Unknown expression type: undefined" error at query compilation time. Now users get immediate feedback with an example of the correct syntax: - -``` -❌ .where(({ user }) => user.id === 'abc') -✅ .where(({ user }) => eq(user.id, 'abc')) -``` diff --git a/.changeset/fix-progressive-must-refetch.md b/.changeset/fix-progressive-must-refetch.md deleted file mode 100644 index 1c279ff69d..0000000000 --- a/.changeset/fix-progressive-must-refetch.md +++ /dev/null @@ -1,9 +0,0 @@ ---- -'@tanstack/electric-db-collection': patch ---- - -Fix orphan transactions after `must-refetch` in progressive sync mode - -When a `must-refetch` message was received in progressive mode, it started a transaction with `truncate()` but reset `hasReceivedUpToDate`, causing subsequent messages to be buffered instead of written to the existing transaction. On `up-to-date`, the atomic swap code would create a new transaction, leaving the first one uncommitted forever. This caused collections to become corrupted with undefined values. - -The fix ensures that when a transaction is already started (e.g., from must-refetch), messages are written directly to it instead of being buffered for atomic swap. diff --git a/.changeset/quick-tables-glow.md b/.changeset/quick-tables-glow.md deleted file mode 100644 index d7174503c6..0000000000 --- a/.changeset/quick-tables-glow.md +++ /dev/null @@ -1,7 +0,0 @@ ---- -'@tanstack/electric-db-collection': patch ---- - -Fix duplicate key error when overlapping subset queries return the same row with different values. - -When multiple subset queries return the same row (e.g., different WHERE clauses that both match the same record), the server sends `insert` operations for each response. If the row's data changed between requests (e.g., timestamp field updated), this caused a `DuplicateKeySyncError`. The adapter now tracks synced keys and converts subsequent inserts to updates. diff --git a/.changeset/some-wombats-rest.md b/.changeset/some-wombats-rest.md deleted file mode 100644 index bccc489d4e..0000000000 --- a/.changeset/some-wombats-rest.md +++ /dev/null @@ -1,39 +0,0 @@ ---- -'@tanstack/powersync-db-collection': patch ---- - -Added support for tracking collection operation metadata in PowerSync CrudEntry operations. - -```typescript -// Schema config -const APP_SCHEMA = new Schema({ - documents: new Table( - { - name: column.text, - author: column.text, - created_at: column.text, - }, - { - // Metadata tracking must be enabled on the PowerSync table - trackMetadata: true, - }, - ), -}) - -// ... Other config - -// Collection operations which specify metadata -await collection.insert( - { - id, - name: `document`, - author: `Foo`, - }, - // The string version of this will be present in PowerSync `CrudEntry`s during uploads - { - metadata: { - extraInfo: 'Info', - }, - }, -) -``` diff --git a/.changeset/suspense-live-query-undefined-support.md b/.changeset/suspense-live-query-undefined-support.md deleted file mode 100644 index c7b571658f..0000000000 --- a/.changeset/suspense-live-query-undefined-support.md +++ /dev/null @@ -1,57 +0,0 @@ ---- -'@tanstack/react-db': patch ---- - -Improve runtime error message and documentation when `useLiveSuspenseQuery` receives `undefined` from query callback. - -Following TanStack Query's `useSuspenseQuery` design, `useLiveSuspenseQuery` intentionally does not support disabled queries (when callback returns `undefined` or `null`). This maintains the type guarantee that `data` is always `T` (not `T | undefined`), which is a core benefit of using Suspense. - -**What changed:** - -1. **Improved runtime error message** with clear guidance: - -``` -useLiveSuspenseQuery does not support disabled queries (callback returned undefined/null). -The Suspense pattern requires data to always be defined (T, not T | undefined). -Solutions: -1) Use conditional rendering - don't render the component until the condition is met. -2) Use useLiveQuery instead, which supports disabled queries with the 'isEnabled' flag. -``` - -2. **Enhanced JSDoc documentation** with detailed `@remarks` section explaining the design decision, showing both incorrect (❌) and correct (✅) patterns - -**Why this matters:** - -```typescript -// ❌ This pattern doesn't work with Suspense queries: -const { data } = useLiveSuspenseQuery( - (q) => userId - ? q.from({ users }).where(({ users }) => eq(users.id, userId)).findOne() - : undefined, - [userId] -) - -// ✅ Instead, use conditional rendering: -function UserProfile({ userId }: { userId: string }) { - const { data } = useLiveSuspenseQuery( - (q) => q.from({ users }).where(({ users }) => eq(users.id, userId)).findOne(), - [userId] - ) - return
{data.name}
// data is guaranteed non-undefined -} - -function App({ userId }: { userId?: string }) { - if (!userId) return
No user selected
- return -} - -// ✅ Or use useLiveQuery for conditional queries: -const { data, isEnabled } = useLiveQuery( - (q) => userId - ? q.from({ users }).where(({ users }) => eq(users.id, userId)).findOne() - : undefined, - [userId] -) -``` - -This aligns with TanStack Query's philosophy where Suspense queries prioritize type safety and proper component composition over flexibility. diff --git a/.changeset/svelte-findone-support.md b/.changeset/svelte-findone-support.md deleted file mode 100644 index 0dffe35c65..0000000000 --- a/.changeset/svelte-findone-support.md +++ /dev/null @@ -1,26 +0,0 @@ ---- -'@tanstack/svelte-db': patch ---- - -Add `findOne()` / `SingleResult` support to `useLiveQuery` hook. - -When using `.findOne()` in a query, the `data` property is now correctly typed as `T | undefined` instead of `Array`, matching the React implementation. - -**Example:** - -```ts -const query = useLiveQuery((q) => - q - .from({ users: usersCollection }) - .where(({ users }) => eq(users.id, userId)) - .findOne(), -) - -// query.data is now typed as User | undefined (not User[]) -``` - -This works with all query patterns: - -- Query functions: `useLiveQuery((q) => q.from(...).findOne())` -- Config objects: `useLiveQuery({ query: (q) => q.from(...).findOne() })` -- Pre-created collections with `SingleResult` diff --git a/.changeset/swift-pens-glow.md b/.changeset/swift-pens-glow.md deleted file mode 100644 index a01f11432d..0000000000 --- a/.changeset/swift-pens-glow.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -'@tanstack/db': patch ---- - -Fix asymmetric behavior in `deepEquals` when comparing different special types (Date, RegExp, Map, Set, TypedArray, Temporal, Array). Previously, comparing values like `deepEquals(Date, Temporal.Duration)` could return a different result than `deepEquals(Temporal.Duration, Date)`. Now both directions correctly return `false` for mismatched types, ensuring `deepEquals` is a proper equivalence relation. diff --git a/.changeset/sync-on-demand-collection-fix.md b/.changeset/sync-on-demand-collection-fix.md deleted file mode 100644 index 1d1fafd1d6..0000000000 --- a/.changeset/sync-on-demand-collection-fix.md +++ /dev/null @@ -1,7 +0,0 @@ ---- -'@tanstack/query-db-collection': patch ---- - -Fix on-demand sync behavior so the full TanStack Query lifecycle is respected. - -This patch resolves an issue where using on-demand synchronization could break the query lifecycle, including the error reported in https://github.com/TanStack/db/issues/998. diff --git a/.changeset/where-callback-subscribe-changes.md b/.changeset/where-callback-subscribe-changes.md deleted file mode 100644 index 687d36e33d..0000000000 --- a/.changeset/where-callback-subscribe-changes.md +++ /dev/null @@ -1,23 +0,0 @@ ---- -'@tanstack/db': patch ---- - -Add `where` callback option to `subscribeChanges` for ergonomic filtering - -Instead of manually constructing IR with `PropRef`: - -```ts -import { eq, PropRef } from '@tanstack/db' -collection.subscribeChanges(callback, { - whereExpression: eq(new PropRef(['status']), 'active'), -}) -``` - -You can now use a callback with query builder functions: - -```ts -import { eq } from '@tanstack/db' -collection.subscribeChanges(callback, { - where: (row) => eq(row.status, 'active'), -}) -``` diff --git a/examples/angular/todos/package.json b/examples/angular/todos/package.json index f306cccba5..2375b8b171 100644 --- a/examples/angular/todos/package.json +++ b/examples/angular/todos/package.json @@ -28,8 +28,8 @@ "@angular/forms": "^20.3.15", "@angular/platform-browser": "^19.2.17", "@angular/router": "^20.3.15", - "@tanstack/angular-db": "^0.1.42", - "@tanstack/db": "^0.5.16", + "@tanstack/angular-db": "^0.1.43", + "@tanstack/db": "^0.5.17", "rxjs": "^7.8.2", "tslib": "^2.8.1", "zone.js": "^0.16.0" diff --git a/examples/react/offline-transactions/package.json b/examples/react/offline-transactions/package.json index ae0429bf44..d66639aac3 100644 --- a/examples/react/offline-transactions/package.json +++ b/examples/react/offline-transactions/package.json @@ -9,9 +9,9 @@ "start": "node .output/server/index.mjs" }, "dependencies": { - "@tanstack/offline-transactions": "^1.0.6", - "@tanstack/query-db-collection": "^1.0.12", - "@tanstack/react-db": "^0.1.60", + "@tanstack/offline-transactions": "^1.0.7", + "@tanstack/query-db-collection": "^1.0.13", + "@tanstack/react-db": "^0.1.61", "@tanstack/react-query": "^5.90.16", "@tanstack/react-router": "^1.144.0", "@tanstack/react-router-devtools": "^1.144.0", diff --git a/examples/react/paced-mutations-demo/package.json b/examples/react/paced-mutations-demo/package.json index 55ab7fa0ae..fbbe9f667c 100644 --- a/examples/react/paced-mutations-demo/package.json +++ b/examples/react/paced-mutations-demo/package.json @@ -9,8 +9,8 @@ "preview": "vite preview" }, "dependencies": { - "@tanstack/db": "^0.5.16", - "@tanstack/react-db": "^0.1.60", + "@tanstack/db": "^0.5.17", + "@tanstack/react-db": "^0.1.61", "mitt": "^3.0.1", "react": "^19.2.3", "react-dom": "^19.2.3" diff --git a/examples/react/projects/package.json b/examples/react/projects/package.json index 6e5dd1fdbe..5b8a4ae000 100644 --- a/examples/react/projects/package.json +++ b/examples/react/projects/package.json @@ -17,8 +17,8 @@ "dependencies": { "@tailwindcss/vite": "^4.1.18", "@tanstack/query-core": "^5.90.16", - "@tanstack/query-db-collection": "^1.0.12", - "@tanstack/react-db": "^0.1.60", + "@tanstack/query-db-collection": "^1.0.13", + "@tanstack/react-db": "^0.1.61", "@tanstack/react-router": "^1.144.0", "@tanstack/react-router-devtools": "^1.144.0", "@tanstack/react-router-with-query": "^1.130.17", diff --git a/examples/react/todo/package.json b/examples/react/todo/package.json index fb2a5b2cef..c765f073bf 100644 --- a/examples/react/todo/package.json +++ b/examples/react/todo/package.json @@ -3,13 +3,13 @@ "private": true, "version": "0.1.24", "dependencies": { - "@tanstack/electric-db-collection": "^0.2.20", + "@tanstack/electric-db-collection": "^0.2.21", "@tanstack/query-core": "^5.90.16", - "@tanstack/query-db-collection": "^1.0.12", - "@tanstack/react-db": "^0.1.60", + "@tanstack/query-db-collection": "^1.0.13", + "@tanstack/react-db": "^0.1.61", "@tanstack/react-router": "^1.144.0", "@tanstack/react-start": "^1.145.5", - "@tanstack/trailbase-db-collection": "^0.1.60", + "@tanstack/trailbase-db-collection": "^0.1.61", "cors": "^2.8.5", "drizzle-orm": "^0.45.1", "drizzle-zod": "^0.8.3", diff --git a/examples/solid/todo/package.json b/examples/solid/todo/package.json index e2e7f5cf6c..0e18f2420f 100644 --- a/examples/solid/todo/package.json +++ b/examples/solid/todo/package.json @@ -3,13 +3,13 @@ "private": true, "version": "0.0.33", "dependencies": { - "@tanstack/electric-db-collection": "^0.2.20", + "@tanstack/electric-db-collection": "^0.2.21", "@tanstack/query-core": "^5.90.16", - "@tanstack/query-db-collection": "^1.0.12", - "@tanstack/solid-db": "^0.1.59", + "@tanstack/query-db-collection": "^1.0.13", + "@tanstack/solid-db": "^0.1.60", "@tanstack/solid-router": "^1.144.0", "@tanstack/solid-start": "^1.145.5", - "@tanstack/trailbase-db-collection": "^0.1.60", + "@tanstack/trailbase-db-collection": "^0.1.61", "cors": "^2.8.5", "drizzle-orm": "^0.45.1", "drizzle-zod": "^0.8.3", diff --git a/packages/angular-db/CHANGELOG.md b/packages/angular-db/CHANGELOG.md index 1b58dfa91d..c28de70ea2 100644 --- a/packages/angular-db/CHANGELOG.md +++ b/packages/angular-db/CHANGELOG.md @@ -1,5 +1,12 @@ # @tanstack/angular-db +## 0.1.43 + +### Patch Changes + +- Updated dependencies [[`f795a67`](https://github.com/TanStack/db/commit/f795a674f21659ef46ff370d4f3b9903a596bcaf), [`d542667`](https://github.com/TanStack/db/commit/d542667a3440415d8e6cbb449b20abd3cbd6855c), [`6503c09`](https://github.com/TanStack/db/commit/6503c091a259208331f471dca29abf086e881147), [`b1cc4a7`](https://github.com/TanStack/db/commit/b1cc4a7e018ffb6804ae7f1c99e9c6eb4bb22812)]: + - @tanstack/db@0.5.17 + ## 0.1.42 ### Patch Changes diff --git a/packages/angular-db/package.json b/packages/angular-db/package.json index 065bf08890..7202ffa03f 100644 --- a/packages/angular-db/package.json +++ b/packages/angular-db/package.json @@ -1,6 +1,6 @@ { "name": "@tanstack/angular-db", - "version": "0.1.42", + "version": "0.1.43", "description": "Angular integration for @tanstack/db", "author": "Ethan McDaniel", "license": "MIT", diff --git a/packages/db/CHANGELOG.md b/packages/db/CHANGELOG.md index 0367dde5ae..ad9180af28 100644 --- a/packages/db/CHANGELOG.md +++ b/packages/db/CHANGELOG.md @@ -1,5 +1,57 @@ # @tanstack/db +## 0.5.17 + +### Patch Changes + +- Export `QueryResult` helper type for easily extracting query result types (similar to Zod's `z.infer`). ([#1096](https://github.com/TanStack/db/pull/1096)) + + ```typescript + import { Query, QueryResult } from '@tanstack/db' + + const myQuery = new Query() + .from({ users }) + .select(({ users }) => ({ name: users.name })) + + // Extract the result type - clean and simple! + type MyQueryResult = QueryResult + ``` + + Also exports `ExtractContext` for advanced use cases where you need the full context type. + +- Add validation for where() and having() expressions to catch JavaScript operator usage ([#1082](https://github.com/TanStack/db/pull/1082)) + + When users accidentally use JavaScript's comparison operators (`===`, `!==`, `<`, `>`, etc.) in `where()` or `having()` callbacks instead of query builder functions (`eq`, `gt`, etc.), the query builder now throws a helpful `InvalidWhereExpressionError` with clear guidance. + + Previously, this mistake would result in a confusing "Unknown expression type: undefined" error at query compilation time. Now users get immediate feedback with an example of the correct syntax: + + ``` + ❌ .where(({ user }) => user.id === 'abc') + ✅ .where(({ user }) => eq(user.id, 'abc')) + ``` + +- Fix asymmetric behavior in `deepEquals` when comparing different special types (Date, RegExp, Map, Set, TypedArray, Temporal, Array). Previously, comparing values like `deepEquals(Date, Temporal.Duration)` could return a different result than `deepEquals(Temporal.Duration, Date)`. Now both directions correctly return `false` for mismatched types, ensuring `deepEquals` is a proper equivalence relation. ([#1018](https://github.com/TanStack/db/pull/1018)) + +- Add `where` callback option to `subscribeChanges` for ergonomic filtering ([#943](https://github.com/TanStack/db/pull/943)) + + Instead of manually constructing IR with `PropRef`: + + ```ts + import { eq, PropRef } from '@tanstack/db' + collection.subscribeChanges(callback, { + whereExpression: eq(new PropRef(['status']), 'active'), + }) + ``` + + You can now use a callback with query builder functions: + + ```ts + import { eq } from '@tanstack/db' + collection.subscribeChanges(callback, { + where: (row) => eq(row.status, 'active'), + }) + ``` + ## 0.5.16 ### Patch Changes diff --git a/packages/db/package.json b/packages/db/package.json index 2e8f236d02..1e2f053366 100644 --- a/packages/db/package.json +++ b/packages/db/package.json @@ -1,6 +1,6 @@ { "name": "@tanstack/db", - "version": "0.5.16", + "version": "0.5.17", "description": "A reactive client store for building super fast apps on sync", "author": "Kyle Mathews", "license": "MIT", diff --git a/packages/electric-db-collection/CHANGELOG.md b/packages/electric-db-collection/CHANGELOG.md index 3c49043da7..c0afa30cd8 100644 --- a/packages/electric-db-collection/CHANGELOG.md +++ b/packages/electric-db-collection/CHANGELOG.md @@ -1,5 +1,22 @@ # @tanstack/electric-db-collection +## 0.2.21 + +### Patch Changes + +- Fix orphan transactions after `must-refetch` in progressive sync mode ([#1069](https://github.com/TanStack/db/pull/1069)) + + When a `must-refetch` message was received in progressive mode, it started a transaction with `truncate()` but reset `hasReceivedUpToDate`, causing subsequent messages to be buffered instead of written to the existing transaction. On `up-to-date`, the atomic swap code would create a new transaction, leaving the first one uncommitted forever. This caused collections to become corrupted with undefined values. + + The fix ensures that when a transaction is already started (e.g., from must-refetch), messages are written directly to it instead of being buffered for atomic swap. + +- Fix duplicate key error when overlapping subset queries return the same row with different values. ([#1070](https://github.com/TanStack/db/pull/1070)) + + When multiple subset queries return the same row (e.g., different WHERE clauses that both match the same record), the server sends `insert` operations for each response. If the row's data changed between requests (e.g., timestamp field updated), this caused a `DuplicateKeySyncError`. The adapter now tracks synced keys and converts subsequent inserts to updates. + +- Updated dependencies [[`f795a67`](https://github.com/TanStack/db/commit/f795a674f21659ef46ff370d4f3b9903a596bcaf), [`d542667`](https://github.com/TanStack/db/commit/d542667a3440415d8e6cbb449b20abd3cbd6855c), [`6503c09`](https://github.com/TanStack/db/commit/6503c091a259208331f471dca29abf086e881147), [`b1cc4a7`](https://github.com/TanStack/db/commit/b1cc4a7e018ffb6804ae7f1c99e9c6eb4bb22812)]: + - @tanstack/db@0.5.17 + ## 0.2.20 ### Patch Changes diff --git a/packages/electric-db-collection/package.json b/packages/electric-db-collection/package.json index f24c707ad8..ed9ba49486 100644 --- a/packages/electric-db-collection/package.json +++ b/packages/electric-db-collection/package.json @@ -1,6 +1,6 @@ { "name": "@tanstack/electric-db-collection", - "version": "0.2.20", + "version": "0.2.21", "description": "ElectricSQL collection for TanStack DB", "author": "Kyle Mathews", "license": "MIT", diff --git a/packages/offline-transactions/CHANGELOG.md b/packages/offline-transactions/CHANGELOG.md index 25da78e13c..cb646a9b2f 100644 --- a/packages/offline-transactions/CHANGELOG.md +++ b/packages/offline-transactions/CHANGELOG.md @@ -1,5 +1,14 @@ # @tanstack/offline-transactions +## 1.0.7 + +### Patch Changes + +- Fix race condition that caused double replay of offline transactions on page load. The issue occurred when WebLocksLeader's async lock acquisition triggered the leadership callback after requestLeadership() had already returned, causing loadAndReplayTransactions() to be called twice. ([#1046](https://github.com/TanStack/db/pull/1046)) + +- Updated dependencies [[`f795a67`](https://github.com/TanStack/db/commit/f795a674f21659ef46ff370d4f3b9903a596bcaf), [`d542667`](https://github.com/TanStack/db/commit/d542667a3440415d8e6cbb449b20abd3cbd6855c), [`6503c09`](https://github.com/TanStack/db/commit/6503c091a259208331f471dca29abf086e881147), [`b1cc4a7`](https://github.com/TanStack/db/commit/b1cc4a7e018ffb6804ae7f1c99e9c6eb4bb22812)]: + - @tanstack/db@0.5.17 + ## 1.0.6 ### Patch Changes diff --git a/packages/offline-transactions/package.json b/packages/offline-transactions/package.json index 75a06d723f..d44f71c22e 100644 --- a/packages/offline-transactions/package.json +++ b/packages/offline-transactions/package.json @@ -1,6 +1,6 @@ { "name": "@tanstack/offline-transactions", - "version": "1.0.6", + "version": "1.0.7", "description": "Offline-first transaction capabilities for TanStack DB", "author": "TanStack", "license": "MIT", diff --git a/packages/powersync-db-collection/CHANGELOG.md b/packages/powersync-db-collection/CHANGELOG.md index 36e571f3c5..aa8c5fc3a6 100644 --- a/packages/powersync-db-collection/CHANGELOG.md +++ b/packages/powersync-db-collection/CHANGELOG.md @@ -1,5 +1,47 @@ # @tanstack/powersync-db-collection +## 0.1.21 + +### Patch Changes + +- Added support for tracking collection operation metadata in PowerSync CrudEntry operations. ([#999](https://github.com/TanStack/db/pull/999)) + + ```typescript + // Schema config + const APP_SCHEMA = new Schema({ + documents: new Table( + { + name: column.text, + + created_at: column.text, + }, + { + // Metadata tracking must be enabled on the PowerSync table + trackMetadata: true, + }, + ), + }) + + // ... Other config + + // Collection operations which specify metadata + await collection.insert( + { + id, + name: `document`, + }, + // The string version of this will be present in PowerSync `CrudEntry`s during uploads + { + metadata: { + extraInfo: 'Info', + }, + }, + ) + ``` + +- Updated dependencies [[`f795a67`](https://github.com/TanStack/db/commit/f795a674f21659ef46ff370d4f3b9903a596bcaf), [`d542667`](https://github.com/TanStack/db/commit/d542667a3440415d8e6cbb449b20abd3cbd6855c), [`6503c09`](https://github.com/TanStack/db/commit/6503c091a259208331f471dca29abf086e881147), [`b1cc4a7`](https://github.com/TanStack/db/commit/b1cc4a7e018ffb6804ae7f1c99e9c6eb4bb22812)]: + - @tanstack/db@0.5.17 + ## 0.1.20 ### Patch Changes diff --git a/packages/powersync-db-collection/package.json b/packages/powersync-db-collection/package.json index 075fb70f90..390dee71f9 100644 --- a/packages/powersync-db-collection/package.json +++ b/packages/powersync-db-collection/package.json @@ -1,6 +1,6 @@ { "name": "@tanstack/powersync-db-collection", - "version": "0.1.20", + "version": "0.1.21", "description": "PowerSync collection for TanStack DB", "author": "POWERSYNC", "license": "MIT", diff --git a/packages/query-db-collection/CHANGELOG.md b/packages/query-db-collection/CHANGELOG.md index 1cad14a67b..69d754b600 100644 --- a/packages/query-db-collection/CHANGELOG.md +++ b/packages/query-db-collection/CHANGELOG.md @@ -1,5 +1,16 @@ # @tanstack/query-db-collection +## 1.0.13 + +### Patch Changes + +- Fix on-demand sync behavior so the full TanStack Query lifecycle is respected. ([#1007](https://github.com/TanStack/db/pull/1007)) + + This patch resolves an issue where using on-demand synchronization could break the query lifecycle, including the error reported in https://github.com/TanStack/db/issues/998. + +- Updated dependencies [[`f795a67`](https://github.com/TanStack/db/commit/f795a674f21659ef46ff370d4f3b9903a596bcaf), [`d542667`](https://github.com/TanStack/db/commit/d542667a3440415d8e6cbb449b20abd3cbd6855c), [`6503c09`](https://github.com/TanStack/db/commit/6503c091a259208331f471dca29abf086e881147), [`b1cc4a7`](https://github.com/TanStack/db/commit/b1cc4a7e018ffb6804ae7f1c99e9c6eb4bb22812)]: + - @tanstack/db@0.5.17 + ## 1.0.12 ### Patch Changes diff --git a/packages/query-db-collection/package.json b/packages/query-db-collection/package.json index 1548167e64..671f83e085 100644 --- a/packages/query-db-collection/package.json +++ b/packages/query-db-collection/package.json @@ -1,6 +1,6 @@ { "name": "@tanstack/query-db-collection", - "version": "1.0.12", + "version": "1.0.13", "description": "TanStack Query collection for TanStack DB", "author": "Kyle Mathews", "license": "MIT", diff --git a/packages/react-db/CHANGELOG.md b/packages/react-db/CHANGELOG.md index d0f30b8211..3353ac3aca 100644 --- a/packages/react-db/CHANGELOG.md +++ b/packages/react-db/CHANGELOG.md @@ -1,5 +1,65 @@ # @tanstack/react-db +## 0.1.61 + +### Patch Changes + +- Improve runtime error message and documentation when `useLiveSuspenseQuery` receives `undefined` from query callback. ([#860](https://github.com/TanStack/db/pull/860)) + + Following TanStack Query's `useSuspenseQuery` design, `useLiveSuspenseQuery` intentionally does not support disabled queries (when callback returns `undefined` or `null`). This maintains the type guarantee that `data` is always `T` (not `T | undefined`), which is a core benefit of using Suspense. + + **What changed:** + 1. **Improved runtime error message** with clear guidance: + + ``` + useLiveSuspenseQuery does not support disabled queries (callback returned undefined/null). + The Suspense pattern requires data to always be defined (T, not T | undefined). + Solutions: + 1) Use conditional rendering - don't render the component until the condition is met. + 2) Use useLiveQuery instead, which supports disabled queries with the 'isEnabled' flag. + ``` + + 2. **Enhanced JSDoc documentation** with detailed `@remarks` section explaining the design decision, showing both incorrect (❌) and correct (✅) patterns + + **Why this matters:** + + ```typescript + // ❌ This pattern doesn't work with Suspense queries: + const { data } = useLiveSuspenseQuery( + (q) => userId + ? q.from({ users }).where(({ users }) => eq(users.id, userId)).findOne() + : undefined, + [userId] + ) + + // ✅ Instead, use conditional rendering: + function UserProfile({ userId }: { userId: string }) { + const { data } = useLiveSuspenseQuery( + (q) => q.from({ users }).where(({ users }) => eq(users.id, userId)).findOne(), + [userId] + ) + return
{data.name}
// data is guaranteed non-undefined + } + + function App({ userId }: { userId?: string }) { + if (!userId) return
No user selected
+ return + } + + // ✅ Or use useLiveQuery for conditional queries: + const { data, isEnabled } = useLiveQuery( + (q) => userId + ? q.from({ users }).where(({ users }) => eq(users.id, userId)).findOne() + : undefined, + [userId] + ) + ``` + + This aligns with TanStack Query's philosophy where Suspense queries prioritize type safety and proper component composition over flexibility. + +- Updated dependencies [[`f795a67`](https://github.com/TanStack/db/commit/f795a674f21659ef46ff370d4f3b9903a596bcaf), [`d542667`](https://github.com/TanStack/db/commit/d542667a3440415d8e6cbb449b20abd3cbd6855c), [`6503c09`](https://github.com/TanStack/db/commit/6503c091a259208331f471dca29abf086e881147), [`b1cc4a7`](https://github.com/TanStack/db/commit/b1cc4a7e018ffb6804ae7f1c99e9c6eb4bb22812)]: + - @tanstack/db@0.5.17 + ## 0.1.60 ### Patch Changes diff --git a/packages/react-db/package.json b/packages/react-db/package.json index 7196a56e29..f73efa8b4d 100644 --- a/packages/react-db/package.json +++ b/packages/react-db/package.json @@ -1,6 +1,6 @@ { "name": "@tanstack/react-db", - "version": "0.1.60", + "version": "0.1.61", "description": "React integration for @tanstack/db", "author": "Kyle Mathews", "license": "MIT", diff --git a/packages/rxdb-db-collection/CHANGELOG.md b/packages/rxdb-db-collection/CHANGELOG.md index e71381eb7f..4b8407650c 100644 --- a/packages/rxdb-db-collection/CHANGELOG.md +++ b/packages/rxdb-db-collection/CHANGELOG.md @@ -1,5 +1,12 @@ # @tanstack/rxdb-db-collection +## 0.1.49 + +### Patch Changes + +- Updated dependencies [[`f795a67`](https://github.com/TanStack/db/commit/f795a674f21659ef46ff370d4f3b9903a596bcaf), [`d542667`](https://github.com/TanStack/db/commit/d542667a3440415d8e6cbb449b20abd3cbd6855c), [`6503c09`](https://github.com/TanStack/db/commit/6503c091a259208331f471dca29abf086e881147), [`b1cc4a7`](https://github.com/TanStack/db/commit/b1cc4a7e018ffb6804ae7f1c99e9c6eb4bb22812)]: + - @tanstack/db@0.5.17 + ## 0.1.48 ### Patch Changes diff --git a/packages/rxdb-db-collection/package.json b/packages/rxdb-db-collection/package.json index ece56fff82..7cf77114e4 100644 --- a/packages/rxdb-db-collection/package.json +++ b/packages/rxdb-db-collection/package.json @@ -1,6 +1,6 @@ { "name": "@tanstack/rxdb-db-collection", - "version": "0.1.48", + "version": "0.1.49", "description": "RxDB collection for TanStack DB", "author": "Kyle Mathews", "license": "MIT", diff --git a/packages/solid-db/CHANGELOG.md b/packages/solid-db/CHANGELOG.md index 67ee5bb520..1a95d76947 100644 --- a/packages/solid-db/CHANGELOG.md +++ b/packages/solid-db/CHANGELOG.md @@ -1,5 +1,12 @@ # @tanstack/react-db +## 0.1.60 + +### Patch Changes + +- Updated dependencies [[`f795a67`](https://github.com/TanStack/db/commit/f795a674f21659ef46ff370d4f3b9903a596bcaf), [`d542667`](https://github.com/TanStack/db/commit/d542667a3440415d8e6cbb449b20abd3cbd6855c), [`6503c09`](https://github.com/TanStack/db/commit/6503c091a259208331f471dca29abf086e881147), [`b1cc4a7`](https://github.com/TanStack/db/commit/b1cc4a7e018ffb6804ae7f1c99e9c6eb4bb22812)]: + - @tanstack/db@0.5.17 + ## 0.1.59 ### Patch Changes diff --git a/packages/solid-db/package.json b/packages/solid-db/package.json index be3dede4c3..d15692b8d6 100644 --- a/packages/solid-db/package.json +++ b/packages/solid-db/package.json @@ -1,6 +1,6 @@ { "name": "@tanstack/solid-db", - "version": "0.1.59", + "version": "0.1.60", "description": "Solid integration for @tanstack/db", "author": "Kyle Mathews", "license": "MIT", diff --git a/packages/svelte-db/CHANGELOG.md b/packages/svelte-db/CHANGELOG.md index f1dd6440b1..f8971ae85a 100644 --- a/packages/svelte-db/CHANGELOG.md +++ b/packages/svelte-db/CHANGELOG.md @@ -1,5 +1,34 @@ # @tanstack/svelte-db +## 0.1.60 + +### Patch Changes + +- Add `findOne()` / `SingleResult` support to `useLiveQuery` hook. ([#1001](https://github.com/TanStack/db/pull/1001)) + + When using `.findOne()` in a query, the `data` property is now correctly typed as `T | undefined` instead of `Array`, matching the React implementation. + + **Example:** + + ```ts + const query = useLiveQuery((q) => + q + .from({ users: usersCollection }) + .where(({ users }) => eq(users.id, userId)) + .findOne(), + ) + + // query.data is now typed as User | undefined (not User[]) + ``` + + This works with all query patterns: + - Query functions: `useLiveQuery((q) => q.from(...).findOne())` + - Config objects: `useLiveQuery({ query: (q) => q.from(...).findOne() })` + - Pre-created collections with `SingleResult` + +- Updated dependencies [[`f795a67`](https://github.com/TanStack/db/commit/f795a674f21659ef46ff370d4f3b9903a596bcaf), [`d542667`](https://github.com/TanStack/db/commit/d542667a3440415d8e6cbb449b20abd3cbd6855c), [`6503c09`](https://github.com/TanStack/db/commit/6503c091a259208331f471dca29abf086e881147), [`b1cc4a7`](https://github.com/TanStack/db/commit/b1cc4a7e018ffb6804ae7f1c99e9c6eb4bb22812)]: + - @tanstack/db@0.5.17 + ## 0.1.59 ### Patch Changes diff --git a/packages/svelte-db/package.json b/packages/svelte-db/package.json index 4d2292323c..b4a1a15eda 100644 --- a/packages/svelte-db/package.json +++ b/packages/svelte-db/package.json @@ -1,6 +1,6 @@ { "name": "@tanstack/svelte-db", - "version": "0.1.59", + "version": "0.1.60", "description": "Svelte integration for @tanstack/db", "author": "Kyle Mathews", "license": "MIT", diff --git a/packages/trailbase-db-collection/CHANGELOG.md b/packages/trailbase-db-collection/CHANGELOG.md index b83c8a82e4..f23af0748f 100644 --- a/packages/trailbase-db-collection/CHANGELOG.md +++ b/packages/trailbase-db-collection/CHANGELOG.md @@ -1,5 +1,12 @@ # @tanstack/trailbase-db-collection +## 0.1.61 + +### Patch Changes + +- Updated dependencies [[`f795a67`](https://github.com/TanStack/db/commit/f795a674f21659ef46ff370d4f3b9903a596bcaf), [`d542667`](https://github.com/TanStack/db/commit/d542667a3440415d8e6cbb449b20abd3cbd6855c), [`6503c09`](https://github.com/TanStack/db/commit/6503c091a259208331f471dca29abf086e881147), [`b1cc4a7`](https://github.com/TanStack/db/commit/b1cc4a7e018ffb6804ae7f1c99e9c6eb4bb22812)]: + - @tanstack/db@0.5.17 + ## 0.1.60 ### Patch Changes diff --git a/packages/trailbase-db-collection/package.json b/packages/trailbase-db-collection/package.json index 4a46b14f04..f1837cfd7d 100644 --- a/packages/trailbase-db-collection/package.json +++ b/packages/trailbase-db-collection/package.json @@ -1,6 +1,6 @@ { "name": "@tanstack/trailbase-db-collection", - "version": "0.1.60", + "version": "0.1.61", "description": "TrailBase collection for TanStack DB", "author": "Sebastian Jeltsch", "license": "MIT", diff --git a/packages/vue-db/CHANGELOG.md b/packages/vue-db/CHANGELOG.md index d3148e27e4..b6059ad47f 100644 --- a/packages/vue-db/CHANGELOG.md +++ b/packages/vue-db/CHANGELOG.md @@ -1,5 +1,12 @@ # @tanstack/vue-db +## 0.0.93 + +### Patch Changes + +- Updated dependencies [[`f795a67`](https://github.com/TanStack/db/commit/f795a674f21659ef46ff370d4f3b9903a596bcaf), [`d542667`](https://github.com/TanStack/db/commit/d542667a3440415d8e6cbb449b20abd3cbd6855c), [`6503c09`](https://github.com/TanStack/db/commit/6503c091a259208331f471dca29abf086e881147), [`b1cc4a7`](https://github.com/TanStack/db/commit/b1cc4a7e018ffb6804ae7f1c99e9c6eb4bb22812)]: + - @tanstack/db@0.5.17 + ## 0.0.92 ### Patch Changes diff --git a/packages/vue-db/package.json b/packages/vue-db/package.json index 548cfb14bc..d942ae4061 100644 --- a/packages/vue-db/package.json +++ b/packages/vue-db/package.json @@ -1,6 +1,6 @@ { "name": "@tanstack/vue-db", - "version": "0.0.92", + "version": "0.0.93", "description": "Vue integration for @tanstack/db", "author": "Kyle Mathews", "license": "MIT", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ab688aee26..6f9ab0730e 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -132,10 +132,10 @@ importers: specifier: ^20.3.15 version: 20.3.15(@angular/common@19.2.17(@angular/core@19.2.17(rxjs@7.8.2)(zone.js@0.16.0))(rxjs@7.8.2))(@angular/core@19.2.17(rxjs@7.8.2)(zone.js@0.16.0))(@angular/platform-browser@19.2.17(@angular/common@19.2.17(@angular/core@19.2.17(rxjs@7.8.2)(zone.js@0.16.0))(rxjs@7.8.2))(@angular/core@19.2.17(rxjs@7.8.2)(zone.js@0.16.0)))(rxjs@7.8.2) '@tanstack/angular-db': - specifier: ^0.1.42 + specifier: ^0.1.43 version: link:../../../packages/angular-db '@tanstack/db': - specifier: ^0.5.16 + specifier: ^0.5.17 version: link:../../../packages/db rxjs: specifier: ^7.8.2 @@ -193,13 +193,13 @@ importers: examples/react/offline-transactions: dependencies: '@tanstack/offline-transactions': - specifier: ^1.0.6 + specifier: ^1.0.7 version: link:../../../packages/offline-transactions '@tanstack/query-db-collection': - specifier: ^1.0.12 + specifier: ^1.0.13 version: link:../../../packages/query-db-collection '@tanstack/react-db': - specifier: ^0.1.60 + specifier: ^0.1.61 version: link:../../../packages/react-db '@tanstack/react-query': specifier: ^5.90.16 @@ -260,10 +260,10 @@ importers: examples/react/paced-mutations-demo: dependencies: '@tanstack/db': - specifier: ^0.5.16 + specifier: ^0.5.17 version: link:../../../packages/db '@tanstack/react-db': - specifier: ^0.1.60 + specifier: ^0.1.61 version: link:../../../packages/react-db mitt: specifier: ^3.0.1 @@ -300,10 +300,10 @@ importers: specifier: ^5.90.16 version: 5.90.16 '@tanstack/query-db-collection': - specifier: ^1.0.12 + specifier: ^1.0.13 version: link:../../../packages/query-db-collection '@tanstack/react-db': - specifier: ^0.1.60 + specifier: ^0.1.61 version: link:../../../packages/react-db '@tanstack/react-router': specifier: ^1.144.0 @@ -433,16 +433,16 @@ importers: examples/react/todo: dependencies: '@tanstack/electric-db-collection': - specifier: ^0.2.20 + specifier: ^0.2.21 version: link:../../../packages/electric-db-collection '@tanstack/query-core': specifier: ^5.90.16 version: 5.90.16 '@tanstack/query-db-collection': - specifier: ^1.0.12 + specifier: ^1.0.13 version: link:../../../packages/query-db-collection '@tanstack/react-db': - specifier: ^0.1.60 + specifier: ^0.1.61 version: link:../../../packages/react-db '@tanstack/react-router': specifier: ^1.144.0 @@ -451,7 +451,7 @@ importers: specifier: ^1.145.5 version: 1.145.5(react-dom@19.2.3(react@19.2.3))(react@19.2.3)(vite-plugin-solid@2.11.10(@testing-library/jest-dom@6.9.1)(solid-js@1.9.10)(vite@7.3.0(@types/node@24.7.0)(jiti@2.6.1)(lightningcss@1.30.2)(sass@1.90.0)(terser@5.44.0)(tsx@4.21.0)(yaml@2.8.1)))(vite@7.3.0(@types/node@24.7.0)(jiti@2.6.1)(lightningcss@1.30.2)(sass@1.90.0)(terser@5.44.0)(tsx@4.21.0)(yaml@2.8.1)) '@tanstack/trailbase-db-collection': - specifier: ^0.1.60 + specifier: ^0.1.61 version: link:../../../packages/trailbase-db-collection cors: specifier: ^2.8.5 @@ -554,16 +554,16 @@ importers: examples/solid/todo: dependencies: '@tanstack/electric-db-collection': - specifier: ^0.2.20 + specifier: ^0.2.21 version: link:../../../packages/electric-db-collection '@tanstack/query-core': specifier: ^5.90.16 version: 5.90.16 '@tanstack/query-db-collection': - specifier: ^1.0.12 + specifier: ^1.0.13 version: link:../../../packages/query-db-collection '@tanstack/solid-db': - specifier: ^0.1.59 + specifier: ^0.1.60 version: link:../../../packages/solid-db '@tanstack/solid-router': specifier: ^1.144.0 @@ -572,7 +572,7 @@ importers: specifier: ^1.145.5 version: 1.145.5(@tanstack/react-router@1.144.0(react-dom@19.2.3(react@19.2.3))(react@19.2.3))(solid-js@1.9.10)(vite-plugin-solid@2.11.10(@testing-library/jest-dom@6.9.1)(solid-js@1.9.10)(vite@7.3.0(@types/node@24.7.0)(jiti@2.6.1)(lightningcss@1.30.2)(sass@1.90.0)(terser@5.44.0)(tsx@4.21.0)(yaml@2.8.1)))(vite@7.3.0(@types/node@24.7.0)(jiti@2.6.1)(lightningcss@1.30.2)(sass@1.90.0)(terser@5.44.0)(tsx@4.21.0)(yaml@2.8.1)) '@tanstack/trailbase-db-collection': - specifier: ^0.1.60 + specifier: ^0.1.61 version: link:../../../packages/trailbase-db-collection cors: specifier: ^2.8.5