From bdee20f1bb2b6f3c368b0e0508b9314951f463c6 Mon Sep 17 00:00:00 2001 From: SAPHID Date: Mon, 12 Oct 2026 00:07:22 +0000 Subject: [PATCH] perf(web): reuse the collator when sorting diff files 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 ad36f75c595c..2ac7593d41d3 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], );