fix(pull-requests): expand code tab diffs by default (#9174)

Co-authored-by: maria-rcks <[email protected]>
This commit is contained in:
mariaandmaria-rcks authored and GitHub committed 2026-09-02 01:44:25 -04:00
1 parent 80a14b6588
commit 0681d85499
2 files changed
+11 -12

No files matched your search

@@ -50,9 +50,9 @@ describe("isLineInFileDiff", () => {
describe("isFileDiffCollapsed", () => {
const NO_TOGGLES: ReadonlySet<string> = new Set();
it("folds every file before the reader has touched anything", () => {
expect(isFileDiffCollapsed("a.ts", null, NO_TOGGLES)).toBe(true);
expect(isFileDiffCollapsed("b.ts", null, NO_TOGGLES)).toBe(true);
it("opens every file before the reader has touched anything", () => {
expect(isFileDiffCollapsed("a.ts", null, NO_TOGGLES)).toBe(false);
expect(isFileDiffCollapsed("b.ts", null, NO_TOGGLES)).toBe(false);
});
it("opens every file once the toolbar has asked for it", () => {
@@ -66,12 +66,12 @@ describe("isFileDiffCollapsed", () => {
expect(isFileDiffCollapsed("b.ts", "folded", NO_TOGGLES)).toBe(true);
});
it("keeps a file the reader opened open as the next slice arrives", () => {
// The file keys grow with every slice, so the answer for one already open must not depend on
// how many of them there are by then.
it("keeps a file the reader folded closed as the next slice arrives", () => {
// The file keys grow with every slice, so the answer for one already folded must not depend
// on how many of them there are by then.
const toggled = new Set(["b.ts"]);
expect(isFileDiffCollapsed("b.ts", null, toggled)).toBe(false);
expect(isFileDiffCollapsed("c.ts", null, toggled)).toBe(true);
expect(isFileDiffCollapsed("b.ts", null, toggled)).toBe(true);
expect(isFileDiffCollapsed("c.ts", null, toggled)).toBe(false);
});
it("still answers to a toggle after either toolbar press", () => {
@@ -30,15 +30,14 @@ export type DiffFoldOverride = "expanded" | "folded" | null;
* A diff arrives a slice at a time, so the reader's own choices are kept as the difference from
* what the toolbar last said rather than as the set of folded files: a file that has not loaded
* yet cannot be in a set, and would otherwise land expanded moments after the reader folded
* everything. Folded is the starting point whatever the change's size, because laying out every
* file of it costs the reader the seconds before the tab is usable and buries the file they came
* for among the ones they did not.
* everything. Files start expanded so opening the Code tab immediately shows the change; the
* reader can still fold individual files or the whole diff from the toolbar.
*/
export function isFileDiffCollapsed(
fileKey: string,
foldOverride: DiffFoldOverride,
toggledFileKeys: ReadonlySet<string>,
): boolean {
const foldedByDefault = foldOverride !== "expanded";
const foldedByDefault = foldOverride === "folded";
return toggledFileKeys.has(fileKey) ? !foldedByDefault : foldedByDefault;
}