fix(themes): 🚀 Fix Lighthouse Performance & Accessibility Issues#814
Draft
Ahmed-S-Abduallah wants to merge 2 commits intomasterfrom
Draft
fix(themes): 🚀 Fix Lighthouse Performance & Accessibility Issues#814Ahmed-S-Abduallah wants to merge 2 commits intomasterfrom
Ahmed-S-Abduallah wants to merge 2 commits intomasterfrom
Conversation
| </div> | ||
| {% if article.has_image %} | ||
| <img src="{{ article.image.url }}" alt="{{ article.image.alt }}" title="{{ article.image.alt }}" | ||
| width="1200" height="320" |
There was a problem hiding this comment.
Bug: The width and height attributes on images are ineffective for preventing layout shifts because CSS classes like w-full and h-80 override them by setting both dimensions explicitly.
Severity: MEDIUM
Suggested Fix
To fix the layout shift, either remove the fixed height class (e.g., h-80) and ensure a global img { height: auto; } rule exists, or use the CSS aspect-ratio property. This will allow the browser to correctly reserve space based on the image's dimensions before it loads.
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.
Location: src/views/pages/blog/single.twig#L42
Potential issue: The addition of `width` and `height` attributes to `<img>` tags is
intended to prevent Cumulative Layout Shift (CLS). However, this is ineffective because
CSS classes like `h-80`, `w-full`, and `h-full` are also applied, which explicitly set
both the width and height of the image. According to browser specifications, for the
HTML attributes to be used for aspect-ratio based space reservation, at least one CSS
dimension must be `auto`. Since both are defined, the browser ignores the aspect ratio
implied by the HTML attributes, leading to the very layout shifts the change was meant
to prevent. This issue is present on multiple pages, including the blog and product
single pages.
Did we get this right? 👍 / 👎 to inform future reviews.
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.
🎯 Overview
This PR addresses critical Lighthouse and PageSpeed issues related to image layout shifts (CLS) and color contrast compliance.
✨ Changes Made
📸 Image Layout Shift (CLS) Fixes
widthandheightattributes to all<img>elementsaspect-ratiofallbacks for dynamic imagesloading="lazy"anddata-src) systems🎨 Color Contrast Improvements
text-gray-400andtext-gray-500contrast ratios♿ Accessibility Enhancements
altattributes📊 Expected Results
🧪 Testing
📝 Files Changed
src/views/pages/product/single.twigsrc/views/pages/cart.twigsrc/views/pages/blog/*.twigsrc/views/pages/customer/orders/single.twigsrc/views/components/home/custom-testimonials.twigsrc/assets/styles/02-generic/reset.scsssrc/assets/styles/05-utilities/accessibility.scss(new)src/assets/styles/app.scss🔒 Compatibility