perf(webui): reduce file activity layout work (#6587)

This commit is contained in:
chengyongru authored and GitHub committed 2026-11-06 23:21:48 +08:00
1 parent 3404fe83e2
commit 94bfd3ff7d
6 files changed
+98 -17

No files matched your search

+12
View File
@@ -22,6 +22,15 @@ async function expectTokenColor(section: Locator, text: string, variable: string
}, { text, variable })).toBe(true);
}
async function expectExpandedDiff(section: Locator) {
const wrapper = section.getByTestId("syntax-highlighted-diff-hunk");
// Expansion updates the window and its spacers on the next animation frame.
await expect.poll(() => wrapper.evaluate(node => {
const rowHeight = Math.floor((parseFloat(getComputedStyle(node).lineHeight) + 2) * 64) / 64;
return node.getBoundingClientRect().height >= 600 * rowHeight - 1;
})).toBe(true);
}
for (const dark of [false, true]) {
for (const narrow of [false, true]) {
test(`read-only diffs preserve source, colors and reading sizes: ${dark ? "dark" : "light"}, ${narrow ? "narrow" : "desktop"}`, async ({ page }) => {
@@ -94,6 +103,7 @@ test("large diffs retain bounded expansion, release and truncated-file actions",
await expect(long.locator("[data-code] [data-line]")).toHaveCount(160);
await expect(long.locator("[data-code] [data-line]").last()).toHaveText('export const item160 = "第 160 行 — readable code";');
await long.getByTestId("file-edit-diff-expand-lines").click();
await expectExpandedDiff(long);
const scroller = page.getByTestId("diff-fixture-scroller");
const seen = new Set<number>();
const height = await scroller.evaluate(node => node.scrollHeight);
@@ -135,6 +145,7 @@ for (const file of ["worker.ts", "long-separated.ts"]) {
await expect(section.locator("[data-code] [data-line]")).toHaveCount(160);
await expectKeywordColor(section.locator("[data-code] [data-line]"));
await section.getByTestId("file-edit-diff-expand-lines").click();
await expectExpandedDiff(section);
const scroller = page.getByTestId("diff-fixture-scroller");
const seen = new Set<number>();
const height = await scroller.evaluate(node => node.scrollHeight);
@@ -180,6 +191,7 @@ for (const [file, renderedIndex, sourceLine, reverse] of [["long.ts", 58, 59, fa
await section.getByTestId("file-edit-diff-toggle").click();
await expectKeywordColor(section.locator("[data-code] [data-line]"));
await section.getByTestId("file-edit-diff-expand-lines").click();
await expectExpandedDiff(section);
const scroller = page.getByTestId("diff-fixture-scroller");
const height = await scroller.evaluate(node => node.scrollHeight);
await section.getByTestId("syntax-highlighted-diff-hunk").evaluate((node, index) => {
+7 -2
View File
@@ -48,8 +48,7 @@ for (const width of [360, 1024]) {
await longPath.press("Enter");
await expect(page.getByLabel("Opened file")).toHaveText(longEditPath);
await expect(hint).toBeHidden();
await page.getByRole("button", { name: /View changes/ }).first().click();
await expect(page.getByTestId("file-edit-diff")).toBeVisible();
// Check hover before expanding the diff above it, which moves the image row.
const imagePath = references.nth(3);
await expect(imagePath).toContainText("…");
await imagePath.hover();
@@ -62,9 +61,15 @@ for (const width of [360, 1024]) {
await page.mouse.move(0, 0);
await imagePath.focus();
await expect(hint).toContainText(longEditPath.replace("serve_fixture.py", "screenshot.png"));
await page.getByRole("button", { name: /View changes/ }).first().click();
await expect(page.getByTestId("file-edit-diff")).toBeVisible();
await page.setViewportSize({ width: 1600, height: 800 });
await page.getByLabel("File edits").evaluate((element) => { (element as HTMLElement).style.maxWidth = "none"; });
await expect(longPath).not.toContainText("…");
expect(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth)).toBe(true);
await page.setViewportSize({ width, height: 800 });
await page.getByLabel("File edits").evaluate((element) => { (element as HTMLElement).style.maxWidth = "640px"; });
await expect(longPath).toContainText("…");
await expect(references.nth(1)).not.toContainText("…");
});
}