Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/devtools-date-sort-equal-timestamps.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@tanstack/query-devtools': patch
---

fix(query-devtools/utils): make 'last updated' sort return 0 for queries with equal 'dataUpdatedAt' to follow the standard comparator contract
7 changes: 7 additions & 0 deletions packages/query-devtools/src/__tests__/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1076,6 +1076,13 @@ describe('Utils tests', () => {
expect(dateSort(older, newer)).toBe(1)
expect(dateSort(newer, older)).toBe(-1)
})

it('should return 0 when both queries share the same "dataUpdatedAt"', () => {
const a = buildQuery(['a'], { dataUpdatedAt: 100 })
const b = buildQuery(['b'], { dataUpdatedAt: 100 })

expect(dateSort(a, b)).toBe(0)
})
})

describe("'query hash'", () => {
Expand Down
6 changes: 4 additions & 2 deletions packages/query-devtools/src/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,10 @@ const getStatusRank = (q: Query) =>

const queryHashSort: SortFn = (a, b) => a.queryHash.localeCompare(b.queryHash)

const dateSort: SortFn = (a, b) =>
a.state.dataUpdatedAt < b.state.dataUpdatedAt ? 1 : -1
const dateSort: SortFn = (a, b) => {
const diff = b.state.dataUpdatedAt - a.state.dataUpdatedAt
return diff < 0 ? -1 : diff > 0 ? 1 : 0
}

const statusAndDateSort: SortFn = (a, b) => {
if (getStatusRank(a) === getStatusRank(b)) {
Expand Down
Loading