Skip to content

fix(wires): re-sort documents on subscription update so new versions count as new time (ELELOG-745)#2686

Open
dannelundqvist wants to merge 1 commit into
mainfrom
feature/elelog-745-wire-reorder-on-new-version
Open

fix(wires): re-sort documents on subscription update so new versions count as new time (ELELOG-745)#2686
dannelundqvist wants to merge 1 commit into
mainfrom
feature/elelog-745-wire-reorder-on-new-version

Conversation

@dannelundqvist

Copy link
Copy Markdown
Collaborator

Problem

The Wire view sometimes shows wires in the wrong order (reported by the Swedish desk on Sydney hours - long sessions with many incoming updates). When a wire already in the list receives a new version, it keeps the slot its previous version had instead of moving to the top by its new modified time.

Root cause

Live subscription updates (pollSubscriptions in useDocuments) patch changed fields in place and call mutate(updatedData, false) without re-sorting. The updated wire's modified becomes newer but its position doesn't change. The server sort (modified desc) only runs on a full refetch, which the in-place update path skips. Not timezone-related; the long-session correlation is just accumulation of out-of-order in-place updates.

Fix

  • New mergeSubscriptionUpdates helper: patches matched fields, then re-sorts by the active sort (date-aware comparator, stable sort). Also exports sortHits.
  • useDocuments threads sort into pollSubscriptions and uses the helper.
  • Stream.tsx re-sorts its paginated (page 2+) merge branch too.

Status-only updates (read/saved/used) don't change modified, so those wires keep their position (no jumping when marked read).

Tests

Added __tests__/mergeSubscriptionUpdates.test.ts (TDD - written to fail against the old behaviour first): a new version moves to the top; an update older than others re-sorts down; a status-only update keeps position; fields are patched; no-sort leaves order untouched.

ELELOG-745

🤖 Generated with Claude Code

…count as new time

Live subscription updates patched changed fields in place without re-sorting,
so a wire receiving a new version kept the slot its previous version had
instead of moving to the top by its new modified time.

- add mergeSubscriptionUpdates helper (patch matched fields, then re-sort by
  the active sort) with tests
- useDocuments threads sort into pollSubscriptions and uses the helper
- Stream re-sorts the paginated merge branch too

ELELOG-745
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