[Bug]: Collapse all does not stay applied to unloaded files in large diffs#17674

opened17d agobyAakshitkrnagpal

[Bug]: Collapse all does not stay applied to unloaded files in large diffs

Before submitting

  • I searched existing issues and did not find a duplicate.
  • I included enough detail to reproduce or investigate the problem.

Area

apps/web (the shared diff panel used by web and desktop)

Summary

In a large diff, clicking Collapse all collapses loaded files, but some files open as their patches load later. The issue affects added, deleted, and pure-renamed files whose placeholder change type differs from the loaded patch's type.

Steps to reproduce

  1. Open a project with an uncommitted diff larger than 120,000 bytes, containing more than four changed files. Include added, deleted, or pure-renamed files after the first four files in alphabetical order.
  2. Open the diff panel and select Uncommitted.
  3. Before scrolling through the diff, click Collapse all.
  4. Scroll down so the remaining files load.
  5. Observe the later-loaded added, deleted, or pure-renamed files.

A local reproduction used 24 changed files: six modified, six added, six deleted, and six pure renames. The patch was approximately 1.15 MB, comfortably above the lazy-loading threshold.

Expected behavior

All files remain collapsed as their patches load. Expand all expands every file, and individual toggles or file-tree navigation can still expand one file.

Actual behavior

Files whose identities change during loading arrive expanded, despite Collapse all having been selected. The toolbar can also stop reporting that all files are collapsed.

Impact

Minor bug or occasional failure

Makes large diffs harder to navigate and requires repeating the collapse action as more files load.

Version or commit

Investigated against local checkout 38571328a4bc3c30c56fc0cae299437fe9b53898. A local fix was manually checked in the dev app. The originally affected release version was not recorded.

Environment

macOS; local web dev client. The affected component is also used by desktop. Browser and OS versions were not recorded.

Workaround

Load the remaining files by scrolling through the diff, then click Collapse all again.

Cause and proposed solution

useReviewFilePatches creates placeholders for every file in a truncated preview. Placeholders use change or rename-changed until the individual patch loads.

buildFileDiffIdentityKey includes the previous path, current path, and change type. Collapse all records those placeholder keys. When the parser replaces a placeholder with a new, deleted, or rename-pure file, its key changes, so the saved collapse state no longer matches it.

Use a stable identity based on the previous and current paths for the lazy file list, which has one entry per path. Use that identity consistently for collapse state and file reveal. Keep the existing type-aware identity for ordinary parsed patches: a file type change can produce deletion and addition blocks at the same path, and those blocks still need distinct IDs (see #11074).

This keeps lazy loading and the existing collapse-state model intact. It does not require eagerly fetching every patch when Collapse all is clicked.

Validation of the local proposal

  • Focused regression cases failed before the fix for added, deleted, and pure-renamed files.
  • Regression coverage now checks collapse/expand and individual reveal across placeholder-to-patch transitions for modified, added, deleted, pure-renamed, and changed-renamed files.
  • 45 focused tests and the web typecheck passed; targeted lint completed with two existing warnings.
  • The reporter confirmed the behavior appeared to work in the local dev app using the large test repository.

Reproduced on Linux in the web dev client at 70e5e384da, using an isolated 24-file repository with a 1.46 MB patch: six modified, six added, six deleted, and six pure renames. In Uncommitted, I clicked Collapse all before later batches loaded, then scrolled. Later added files expanded and the toolbar reverted to Collapse all.

Recording: click Collapse all, then scroll; b-added-2.txt arrives expanded.