Skip to content

fix(db-sqlite-persistence-core): rows marked with metadata prior to insert get reset causing stale data#1619

Open
tombryden wants to merge 2 commits into
TanStack:mainfrom
tombryden:main
Open

fix(db-sqlite-persistence-core): rows marked with metadata prior to insert get reset causing stale data#1619
tombryden wants to merge 2 commits into
TanStack:mainfrom
tombryden:main

Conversation

@tombryden

@tombryden tombryden commented Jun 25, 2026

Copy link
Copy Markdown

🎯 Changes

Fixes #1618 - rows in the same transaction marked with metadata get their metadata reset on insert, causing bugs like stale data when used with queryCollectionOptions

✅ Checklist

  • I have tested this code locally with pnpm test.

🚀 Release Impact

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

Summary by CodeRabbit

  • Bug Fixes
    • Fixed an issue where stale item metadata could remain after inserts, causing outdated items to persist.
    • Preserved existing row metadata when an insert occurs in the same transaction as an explicit metadata update.
    • Cleared leftover metadata only when no newer metadata update was already queued, improving sync accuracy.

@coderabbitai

coderabbitai Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 88dc55fc-1760-4629-a8e4-93807b3ab080

📥 Commits

Reviewing files that changed from the base of the PR and between 267b36b and ff1cf8a.

📒 Files selected for processing (3)
  • .changeset/small-tables-listen.md
  • packages/db-sqlite-persistence-core/src/persisted.ts
  • packages/db-sqlite-persistence-core/tests/persisted.test.ts

📝 Walkthrough

Walkthrough

Adjusts SQLite persistence insert handling so a metadata-less insert only clears row metadata when no row-metadata write is already queued for that key. Adds regression tests for preserved metadata and stale metadata clearing, plus a patch changeset.

Changes

SQLite row-metadata insert fix

Layer / File(s) Summary
Insert metadata guard
packages/db-sqlite-persistence-core/src/persisted.ts
The wrapped sync.write insert path only queues a row-metadata delete when the transaction has not already queued a row-metadata write for that key.
Regression coverage and release note
packages/db-sqlite-persistence-core/tests/persisted.test.ts, .changeset/small-tables-listen.md
Tests cover same-transaction metadata preservation and stale metadata clearing, and the patch changeset records the release entry.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Suggested reviewers

  • samwillis

Poem

I thump through the metadata grass,
one hop keeps old crumbs from the past.
If a write is already in flight,
I leave its little tag alight. 🐇
Hooray for cleaner burrow paths!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main bug fix in db-sqlite-persistence-core and matches the changeset.
Description check ✅ Passed The description follows the template with changes, checklist, and release impact sections filled in.
Linked Issues check ✅ Passed The code and tests address issue #1618 by preserving row metadata on insert and clearing stale metadata when needed.
Out of Scope Changes check ✅ Passed The PR only adds a changeset plus focused code and test updates for the reported metadata bug.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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.

ExpoSQLitePersistence + queryCollectionOptions + offline-transactions - stale items after insert

1 participant