From 7ab28a3b2e8837bb919c9b83b4b463b6ebf85c4a Mon Sep 17 00:00:00 2001 From: Alex Southwell Date: Mon, 12 Oct 2026 11:37:53 +1100 Subject: [PATCH] perf(web): reuse the collator when sorting diff files (#18420) Co-authored-by: SAPHID Co-authored-by: GPT-6.1 Sol --- .../src/components/diffs/useReviewFilePatches.ts | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/apps/web/src/components/diffs/useReviewFilePatches.ts b/apps/web/src/components/diffs/useReviewFilePatches.ts index ad36f75c595c428628ccac021cce121ef785f6c0..2ac7593d41d3ea8d37c40f67c4abc2010829555a 100644 --- a/apps/web/src/components/diffs/useReviewFilePatches.ts +++ b/apps/web/src/components/diffs/useReviewFilePatches.ts @@ -15,6 +15,11 @@ import { import { getRenderablePatch, resolveFileDiffPath, type RenderablePatch } from "~/lib/diffRendering"; import { reviewEnvironment } from "~/state/review"; +const filePathCollator = new Intl.Collator(undefined, { + numeric: true, + sensitivity: "base", +}); + export function useReviewFilePatches({ environmentId, cwd, @@ -49,10 +54,7 @@ export function useReviewFilePatches({ [requested, scope], ); const files = useMemo( - () => - source?.files?.toSorted((a, b) => - a.path.localeCompare(b.path, undefined, { numeric: true, sensitivity: "base" }), - ) ?? [], + () => source?.files?.toSorted((a, b) => filePathCollator.compare(a.path, b.path)) ?? [], [source?.files], ); const queries = useMemo( @@ -191,10 +193,7 @@ export function useReviewFilePatches({ }; }) : (preview?.kind === "files" ? preview.files : []).toSorted((a, b) => - resolveFileDiffPath(a).localeCompare(resolveFileDiffPath(b), undefined, { - numeric: true, - sensitivity: "base", - }), + filePathCollator.compare(resolveFileDiffPath(a), resolveFileDiffPath(b)), ), [source, files, patches, scope, preview], ); -- 2.54.0