Skip to content

[ADD] checks_odoo_module_scss: new scss-font-display-missing and scss-css-import checks - #207

Merged
moylop260 merged 2 commits into
OCA:mainfrom
vauxoo-dev:scss-css-import-moy
Nov 30, 2026
Merged

moylop260 merged 2 commits into
OCA:mainfrom
vauxoo-dev:scss-css-import-moy

Conversation

@moylop260

@moylop260 moylop260 commented Nov 30, 2026 •

Copy link
Copy Markdown
Collaborator

Adds two checks for stylesheets, in two commits of one PR because the second one builds on the first (both extend the scss checker of #205 and its README and test counters):

  1. scss-font-display-missing: a @font-face without font-display, with autofix.
  2. scss-css-import: an @import that the browser has to resolve.

This replaces #206 (the first commit), which is closed.

scss-font-display-missing

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

The autofix adds font-display: swap; as the last declaration of the @font-face, with the indentation of the first line of the previous declaration (a multi-line src does not shift it), the missing ; of the last one when needed, the line ending of the file (CRLF stays CRLF) and the trailing comment on the same line. It leaves icon fonts alone (a font-family with icon, awesome or glyph), because they need block; the message still reports them. 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).

scss-css-import

It reports an @import of a stylesheet that is not part of the bundle: @import url(...), an @import of an http(s):// or // address, or of a .css file. Any other @import is a Sass partial that the compiler inlines, so @import "variables"; is not reported. Every item of a comma list is checked, and a ; inside the url() (Google Fonts css2) does not cut the reported text.

There are two cases, and the message says which one it is:

  • @import url(...), or any @import inside a .css file: resolved by the browser. Odoo keeps it and moves it to the top of the bundle. The browser only discovers the imported file after it has downloaded and parsed the one that imports it, so the two downloads are chained and the page cannot paint before both end (GTmetrix: "Avoid CSS @import" and "Avoid chaining critical requests"). When it is another site, as fonts.googleapis.com, it also costs a new connection (DNS, TCP and TLS), the stylesheet has a short cache lifetime that the project does not control, and every visitor is revealed to a third party.
  • A quoted @import "..." of a .css file or of an address, in a .scss file: dropped by Odoo. compile_css removes the quoted imports whose path has a dot or starts with ., / or ~, and adds "Local import is forbidden for security reasons" to the errors of the bundle. The file is never loaded.

What to do instead, also in the message: self-host a font (download the files as .woff2, declare the @font-face in the module with font-display: swap and delete the @import), or list the stylesheet in the assets of the manifest. There is no autofix: the fonts have to be downloaded and reviewed.

Tests

Full suite: 177 passed, 7 skipped. Each check has its fixture (4 reported cases each, plus accepted forms and the report bundle that must stay untouched) and its unit tests (CRLF, missing ;, case-insensitive font-display, each import form, Sass partials, comments). The README is generated with tox -e update-readme (Python 3.14), which shows at most three examples per check.

@moylop260
moylop260 force-pushed the scss-css-import-moy branch 3 times, most recently from 1a1e135 to 0b86ec8 Compare November 30, 2026 18:22
@moylop260 moylop260 changed the title [ADD] checks_odoo_module_scss: new scss-css-import check [ADD] checks_odoo_module_scss: new scss-font-display-missing and scss-css-import checks Nov 30, 2026
…th autofix

A @font-face without font-display makes the browser use auto, which in practice is block: the text that uses the font stays invisible while the font downloads (the flash of invisible text), and that delays the First and Largest Contentful Paint (GTmetrix: Ensure text remains visible during webfont load).

The check reports it and recommends swap, optional for a decorative font and block for an icon font. The autofix adds font-display: swap as the last declaration, with the indentation of the first line of the previous declaration, the missing semicolon when needed, the line ending of the file and the trailing comment of its line, and it leaves the icon fonts alone because they need block. The stylesheets of the PDF report bundles are skipped, wkhtmltopdf does not paint the text progressively.
An @import url(...) of a stylesheet, or any @import inside a .css file, is left to the browser, which only discovers the imported file after it has downloaded and parsed the one that imports it: the two downloads are chained and the page cannot paint before both end (GTmetrix: Avoid CSS @import and Avoid chaining critical requests). When it is another site, as fonts.googleapis.com, it also costs a connection and shows every visitor to a third party.

A quoted @import of a .css file or of an address, in a .scss file, never reaches the browser: Odoo removes the quoted imports whose path has a dot or starts with ., / or ~ and reports Local import is forbidden among the errors of the bundle. The check says which of the two cases it is and points to the assets of the manifest or to a self-hosted .woff2 with an @font-face. Every item of a comma list is checked and a semicolon inside the url() does not cut the reported text.
@moylop260
moylop260 merged commit f819711 into OCA:main Nov 30, 2026
42 of 43 checks passed
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