From 8b78710cef8c22541275d6a3b6b815a2343f3077 Mon Sep 17 00:00:00 2001 From: Hugo <60015232+hugop95@users.noreply.github.com> Date: Mon, 17 Feb 2025 07:16:07 +0100 Subject: [PATCH] fix: fix maximum call stack size with fallback sort --- test/utils/compare.test.ts | 14 ++++++++++++++ utils/compare.ts | 4 +++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/test/utils/compare.test.ts b/test/utils/compare.test.ts index e4d5a31b..cc301750 100644 --- a/test/utils/compare.test.ts +++ b/test/utils/compare.test.ts @@ -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 => diff --git a/utils/compare.ts b/utils/compare.ts index 6b58ac2e..8421e9de 100644 --- a/utils/compare.ts +++ b/utils/compare.ts @@ -101,9 +101,11 @@ export let compare = ( let { fallbackSort, order } = options return compare(a, b, { ...options, + fallbackSort: { + type: 'unsorted', + }, order: fallbackSort.order ?? order, type: fallbackSort.type, - fallbackSort, } as CompareOptions) }