CLS: #packages-static uit de layout (visueel verborgen) en metrisch gelijke terugvalfont voor JetBrains Mono; test erbij

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-17 08:16:41 +01:00
co-authored by Claude Sonnet 5.5
parent 43c76c80ad
commit d6a3acdd47
4 changed files with 49 additions and 1 deletions
+8
View File
@@ -2,6 +2,14 @@
@tailwind components;
@tailwind utilities;
/* Metric-compatible stand-in for JetBrains Mono while it loads (both have an advance of 0.6em), so the code
line of the hero does not re-wrap and shift the page when the real font arrives (CLS). */
@font-face {
font-family: 'JetBrains Mono Fallback';
src: local('Courier New'), local('Liberation Mono'), local('Cousine');
font-display: swap;
}
/* Theme tokens: variant (b | e) x mode (light | dark), selected by <html data-variant data-mode>
(set before first paint by public/theme-init.js and kept in sync by ThemeProvider).
Semantic names stay the same so the Tailwind colors in tailwind.config.ts keep working.
+25
View File
@@ -0,0 +1,25 @@
import { readFileSync } from 'node:fs';
import { resolve } from 'node:path';
import { describe, expect, it } from 'vitest';
const root = resolve(__dirname, '../..');
const read = (file: string) => readFileSync(resolve(root, file), 'utf8');
/**
* Guards against layout shifts (CLS) at start-up: the static packages list that the CMS host may inject above #root
* is removed by main.tsx, so it must not take any space, and the code line needs a metric-compatible font fallback.
*/
describe('layout stability at start-up', () => {
it('takes the injected #packages-static list out of the layout in index.html', () => {
const html = read('index.html');
const rule = html.match(/#packages-static\s*\{([^}]*)\}/);
expect(rule).not.toBeNull();
expect(rule?.[1]).toMatch(/position:\s*absolute/);
expect(rule?.[1]).toMatch(/clip:/);
});
it('gives the mono font a metric-compatible fallback', () => {
expect(read('src/index.css')).toMatch(/font-family:\s*'JetBrains Mono Fallback'/);
expect(read('tailwind.config.ts')).toMatch(/'JetBrains Mono',\s*'JetBrains Mono Fallback'/);
});
});