문제: 라우트 로딩 화면(280 px)은 720 px 창에 들고 홈 화면(732 px 문서)은
넘친다. 일반(overlay가 아닌) 스크롤바를 쓰는 브라우저에서 홈이 그려지는
프레임에 세로 스크롤바가 생겨 너비가 15 px 줄고 header 오른쪽(세션 영역)이
15 px 밀린다(1280x720·1366x657에서 CLS 0.0002, 리뷰 15-R2 12회). lab과 모든
게이트의 Playwright Chromium은 --hide-scrollbars로 떠서 이 shift를 못 본다.
고른 방법:
- base.css의 :root에 scrollbar-gutter: stable을 둔다. 스크롤바 자리가
첫 프레임부터 있어 내용이 길어져도 너비가 바뀌지 않는다. overlay
스크롤바(macOS 기본)는 어느 쪽이든 자리를 쓰지 않는다.
- lab(scripts/test-performance.ts)은 labBrowserLaunchOptions()로
--hide-scrollbars를 빼고 띄운다. lab.json context.browser에
scrollbars: "visible"을 남긴다. 이제 lab의 `/` CLS가 같은 회귀를 본다.
- 단위 테스트: 실행 옵션이 --hide-scrollbars를 빼는지, :root에
scrollbar-gutter: stable이 있는지.
- 시각 골든 5장을 새 gutter에 맞춰 desktop에서 다시 찍는다
(test:visual:update).
버린 대안: html { overflow-y: scroll } — 짧은 화면에도 빈 스크롤바를
그린다.
위험·한계: 스크롤바 폭만큼 오른쪽 여백이 짧은 화면에서도 늘 생긴다.
--hide-scrollbars로 뜬 Chromium도 gutter 자리를 잡는다. 그래서 시각 골든
5장이 모두 바뀌었다. 바뀐 것은 내용 폭 15 px다(main 1040 → 1025 px).
compact(390 px) 골든은 줄바꿈이 늘어 1297 → 1377 px로 길어졌다. 실제
휴대폰은 overlay 스크롤바라 자리를 쓰지 않으므로, compact 골든은 휴대폰
화면보다 15 px 좁게 그린다. 열린 drawer의 가림막은 gutter를 덮지 않는다
(일반 스크롤바 브라우저에서는 그 자리에 스크롤바가 그려진다). lab의 CLS 예산
0.1은 그대로라 0.0002 shift가 다시 생겨도 lab은 통과한다(값만 남는다).
Firefox·Windows 스크롤바 폭은 재지 않았다.
검증: desktop batch에서 확인.
node scripts/run-vitest.ts run tests/unit/lab-performance.test.ts
corepack pnpm test:visual (부모 d5b6aeba에서 6건 통과, 이 변경은 옛
골든과 5건이 달라 실패, 다시 찍은 골든에서 통과)
corepack pnpm build && corepack pnpm test:performance -- --runs=5
Refs: 1105/15-05
101 lines
3.1 KiB
TypeScript
101 lines
3.1 KiB
TypeScript
/**
|
|
* 11-07. The pieces of the lab performance gate (`scripts/test-performance.ts`)
|
|
* that decide what is measured and whether the numbers can be trusted.
|
|
*/
|
|
|
|
export const DEFAULT_LAB_PORT = 4173;
|
|
export const DEFAULT_LAB_RUNS = 5;
|
|
|
|
/**
|
|
* `vite preview` arguments. Without `--strictPort` vite moved to the next free
|
|
* port when the requested one was taken, and the gate measured whatever server
|
|
* already listened there.
|
|
*/
|
|
export function previewArguments(port: number): readonly string[] {
|
|
return [
|
|
"pnpm",
|
|
"preview",
|
|
"--host",
|
|
"127.0.0.1",
|
|
"--port",
|
|
String(port),
|
|
"--strictPort",
|
|
];
|
|
}
|
|
|
|
/**
|
|
* 1105/15-05. Playwright starts Chromium with `--hide-scrollbars`, so the lab
|
|
* measured layout shift in a browser without the classic scrollbar most
|
|
* Windows and Linux desktops draw. A first render that made one appear
|
|
* moved the header 15 px and the lab reported CLS 0. The lab runs with
|
|
* scrollbars, as those users see the page.
|
|
*/
|
|
export function labBrowserLaunchOptions(): { ignoreDefaultArgs: string[] } {
|
|
return { ignoreDefaultArgs: ["--hide-scrollbars"] };
|
|
}
|
|
|
|
export type SampleSummary = Readonly<{
|
|
median: number;
|
|
min: number;
|
|
max: number;
|
|
samples: readonly number[];
|
|
}>;
|
|
|
|
export function summarizeSamples(samples: readonly number[]): SampleSummary {
|
|
if (samples.length === 0) throw new RangeError("no samples to summarize");
|
|
const sorted = [...samples].sort((left, right) => left - right);
|
|
const middle = Math.floor(sorted.length / 2);
|
|
const median =
|
|
sorted.length % 2 === 1
|
|
? sorted[middle]!
|
|
: (sorted[middle - 1]! + sorted[middle]!) / 2;
|
|
return Object.freeze({
|
|
median,
|
|
min: sorted[0]!,
|
|
max: sorted.at(-1)!,
|
|
samples: Object.freeze([...samples]),
|
|
});
|
|
}
|
|
|
|
/** Fails when anything already answers where the preview server will listen. */
|
|
export async function assertPortUnused(
|
|
baseUrl: string,
|
|
fetchImpl: typeof fetch = fetch,
|
|
): Promise<void> {
|
|
let answered = false;
|
|
try {
|
|
await fetchImpl(baseUrl, { signal: AbortSignal.timeout(1_000) });
|
|
answered = true;
|
|
} catch {
|
|
// Nothing is listening: the expected state.
|
|
}
|
|
if (answered) {
|
|
throw new Error(
|
|
`${baseUrl} already answers before the preview server starts; another server holds the port.`,
|
|
);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Compares the release the server actually serves with the local build that
|
|
* is being measured, so the numbers belong to that build.
|
|
*/
|
|
export async function assertServedRelease(
|
|
baseUrl: string,
|
|
expected: Readonly<{ buildId: string; releaseId: string }>,
|
|
fetchImpl: typeof fetch = fetch,
|
|
): Promise<void> {
|
|
const response = await fetchImpl(new URL("/release-manifest.json", baseUrl), {
|
|
cache: "no-store",
|
|
});
|
|
const served = response.ok
|
|
? ((await response.json()) as Partial<Record<"buildId" | "releaseId", unknown>>)
|
|
: {};
|
|
if (served.buildId !== expected.buildId || served.releaseId !== expected.releaseId) {
|
|
throw new Error(
|
|
`${baseUrl} serves build ${String(served.buildId)}/${String(served.releaseId)}, ` +
|
|
`not the measured ${expected.buildId}/${expected.releaseId}.`,
|
|
);
|
|
}
|
|
}
|