Skip to content

fix(db): includes orderBy ignored after optimistic update on child collection#1496

Open
comet08 wants to merge 1 commit intoTanStack:mainfrom
comet08:main
Open

fix(db): includes orderBy ignored after optimistic update on child collection#1496
comet08 wants to merge 1 commit intoTanStack:mainfrom
comet08:main

Conversation

@comet08
Copy link
Copy Markdown

@comet08 comet08 commented Apr 25, 2026

Closes #1444

🎯 Changes

When a child collection item is updated, the D2 graph emits a (-1, +1) pair. If the delete (-1) message arrives first, an accumulator entry is created with the old orderByIndex. The subsequent insert (+1) message updated value correctly but never updated orderByIndex — so the child collection's comparator kept using the stale positional index.

This caused incorrect sort order immediately after optimistic updates on child collections, with ordering only correcting itself after server confirmation.

The parent pipeline (accumulateChanges) already handled this correctly. This fix applies the same orderByIndex update logic to the child pipeline accumulator and the nested pipeline accumulator for consistency.

✅ 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).

…llection to avoid stale sort order

Co-Authored-By: Claude <noreply@anthropic.com>
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.

TanStack DB "includes" ignores orderBy after optimistic update

1 participant