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:
+15
@@ -45,6 +45,21 @@
|
|||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
<!--SLP:OFFERINGS-JSON-LD-->
|
<!--SLP:OFFERINGS-JSON-LD-->
|
||||||
|
<!-- The host may inject a crawler-readable packages list above #root (removed by main.tsx at start-up).
|
||||||
|
Take it out of the layout so that removing it does not shift the page (CLS). -->
|
||||||
|
<style>
|
||||||
|
#packages-static {
|
||||||
|
position: absolute;
|
||||||
|
width: 1px;
|
||||||
|
height: 1px;
|
||||||
|
margin: -1px;
|
||||||
|
padding: 0;
|
||||||
|
overflow: hidden;
|
||||||
|
clip: rect(0, 0, 0, 0);
|
||||||
|
white-space: nowrap;
|
||||||
|
border: 0;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
<!--CMS:HERO-PRELOAD--><!--/CMS:HERO-PRELOAD-->
|
<!--CMS:HERO-PRELOAD--><!--/CMS:HERO-PRELOAD-->
|
||||||
<!--CMS:DATA-->
|
<!--CMS:DATA-->
|
||||||
<script type="application/json" id="cms-data">
|
<script type="application/json" id="cms-data">
|
||||||
|
|||||||
@@ -2,6 +2,14 @@
|
|||||||
@tailwind components;
|
@tailwind components;
|
||||||
@tailwind utilities;
|
@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>
|
/* 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).
|
(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.
|
Semantic names stay the same so the Tailwind colors in tailwind.config.ts keep working.
|
||||||
|
|||||||
@@ -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'/);
|
||||||
|
});
|
||||||
|
});
|
||||||
+1
-1
@@ -29,7 +29,7 @@ export default {
|
|||||||
// `[font-stretch:125%]` for the wide display type.
|
// `[font-stretch:125%]` for the wide display type.
|
||||||
sans: ['Archivo Variable', 'system-ui', 'sans-serif'],
|
sans: ['Archivo Variable', 'system-ui', 'sans-serif'],
|
||||||
display: ['Archivo Variable', 'system-ui', 'sans-serif'],
|
display: ['Archivo Variable', 'system-ui', 'sans-serif'],
|
||||||
mono: ['JetBrains Mono', 'monospace'],
|
mono: ['JetBrains Mono', 'JetBrains Mono Fallback', 'monospace'],
|
||||||
archivo: ['Archivo Variable', 'system-ui', 'sans-serif'],
|
archivo: ['Archivo Variable', 'system-ui', 'sans-serif'],
|
||||||
},
|
},
|
||||||
borderRadius: {
|
borderRadius: {
|
||||||
|
|||||||
Reference in New Issue
Block a user