Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR enhances font preloading by excluding elements that cannot use the font-family CSS property before running visibility and position checks.
- Introduces an
EXCLUDED_TAG_NAMESset to list non-stylable HTML tags. - Adds
canElementBeStyledWithFontFamilyandcanElementBeProcessedhelper methods. - Updates filtering in
run()andprocessExternalFonts()to use the new combined check.
Comments suppressed due to low confidence (1)
assets/js/wpr-beacon.js:480
- [nitpick] The constant name
EXCLUDED_TAG_NAMESis quite generic; consider renaming it to something likeEXCLUDED_FONT_STYLABLE_TAGSto clarify that these tags cannot be styled withfont-family.
canElementBeStyledWithFontFamily(element) {
Coverage summary from CodacySee diff coverage on Codacy
Coverage variation details
Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: Diff coverage details
Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: See your quality gate settings Change summary preferencesFootnotes
|
Description
Fixes #7428
This enhancement improves font preloading performance by filtering out HTML elements that cannot be styled with font-family CSS properties before processing them for visibility and position checks.
Type of change
Detailed scenario
What was tested
Automated Testing:
canElementBeStyledWithFontFamily()andcanElementBeProcessed()methodsManual Testing Scenarios:
<img>,<script>,<meta>,<br>are excluded from font analysis<p>,<div>,<span>continue to be processed normallyHow to test
Refer to wp-media/rocket-scripts#61
Technical description
Documentation
Implementation Details:
canElementBeStyledWithFontFamily(element): Checks if element's tagName is not in excluded setcanElementBeProcessed(element): Combines font-family check with above-fold visibility checkrun()method: Changed from.filter(el => this.isElementAboveFold(el))to.filter(el => this.canElementBeProcessed(el))processExternalFonts()method: Applied same filtering improvementFlow Diagram
New dependencies
None
Risks
None
Mandatory Checklist
Code validation
Code style