Skip to content
TypeScript

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

maria0681d854994e
diff --git a/apps/web/src/components/pullRequest/pullRequestDiff.logic.test.ts b/apps/web/src/components/pullRequest/pullRequestDiff.logic.test.ts
index b39cfd9ff1b..203be64eebe 100644
--- a/apps/web/src/components/pullRequest/pullRequestDiff.logic.test.ts
+++ b/apps/web/src/components/pullRequest/pullRequestDiff.logic.test.ts
@@ -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", () => {
diff --git a/apps/web/src/components/pullRequest/pullRequestDiff.logic.ts b/apps/web/src/components/pullRequest/pullRequestDiff.logic.ts
index b3c19c4fe9c..a286a4552cb 100644
--- a/apps/web/src/components/pullRequest/pullRequestDiff.logic.ts
+++ b/apps/web/src/components/pullRequest/pullRequestDiff.logic.ts
@@ -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;
}