diff --git a/.changeset/fix-progressive-must-refetch.md b/.changeset/fix-progressive-must-refetch.md deleted file mode 100644 index 1c279ff69..000000000 --- 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 d7174503c..000000000 --- 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/examples/react/todo/package.json b/examples/react/todo/package.json index 82bbb4f33..2e457ed02 100644 --- a/examples/react/todo/package.json +++ b/examples/react/todo/package.json @@ -3,7 +3,7 @@ "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.15", "@tanstack/query-db-collection": "^1.0.12", "@tanstack/react-db": "^0.1.60", diff --git a/examples/solid/todo/package.json b/examples/solid/todo/package.json index 87589dab2..e434ad406 100644 --- a/examples/solid/todo/package.json +++ b/examples/solid/todo/package.json @@ -3,7 +3,7 @@ "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.15", "@tanstack/query-db-collection": "^1.0.12", "@tanstack/solid-db": "^0.1.59", diff --git a/packages/electric-db-collection/CHANGELOG.md b/packages/electric-db-collection/CHANGELOG.md index 3c49043da..a6a0376ab 100644 --- a/packages/electric-db-collection/CHANGELOG.md +++ b/packages/electric-db-collection/CHANGELOG.md @@ -1,5 +1,19 @@ # @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. + ## 0.2.20 ### Patch Changes diff --git a/packages/electric-db-collection/package.json b/packages/electric-db-collection/package.json index f24c707ad..ed9ba4948 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/pnpm-lock.yaml b/pnpm-lock.yaml index 8f8a15bfc..d4de0a635 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -427,7 +427,7 @@ 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.15 @@ -548,7 +548,7 @@ 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.15 @@ -747,8 +747,6 @@ importers: specifier: ^3.2.4 version: 3.2.4(@types/debug@4.1.12)(@types/node@24.7.0)(@vitest/ui@3.2.4)(jiti@2.6.1)(jsdom@27.4.0)(lightningcss@1.30.2)(sass@1.90.0)(terser@5.44.0)(tsx@4.21.0)(yaml@2.8.1) - packages/db-collections: {} - packages/db-ivm: dependencies: fractional-indexing: