Skip to content

Commit aef38b5

Browse files
perf(ui): move loading shimmer off paint
1 parent 1bca825 commit aef38b5

6 files changed

Lines changed: 132 additions & 34 deletions

File tree

‎ui/src/pages/memory-import/view.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -692,8 +692,8 @@ export function renderMemoryImport(props: MemoryImportViewProps) {
692692
: nothing}
693693
${props.loading && !props.plan
694694
? html`<div class="settings-group memory-import__loading" aria-busy="true">
695-
<div class="memory-import__skeleton"></div>
696-
<div class="memory-import__skeleton"></div>
695+
<div class="skeleton memory-import__skeleton"></div>
696+
<div class="skeleton memory-import__skeleton"></div>
697697
</div>`
698698
: (props.plan?.providers ?? []).map((provider) => renderProvider(props, provider))}
699699
${renderConfirmation(props)}

‎ui/src/pages/usage/view.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,9 @@ function renderUsageLoadingState(filters: UsageFilterState) {
115115
</div>
116116
</div>
117117
<div class="usage-loading-grid">
118-
<div class="usage-skeleton-block usage-skeleton-block--tall"></div>
119-
<div class="usage-skeleton-block"></div>
120-
<div class="usage-skeleton-block"></div>
118+
<div class="skeleton usage-skeleton-block usage-skeleton-block--tall"></div>
119+
<div class="skeleton usage-skeleton-block"></div>
120+
<div class="skeleton usage-skeleton-block"></div>
121121
</div>
122122
</div>
123123
`,

‎ui/src/styles/base.css‎

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1287,22 +1287,31 @@ wa-popover::part(body)::-webkit-scrollbar-thumb:hover {
12871287
}
12881288

12891289
@keyframes shimmer {
1290-
0% {
1291-
background-position: -200% 0;
1290+
from {
1291+
transform: translateX(-100%);
12921292
}
1293-
100% {
1294-
background-position: 200% 0;
1293+
to {
1294+
transform: translateX(100%);
12951295
}
12961296
}
12971297

12981298
/* Skeleton loading primitives */
12991299
.skeleton {
1300-
background: linear-gradient(90deg, var(--bg-muted) 25%, var(--bg-hover) 50%, var(--bg-muted) 75%);
1301-
background-size: 200% 100%;
1302-
animation: shimmer 1.5s ease-in-out infinite;
1300+
position: relative;
1301+
overflow: hidden;
1302+
background: var(--bg-muted);
13031303
border-radius: var(--radius-md);
13041304
}
13051305

1306+
.skeleton::after {
1307+
position: absolute;
1308+
inset: 0;
1309+
background: linear-gradient(90deg, transparent 25%, var(--bg-hover) 50%, transparent 75%);
1310+
content: "";
1311+
animation: shimmer 1.5s ease-in-out infinite;
1312+
will-change: transform;
1313+
}
1314+
13061315
.skeleton-line {
13071316
height: 14px;
13081317
border-radius: var(--radius-sm);

‎ui/src/styles/memory-import.css‎

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -222,9 +222,10 @@
222222
.memory-import__skeleton {
223223
height: 96px;
224224
border-radius: var(--radius-md);
225-
background: linear-gradient(90deg, var(--bg-muted), var(--bg-elevated), var(--bg-muted));
226-
background-size: 200% 100%;
227-
animation: memory-import-pulse 1.4s ease infinite;
225+
}
226+
227+
.memory-import__skeleton::after {
228+
animation-duration: 1.4s;
228229
}
229230

230231
.memory-import__confirm .callout {
@@ -290,9 +291,3 @@
290291
justify-content: flex-start;
291292
}
292293
}
293-
294-
@keyframes memory-import-pulse {
295-
to {
296-
background-position: -200% 0;
297-
}
298-
}
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
import { chromium, type Browser } from "playwright";
2+
import { afterAll, beforeAll, describe, expect, it } from "vitest";
3+
import { readStyleSheet } from "../../../test/helpers/ui-style-fixtures.js";
4+
import {
5+
canRunPlaywrightChromium,
6+
resolvePlaywrightChromiumExecutablePath,
7+
} from "../test-helpers/control-ui-e2e.ts";
8+
9+
const chromiumExecutablePath = resolvePlaywrightChromiumExecutablePath(chromium.executablePath());
10+
const describeShimmer = canRunPlaywrightChromium(chromiumExecutablePath) ? describe : describe.skip;
11+
12+
let browser: Browser;
13+
14+
beforeAll(async () => {
15+
if (!canRunPlaywrightChromium(chromiumExecutablePath)) {
16+
return;
17+
}
18+
browser = await chromium.launch({ executablePath: chromiumExecutablePath, headless: true });
19+
});
20+
21+
afterAll(async () => {
22+
await browser?.close().catch(() => {});
23+
});
24+
25+
describeShimmer("Control UI shimmer", () => {
26+
it("moves loading highlights on compositor-safe pseudo-elements", async () => {
27+
const page = await browser.newPage();
28+
try {
29+
await page.setContent(`<!doctype html><html><head><style>
30+
${readStyleSheet("ui/src/styles/base.css")}
31+
${readStyleSheet("ui/src/styles/memory-import.css")}
32+
${readStyleSheet("ui/src/styles/usage.css")}
33+
</style></head><body>
34+
<div class="skeleton skeleton-line"></div>
35+
<div class="skeleton usage-skeleton-block"></div>
36+
<div class="skeleton memory-import__skeleton"></div>
37+
</body></html>`);
38+
39+
for (const selector of [
40+
".skeleton-line",
41+
".usage-skeleton-block",
42+
".memory-import__skeleton",
43+
]) {
44+
const styles = await page.locator(selector).evaluate((element) => {
45+
const host = getComputedStyle(element);
46+
const highlight = getComputedStyle(element, "::after");
47+
return {
48+
hostAnimation: host.animationName,
49+
hostBackground: host.backgroundImage,
50+
hostOverflow: host.overflow,
51+
highlightAnimation: highlight.animationName,
52+
highlightBackground: highlight.backgroundImage,
53+
highlightWillChange: highlight.willChange,
54+
};
55+
});
56+
57+
expect(styles).toMatchObject({
58+
hostAnimation: "none",
59+
hostBackground: "none",
60+
hostOverflow: "hidden",
61+
highlightAnimation: "shimmer",
62+
highlightWillChange: "transform",
63+
});
64+
expect(styles.highlightBackground).toContain("linear-gradient");
65+
}
66+
} finally {
67+
await page.close().catch(() => {});
68+
}
69+
});
70+
71+
it("keeps the global reduced-motion gate", async () => {
72+
const page = await browser.newPage({ reducedMotion: "reduce" });
73+
try {
74+
await page.setContent(`<!doctype html><html><head><style>
75+
${readStyleSheet("ui/src/styles/base.css")}
76+
${readStyleSheet("ui/src/styles/memory-import.css")}
77+
${readStyleSheet("ui/src/styles/usage.css")}
78+
</style></head><body>
79+
<div class="skeleton skeleton-line"></div>
80+
<div class="skeleton usage-skeleton-block"></div>
81+
<div class="skeleton memory-import__skeleton"></div>
82+
</body></html>`);
83+
84+
for (const selector of [
85+
".skeleton-line",
86+
".usage-skeleton-block",
87+
".memory-import__skeleton",
88+
]) {
89+
const animation = await page.locator(selector).evaluate((element) => {
90+
const highlight = getComputedStyle(element, "::after");
91+
return {
92+
duration: highlight.animationDuration,
93+
iterations: highlight.animationIterationCount,
94+
};
95+
});
96+
97+
expect(animation).toEqual({ duration: "1e-05s", iterations: "1" });
98+
}
99+
} finally {
100+
await page.close().catch(() => {});
101+
}
102+
});
103+
});

‎ui/src/styles/usage.css‎

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -314,9 +314,10 @@
314314
min-height: 96px;
315315
border-radius: var(--radius-lg);
316316
border: 1px solid var(--border);
317-
background: linear-gradient(90deg, var(--bg-muted) 20%, var(--bg-hover) 50%, var(--bg-muted) 80%);
318-
background-size: 200% 100%;
319-
animation: usage-shimmer 1.35s ease-in-out infinite;
317+
}
318+
319+
.usage-skeleton-block::after {
320+
animation-duration: 1.35s;
320321
}
321322

322323
.usage-skeleton-block--tall {
@@ -1983,13 +1984,3 @@
19831984
transform: rotate(360deg);
19841985
}
19851986
}
1986-
1987-
@keyframes usage-shimmer {
1988-
0% {
1989-
background-position: 100% 0;
1990-
}
1991-
1992-
100% {
1993-
background-position: -100% 0;
1994-
}
1995-
}

0 commit comments

Comments
 (0)