authorgravatar for 97427849+flamboh@users.noreply.github.comoliver <97427849+flamboh@users.noreply.github.com> 2026-10-07 22:24:58-07:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2026-10-08 02:24:58-03:00
log6053a7878d24e5fd596d2b417ed94964a4b9c1c6
tree66fc73c164b11bc9e76b5a5661756f5160ea624e
parentc28cd905572e2a28934a6229d88bcf2975963032
signature Signed by PGP key B5690EEEBB952194

fix(web): PR file stats ignore the hide-whitespace toggle (#16162)


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

apps/web/src/components/pullRequest/PullRequestCodeTab.tsx+21-7
...@@ -37,6 +37,7 @@ import { orderDiffFiles } from "./pullRequestFileOrder.logic";...@@ -37,6 +37,7 @@ import { orderDiffFiles } from "./pullRequestFileOrder.logic";
37import {37import {
38 buildFileDiffRenderKey,38 buildFileDiffRenderKey,
39 fnv1a32,39 fnv1a32,
40 getDiffLineStat,
40 getRenderablePatch,41 getRenderablePatch,
41 resolveDiffThemeName,42 resolveDiffThemeName,
42 resolveFileDiffPath,43 resolveFileDiffPath,
...@@ -596,6 +597,23 @@ function PullRequestCodeTab({...@@ -596,6 +597,23 @@ function PullRequestCodeTab({
596 ),597 ),
597 [loadedSlices],598 [loadedSlices],
598 );599 );
600 const sourceFileStats = useMemo(
601 () =>
602 new Map(
603 parsedSlices.flatMap((parsed) =>
604 parsed?.kind === "files"
605 ? parsed.files.map(
606 (file, index) =>
607 [
608 buildFileDiffRenderKey(file),
609 getDiffLineStat([parsed.sourceFiles[index] ?? file]),
610 ] as const,
611 )
612 : [],
613 ),
614 ),
615 [parsedSlices],
616 );
599 const fileKeys = useMemo(() => items.map((item) => item.id), [items]);617 const fileKeys = useMemo(() => items.map((item) => item.id), [items]);
600 const collapsedFileKeys = useMemo(618 const collapsedFileKeys = useMemo(
601 () => new Set(items.filter((item) => item.collapsed === true).map((item) => item.id)),619 () => new Set(items.filter((item) => item.collapsed === true).map((item) => item.id)),
...@@ -811,12 +829,8 @@ function PullRequestCodeTab({...@@ -811,12 +829,8 @@ function PullRequestCodeTab({
811 const renderHeaderMetadata = useCallback(829 const renderHeaderMetadata = useCallback(
812 (item: CodeViewItem<ReviewAnnotationGroup>) => {830 (item: CodeViewItem<ReviewAnnotationGroup>) => {
813 if (item.type !== "diff") return null;831 if (item.type !== "diff") return null;
814 let additions = 0;832 let { additions, deletions } =
815 let deletions = 0;833 sourceFileStats.get(item.id) ?? getDiffLineStat([item.fileDiff]);
816 for (const hunk of item.fileDiff.hunks) {
817 additions += hunk.additionLines;
818 deletions += hunk.deletionLines;
819 }
820 const path = resolveFileDiffPath(item.fileDiff);834 const path = resolveFileDiffPath(item.fileDiff);
821 if (additions === 0 && deletions === 0) {835 if (additions === 0 && deletions === 0) {
822 const withheld = omittedFileStats.get(path);836 const withheld = omittedFileStats.get(path);
...@@ -864,7 +878,7 @@ function PullRequestCodeTab({...@@ -864,7 +878,7 @@ function PullRequestCodeTab({
864 </span>878 </span>
865 );879 );
866 },880 },
867 [omittedFileStats],881 [omittedFileStats, sourceFileStats],
868 );882 );
869883
870 const diffViewOptions = useMemo(884 const diffViewOptions = useMemo(