Skip to content

[ADD] checks_odoo_module_scss: new scss-font-display-missing check with autofix - #206

Closed
moylop260 wants to merge 2 commits into
OCA:mainfrom
vauxoo-dev:scss-font-display-moy
Closed

moylop260 wants to merge 2 commits into
OCA:mainfrom
vauxoo-dev:scss-font-display-moy

Conversation

@moylop260

@moylop260 moylop260 commented Nov 30, 2026 •

Copy link
Copy Markdown
Collaborator

Adds scss-font-display-missing: a @font-face without font-display.

Depends on #205, which adds the scss checker; this PR contains its commit until it is merged, the new check is the last commit.

Why

Without font-display the browser uses auto, which in practice is block: the text that uses the font stays invisible while the font downloads, for a short block period (about 3 s in the browsers that implement it), before the browser falls back (the "flash of invisible text"). That delays the First and Largest Contentful Paint of every page that has text in that font. GTmetrix and Lighthouse report it as "Ensure text remains visible during webfont load".

Value What the visitor sees When
swap the text at once in the fallback font, swapped when the font is ready the default recommendation: the text is never hidden
optional the fallback font, and the custom one only if it was already cached a decorative font: it never moves the text, so there is no layout shift
fallback a very short invisible period, then the fallback; the swap only within a few seconds in between
block invisible text during the block period, on purpose an icon font: a fallback font would paint the code points of the icons as unrelated characters
none (auto) invisible text during the block period what this check reports

Autofix

It adds font-display: swap; as the last declaration of the @font-face, with the indentation of the previous declaration, the missing ; of the last one when needed, and the line ending of the file (a file with CRLF stays with CRLF; a test caught that a first version inserted an LF).

Report bundles

The stylesheets of the PDF report bundles (report_assets_*) are not reported: wkhtmltopdf does not paint the text progressively, so font-display has no effect there (see #205 for how the bundle is read).

Tests

Full suite: 149 passed, 7 skipped. The fixture has 4 reported faces and 1 with font-display, plus the report bundle that must stay untouched; 7 unit tests cover the one-line face, the missing ;, case-insensitive font-display, CRLF and the report bundle. README sections added by hand, as in #205.

@moylop260
moylop260 force-pushed the scss-font-display-moy branch 2 times, most recently from 476c6e2 to cb21345 Compare November 30, 2026 09:25
… autofix

A `@font-face` that serves its font as .otf, .ttf, .eot or .woff and no
.woff2 makes every visitor download a bigger file than needed. WOFF2
compresses with Brotli: measured on 13 real fonts of Odoo 19.0 it is
44-72 % smaller than the .ttf/.otf (63 % in total) and 12-30 % smaller
than the .woff (26 % in total). Every browser still supported reads it
(Chrome 36, Firefox 39, Safari 12, Edge 14), so no other format is
needed as a fallback. With the default font-display the text stays
invisible while the font downloads, so its size shows in the paint
metrics (GTmetrix: "Enormous network payloads").

The message explains how to convert the font without touching its
glyphs. The autofix rewrites the url() and its format() when the .woff2
already sits next to the old file, keeping the quotes and the line
endings; it does not convert the font, since that is a binary file that
has to be reviewed.

The stylesheets of the PDF report bundles (`report_assets_*`) are not
reported: wkhtmltopdf renders them with an old QtWebKit that does not
read WOFF2, and a PDF whose @font-face has only a .woff2 falls back to
another font. The bundle is read from the "assets" of the manifest.

This adds the scss checker: the hook now also runs on .scss and .css
files, and reads the ones declared in the "assets" of the manifest.
@moylop260
moylop260 force-pushed the scss-font-display-moy branch from cb21345 to db54931 Compare November 30, 2026 09:28
…th autofix

A `@font-face` without `font-display` uses `auto`, which in practice is
`block`: the text that uses the font stays invisible until the font
arrives, up to 3 seconds, before the browser falls back (the flash of
invisible text). That delays the First and Largest Contentful Paint of
every page that has text in that font. GTmetrix reports it as "Ensure
text remains visible during webfont load".

`font-display: swap` paints the text at once with the fallback font and
swaps it when the font is ready; `optional` is better for a decorative
font because it never moves the text.

The autofix adds `font-display: swap;` as the last declaration of the
`@font-face`.
@moylop260

Copy link
Copy Markdown
Collaborator Author

Included in #207 as its first commit: the second check depends on the first one (same file, README and test counters), so both go in one PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant