authorgravatar for saphid@gmail.comAlex Southwell <saphid@gmail.com> 2026-10-12 11:37:53+11:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2026-10-12 00:37:53+00:00
log7ab28a3b2e8837bb919c9b83b4b463b6ebf85c4a
treee6208746a96ad566e15c40e11f8acf8bd3b3029f
parent6ec6376e321cbc4ea202dee287497dac4582ea41
signature Signed by PGP key B5690EEEBB952194

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

Co-authored-by: SAPHID <saphid@users.noreply.github.com> Co-authored-by: GPT-6.1 Sol <noreply@openai.com>

1 files changed, 7 insertions(+), 8 deletions(-)

apps/web/src/components/diffs/useReviewFilePatches.ts+7-8
......@@ -15,6 +15,11 @@ import {
1515import { getRenderablePatch, resolveFileDiffPath, type RenderablePatch } from "~/lib/diffRendering";
1616import { reviewEnvironment } from "~/state/review";
1717
18const filePathCollator = new Intl.Collator(undefined, {
19 numeric: true,
20 sensitivity: "base",
21});
22
1823export function useReviewFilePatches({
1924 environmentId,
2025 cwd,
......@@ -49,10 +54,7 @@ export function useReviewFilePatches({
4954 [requested, scope],
5055 );
5156 const files = useMemo(
52 () =>
53 source?.files?.toSorted((a, b) =>
54 a.path.localeCompare(b.path, undefined, { numeric: true, sensitivity: "base" }),
55 ) ?? [],
57 () => source?.files?.toSorted((a, b) => filePathCollator.compare(a.path, b.path)) ?? [],
5658 [source?.files],
5759 );
5860 const queries = useMemo(
......@@ -191,10 +193,7 @@ export function useReviewFilePatches({
191193 };
192194 })
193195 : (preview?.kind === "files" ? preview.files : []).toSorted((a, b) =>
194 resolveFileDiffPath(a).localeCompare(resolveFileDiffPath(b), undefined, {
195 numeric: true,
196 sensitivity: "base",
197 }),
196 filePathCollator.compare(resolveFileDiffPath(a), resolveFileDiffPath(b)),
198197 ),
199198 [source, files, patches, scope, preview],
200199 );