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 {...@@ -15,6 +15,11 @@ import {
15import { getRenderablePatch, resolveFileDiffPath, type RenderablePatch } from "~/lib/diffRendering";15import { getRenderablePatch, resolveFileDiffPath, type RenderablePatch } from "~/lib/diffRendering";
16import { reviewEnvironment } from "~/state/review";16import { reviewEnvironment } from "~/state/review";
1717
18const filePathCollator = new Intl.Collator(undefined, {
19 numeric: true,
20 sensitivity: "base",
21});
22
18export function useReviewFilePatches({23export function useReviewFilePatches({
19 environmentId,24 environmentId,
20 cwd,25 cwd,
...@@ -49,10 +54,7 @@ export function useReviewFilePatches({...@@ -49,10 +54,7 @@ export function useReviewFilePatches({
49 [requested, scope],54 [requested, scope],
50 );55 );
51 const files = useMemo(56 const files = useMemo(
52 () =>57 () => source?.files?.toSorted((a, b) => filePathCollator.compare(a.path, b.path)) ?? [],
53 source?.files?.toSorted((a, b) =>
54 a.path.localeCompare(b.path, undefined, { numeric: true, sensitivity: "base" }),
55 ) ?? [],
56 [source?.files],58 [source?.files],
57 );59 );
58 const queries = useMemo(60 const queries = useMemo(
...@@ -191,10 +193,7 @@ export function useReviewFilePatches({...@@ -191,10 +193,7 @@ export function useReviewFilePatches({
191 };193 };
192 })194 })
193 : (preview?.kind === "files" ? preview.files : []).toSorted((a, b) =>195 : (preview?.kind === "files" ? preview.files : []).toSorted((a, b) =>
194 resolveFileDiffPath(a).localeCompare(resolveFileDiffPath(b), undefined, {196 filePathCollator.compare(resolveFileDiffPath(a), resolveFileDiffPath(b)),
195 numeric: true,
196 sensitivity: "base",
197 }),
198 ),197 ),
199 [source, files, patches, scope, preview],198 [source, files, patches, scope, preview],
200 );199 );