Repository navigation
[ADD] checks_odoo_module_xml: new xml-img-without-size check - #204
Merged
Merged
Conversation
moylop260
force-pushed
the
xml-img-size-moy
branch
2 times, most recently
from
November 30, 2026 09:26
4228034 to
b1048f8
Compare
An `<img>` of a QWeb template with no width and height makes the browser reserve no space for the picture until it arrives, so the content below it moves when it does. Lighthouse and GTmetrix report it as "Use explicit width and height on image elements" and it counts for Cumulative Layout Shift. The attributes should state the intrinsic size of the image: with `img-fluid` or `height: auto` the picture still scales down, but the `width` attribute is the width it uses. The dynamic forms `t-att-width`, `t-attf-width`, `t-att`, `t-att-style`, a width and a height in the inline style and an inline `aspect-ratio` are accepted, since the size is then decided at render time. The check only reports where a layout shift matters and the size can be stated. It skips the PDF reports and the mails, the pictures that the user replaces in the website builder (a fixed `src` inside a snippet or an editable zone), a size fixed by the class (`o_image_64_cover`), the pictures out of the flow and the pixels inside `<noscript>`. A picture whose `src` is built by the template, such as the logo of the website, is still reported. The usual comment of the file silences the rest.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds
xml-img-without-size: an<img>of a QWeb template with neitherwidthnorheight.Why
The browser reserves no space for the picture until it arrives, so the content below it moves when it does. Lighthouse and GTmetrix report it as "Use explicit width and height on image elements" and it counts for Cumulative Layout Shift. Today it is only found after the page is deployed and measured; this finds it in the commit.
Use the intrinsic size of the image in pixels. With
img-fluidorheight: autothe picture still scales down with its container, but thewidthattribute is the width it uses, so a smaller number than the real one shrinks it (measured in headless Chrome with a 600x300 image:width="16" height="9"rendered it at 16x8).What is accepted
widthandheight;t-att-width,t-attf-width(and the height ones); at-attort-att-style/t-attf-stylethat builds them at render time; awidthand aheightin the inlinestyle; an inlineaspect-ratio.What is not reported
The check only reports where a layout shift matters and the size can be stated. Every rule is a structural fact of the XML, not a guess about the picture:
web.external_layout*,web.html_container,mail.*,mass_mailing.*), it is the template of anir.actions.reportof the module, or its file is in areport/directory or hasmail,mailingordigestin its name.srcinside adata-snippet, anoe_structure/o_editablezone, a snippet template (s_*) or a page template. A picture whosesrcis built by the template (t-att-src,t-attf-src: the logo of the website, the photo of a record) is still reported, because nobody replaces it and the size is known only to the template.o_image_64_cover), a picture out of the flow (position-absolute,position: absolute) and a pixel inside<noscript>.Anything else can be silenced with the usual
oca-hooks:disablecomment of the file, which this check honours like its neighbours.Impact (measured)
On odoo/odoo 18.0
addons/and six OCA repositories (18.0) the first version of the check reported 472 findings, 467 of them in odoo/odoo and 5 in the OCA repositories; a classification of the 472 showed that about 85 % were reports, mails, snippets or sizes already fixed. Replaying the exemptions over the same 472 findings leaves 103, and 63 of the 69 findings that were classified as genuine are kept (the other 6 are a tracking pixel in<noscript>and static pictures of snippets that the user replaces). Typical OCA repository: 0 to 3 findings.No autofix: the right size depends on the picture and cannot be guessed from the XML.
Tests
Full suite: 125 passed, 7 skipped. The fixture has 3 reported images and one case per exemption; with the exemptions switched off the same fixture reports 13. The README sections were added by hand, because the generated README changes its indentation with the Python version used to build it.