Opened 4 years ago
Last modified 4 years ago
#50011 new defect (bug)
Edge case in image lazy-loading
Reported by: | superpoincare | Owned by: | |
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | normal | Version: | 5.5 |
Component: | Media | Keywords: | |
Focuses: | Cc: |
Description
In #44427 the feature to lazy load images by default was added.
The code uses regex and hence there are some edge cases which can complicate.
One such case is adding
loading=lazy
with space before 'loading' in the alt value.
This can be done in the block-editor by selecting the image and adding the above in:
Image settings > Alt text (alternative text) box
This is allowed in HTML.
When this is done, the regex thinks that the image tag has a lazy loading attribute and doesn't add it.
Change History (3)
Note: See
TracTickets for help on using
tickets.
Right, it is a "false positive" edge case. The code there only looks for a
loading=
string in the img tag. This is the same as when addingsrcset
, see https://core.trac.wordpress.org/browser/tags/5.4.1/src/wp-includes/media.php#L1499. It is possible to somewhat enhance it by using regex, but there will always be a small possibility for a false positive.The general idea is to eliminate "false negatives" as much as possible, i.e. not add another
loading
attribute if one already exists. False positives are not great, but will not "break" anything like false negatives/double attributes can.Will test a bit to see how much slower it gets if using regex there.