Skip to content

Commit

Permalink
fix: fix maximum call stack size with fallback sort
Browse files Browse the repository at this point in the history
  • Loading branch information
hugop95 authored Feb 17, 2025
1 parent a38fc8c commit 8b78710
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
14 changes: 14 additions & 0 deletions test/utils/compare.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,20 @@ describe('compare', () => {
}),
).toBe(-1)
})

it("doesn't sort using the fallback configuration more than once", () => {
let node = createTestNode({ name: 'aaa' })
let duplicateNode = createTestNode({ name: 'aaa' })
expect(
compare(node, duplicateNode, {
...compareOptions,
fallbackSort: {
type: 'alphabetical',
order: 'asc',
} as const,
}),
).toBe(0)
})
})

let createTestNode = ({ name }: { name: string }): SortingNode =>
Expand Down
4 changes: 3 additions & 1 deletion utils/compare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,11 @@ export let compare = <T extends SortingNode>(
let { fallbackSort, order } = options
return compare(a, b, {
...options,
fallbackSort: {
type: 'unsorted',
},
order: fallbackSort.order ?? order,
type: fallbackSort.type,
fallbackSort,
} as CompareOptions<T>)
}

Expand Down

0 comments on commit 8b78710

Please sign in to comment.