Make WordPress Core

Opened 4 years ago

Last modified 4 years ago

#50011 new defect (bug)

Edge case in image lazy-loading

Reported by: superpoincare's profile superpoincare Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 5.5
Component: Media Keywords:
Focuses: Cc:


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


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)

#1 @SergeyBiryukov
4 years ago

  • Component changed from General to Media

This ticket was mentioned in Slack in #core by ocean90. View the logs.

4 years ago

#3 @azaozz
4 years ago

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 adding srcset, see 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.

Note: See TracTickets for help on using tickets.