Skip to content

Conversation

@Miraeld
Copy link
Contributor

@Miraeld Miraeld commented May 9, 2025

Description

Fixes #49
The list of font extensions processed will now be dynamically coming from WP Rocket filter rather than a static value.

Type of change

  • Enhancement (non-breaking change which improves an existing functionality).

Detailed scenario

What was tested

The value is coming from the variable in the page. If we can't get it, then we have default values.

How to test

Please run with wp-media/wp-rocket#7318 to have the actual variable being added to the html

Technical description

Documentation

This pull request updates the BeaconPreloadFonts class to allow configurable font file extensions and improves the flexibility of font file detection. The most important changes include replacing the static FONT_FILE_REGEX with an instance-specific regex based on the configuration and updating font-loading logic to use the new regex.

Updates to font file detection:

  • src/BeaconPreloadFonts.js: Replaced the static FONT_FILE_REGEX with an instance-specific regex (this.FONT_FILE_REGEX) that is dynamically generated based on the processed_extensions configuration. If no configuration is provided, it defaults to ["woff", "woff2", "ttf"]. This change ensures greater flexibility in specifying font file extensions.

  • src/BeaconPreloadFonts.js: Updated the getNetworkLoadedFonts method to use the instance-specific this.FONT_FILE_REGEX instead of the removed static FONT_FILE_REGEX. This aligns the method with the new customizable regex logic.

New dependencies

None

Risks

None

Mandatory Checklist

Code validation

  • I validated all the Acceptance Criteria. If possible, provide screenshots or videos.
  • I triggered all changed lines of code at least once without new errors/warnings/notices.
  • I implemented built-in tests to cover the new/changed code.

Code style

  • I wrote a self-explanatory code about what it does.
  • I protected entry points against unexpected inputs.
  • I did not introduce unnecessary complexity.
  • Output messages (errors, notices, logs) are explicit enough for users to understand the issue and are actionnable.

Unticked items justification

No test for that

@Miraeld Miraeld requested review from a team and Copilot May 9, 2025 12:09
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR enhances font file detection by dynamically generating the regex for processing font file extensions based on configuration, thereby excluding otf and eot from the defaults.

  • Replaces the static FONT_FILE_REGEX with an instance-specific regex using processed_extensions from the configuration.
  • Updates the getNetworkLoadedFonts method to use the new instance-specific regex.
Comments suppressed due to low confidence (1)

src/BeaconPreloadFonts.js:8

  • [nitpick] Consider adding tests to verify the dynamic regex generation behavior with different processed_extensions configurations.
const extensions = (Array.isArray(this.config.processed_extensions) && this.config.processed_extensions.length > 0 ? this.config.processed_extensions : ["woff", "woff2", "ttf"])

@Miraeld Miraeld self-assigned this May 9, 2025
@codacy-production
Copy link

Coverage summary from Codacy

See diff coverage on Codacy

Coverage variation Diff coverage
Report missing for bc8cd031 77.78% (target: 50.00%)
Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (bc8cd03) Report Missing Report Missing Report Missing
Head commit (ad51166) 1384 1110 80.20%

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#50) 9 7 77.78%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

See your quality gate settings    Change summary preferences

Footnotes

  1. Codacy didn't receive coverage data for the commit, or there was an error processing the received data. Check your integration for errors and validate that your coverage setup is correct.

@Miraeld Miraeld linked an issue May 9, 2025 that may be closed by this pull request
@jeawhanlee
Copy link
Contributor

@Miraeld Can we include the changes here in this PR following these steps

@Miraeld
Copy link
Contributor Author

Miraeld commented May 13, 2025

@jeawhanlee Done :)

@Miraeld Miraeld merged commit 5794bbb into feature/3.19-beacons May 15, 2025
4 of 5 checks passed
@Miraeld Miraeld deleted the fix/49-default-processed-fonts-extensions branch May 15, 2025 02:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

otf and eot fonts shouldn't be processed by default with preload fonts

4 participants