Skip to content

Conversation

@ibarakaiev
Copy link
Contributor

When a must-refetch message is received in progressive mode, it starts a transaction with begin() and calls truncate(). This resets hasReceivedUpToDate to false, causing isBufferingInitialSync() to return true.

The bug: subsequent messages after must-refetch were being buffered instead of written to the existing transaction. When up-to-date was received, the atomic swap code would create a NEW transaction, leaving the first transaction (from must-refetch) uncommitted forever. This "orphan transaction" caused the collection to become corrupted with undefined values.

The fix: Add && !transactionStarted checks to 5 places so that when a transaction is already started (from must-refetch), messages are written directly to it instead of being buffered for atomic swap.

🤖 Generated with Claude Code

🚀 Release Impact

  • This change affects published code, and I have generated a changeset.
  • This change is docs/CI/dev-only (no release).

@changeset-bot
Copy link

changeset-bot bot commented Dec 23, 2025

🦋 Changeset detected

Latest commit: 3d4c962

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

This PR includes changesets to release 1 package
Name Type
@tanstack/electric-db-collection 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

pkg-pr-new bot commented Dec 23, 2025

More templates

@tanstack/angular-db

npm i https://pkg.pr.new/@tanstack/angular-db@1069

@tanstack/db

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

@tanstack/db-ivm

npm i https://pkg.pr.new/@tanstack/db-ivm@1069

@tanstack/electric-db-collection

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

@tanstack/offline-transactions

npm i https://pkg.pr.new/@tanstack/offline-transactions@1069

@tanstack/powersync-db-collection

npm i https://pkg.pr.new/@tanstack/powersync-db-collection@1069

@tanstack/query-db-collection

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

@tanstack/react-db

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

@tanstack/rxdb-db-collection

npm i https://pkg.pr.new/@tanstack/rxdb-db-collection@1069

@tanstack/solid-db

npm i https://pkg.pr.new/@tanstack/solid-db@1069

@tanstack/svelte-db

npm i https://pkg.pr.new/@tanstack/svelte-db@1069

@tanstack/trailbase-db-collection

npm i https://pkg.pr.new/@tanstack/trailbase-db-collection@1069

@tanstack/vue-db

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

commit: 3d4c962

…efetch in progressive mode

When a `must-refetch` message is received in progressive mode, it starts a
transaction with `begin()` and calls `truncate()`. This resets `hasReceivedUpToDate`
to `false`, causing `isBufferingInitialSync()` to return `true`.

The bug: subsequent messages after must-refetch were being buffered instead of
written to the existing transaction. When `up-to-date` was received, the atomic
swap code would create a NEW transaction, leaving the first transaction (from
must-refetch) uncommitted forever. This "orphan transaction" caused the collection
to become corrupted with undefined values.

The fix: Add `&& !transactionStarted` checks to 5 places so that when a transaction
is already started (from must-refetch), messages are written directly to it instead
of being buffered for atomic swap.

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@ibarakaiev ibarakaiev force-pushed the fix/progressive-mode-must-refetch-orphan-transaction branch 2 times, most recently from b1b9572 to 3d4c962 Compare December 23, 2025 22:32
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.

1 participant