perf(web): reuse the collator when sorting diff files (#18420)

Co-authored-by: SAPHID <[email protected]>
Co-authored-by: GPT-6.1 Sol <[email protected]>
This commit is contained in:
authored and GitHub committed 2026-10-12 00:37:53 +00:00
1 parent 6ec6376e32
commit 7ab28a3b2e
1 file changed
+7 -8
@@ -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],
);