Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closes #7069: 3.18 - Exclusions part #7167

Merged
merged 23 commits into from
Dec 13, 2024

Conversation

Miraeld
Copy link
Contributor

@Miraeld Miraeld commented Dec 4, 2024

Description

Fixes #7069
It allows the user to use a new filter rocket_exclude_locally_host_fonts to exclude some fonts from the feature.

Type of change

  • New feature (non-breaking change which adds functionality).

Detailed scenario

Just add some fonts to exclusiosn through the new filter (rocket_exclude_locally_host_fonts), and it won't be downloaded.

Technical description

Documentation

This pull request introduces a new feature to exclude specific fonts from being rewritten in the media fonts optimization process. The changes involve adding methods to handle font exclusions and updating relevant tests to ensure the new functionality works as expected.

New Feature: Font Exclusions

Tests and Fixtures Updates

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.

@Miraeld Miraeld added this to the 3.18 milestone Dec 4, 2024
@Miraeld Miraeld requested a review from a team December 4, 2024 01:33
@Miraeld Miraeld self-assigned this Dec 4, 2024
Copy link

codacy-production bot commented Dec 4, 2024

Coverage summary from Codacy

See diff coverage on Codacy

Coverage variation Diff coverage
+0.05% (target: -0.10%) 91.67% (target: 50.00%)
Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (ea1eee8) 38495 16909 43.93%
Head commit (8637808) 38500 (+5) 16929 (+20) 43.97% (+0.05%)

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 (#7167) 48 44 91.67%

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

Codacy stopped sending the deprecated coverage status on June 5th, 2024. Learn more

@Miraeld Miraeld linked an issue Dec 4, 2024 that may be closed by this pull request
inc/Engine/Media/Fonts/Frontend/Controller.php Outdated Show resolved Hide resolved
inc/Engine/Media/Fonts/Frontend/Controller.php Outdated Show resolved Hide resolved
inc/Engine/Media/Fonts/Frontend/Controller.php Outdated Show resolved Hide resolved
@remyperona remyperona added the type: sub-task Indicates the issue is a sub-task linked to an epics card label Dec 4, 2024
@jeawhanlee
Copy link
Contributor

I might be mistaken but I'm not sure this PR considers this thread here and the proposals following because as it is we might not be correctly excluding combined fonts or not?

@Miraeld
Copy link
Contributor Author

Miraeld commented Dec 5, 2024

@remyperona @jeawhanlee
Hello hello,

I've made modifications to comply with feedbacks.
Added, also, the exclusion to the Google Font combine feature so we won't combine excluded fonts.


Summary of changes by this PR:

This pull request introduces several enhancements to the font optimization process, specifically focusing on excluding certain fonts from being optimized based on user-defined patterns. These changes include updates to the core functionality, new methods for exclusion handling, and corresponding test cases.

Core Functionality Enhancements:

  • inc/Engine/Media/Fonts/Frontend/Controller.php: Added methods get_exclusions and is_excluded to retrieve exclusion patterns and check if a font URL matches any exclusion pattern. Updated rewrite_fonts method to skip excluded fonts during font replacement. [1] [2]

Integration with Dynamic Lists:

Google Fonts Optimization:

Test Cases:

  • Added new test fixtures and updated existing ones to validate the exclusion functionality. [1] [2] [3] [4] [5] [6] [7]
  • Updated integration tests to include the new exclusion filters and ensure they are applied correctly. [1] [2] [3] [4] [5] [6]

@Miraeld Miraeld force-pushed the feature/7069-exclusion-part branch from 22258dd to ef79267 Compare December 5, 2024 18:58
@Miraeld Miraeld requested a review from remyperona December 5, 2024 19:05
@hanna-meda
Copy link

@Miraeld, thank you for this PR.
I could only make the filter work using font family name, i.e. $exclusions[] = 'Roboto';
Based on this AC The exclusion should be regex compatible, we should also cover expressions such as:
$exclusions[] = 'https://fonts.googleapis.com/css?family=.*';
$exclusions[] = 'fonts.googleapis.com/.*';
$exclusions[] = 'https://fonts.googleapis.com/css?family=Noto%20Sans%3A400%2C700%7CMontserrat%3A700&display=swap';
$exclusions[] = 'https://fonts.googleapis.com/css?family=Rob.*';

Returning this back to In Progress based on this comment. cc @piotrbak

@jeawhanlee jeawhanlee self-assigned this Dec 11, 2024
@piotrbak
Copy link
Contributor

@hanna-meda after discussion on the daily, since the URL doesn't matter for the exclusions, we'll match the regex after it:

  • family(.*)Montserrat%3A700&display=swap
    -family=Rob(.*)o

cc @jeawhanlee

@Mai-Saad
Copy link
Contributor

Mai-Saad commented Dec 13, 2024

Thanks for the update.
[WIP] exploratory test notes:

  1. If the HTML have already combined file , the feature won't be applied ex this page (no font is downloaded nor rewritten) https://new.rocketlabsqa.ovh/combinedalready
  2. Exclusion is now case sensitive i.eMontserratwill work while montserrat won't (test page https://new.rocketlabsqa.ovh/combine_gf_v2new)
  3. Using exclusion like this $exclusions[] = 'family=Oswald&#038'; won't make the feature work at all (nothing is downloaded nor rewritten, only combined external) here https://new.rocketlabsqa.ovh/combine_gf_v2new
  4. Exclusion by argument is not working i.e $exclusions[]= 'testRobo'; here https://new.rocketlabsqa.ovh/combine_gf_v2new
  5. If the filter returns [""], the feature won't work at all (fonts will be there , not combined nor locally hosted) and nothing in debug.log about that

@piotrbak What do you think is a must to be fixed here? or other GH

Note: these exclusions are working fine here https://new.rocketlabsqa.ovh/combine_gf_v2new (partial match of the font URL, partial match with regex)

$exclusions[] = 'Lora'; 
$exclusions[] = 'family=Phetsarath';
$exclusions[] = 'family=R(.*)';
$exclusions[] = 'family=Phetsarath:wght@400;700&display=swap';

@piotrbak
Copy link
Contributor

piotrbak commented Dec 13, 2024

@Mai-Saad

  1. Seems to be a markup issue, lack of "
  2. That's fine

Points 3 and 4 seem to be related, is it possible that we're trying to exclude after the combination process 🤔 ?

  1. It's fine

@Mai-Saad
Copy link
Contributor

Mai-Saad commented Dec 13, 2024

For 3 family=Phetsarath:wght@400;700&display=swap is working {excluding only related font} but family=Phetsarath:wght@400;700&#038;display=swap is not working (the one not working is from the combined file in HTML , while the working one is when we open combined in browser)

@remyperona
Copy link
Contributor

Point 4 is not working because the exclusion is done against the URL only, not attributes of the link tag.

Copy link

codacy-production bot commented Dec 13, 2024

Coverage summary from Codacy

See diff coverage on Codacy

Coverage variation Diff coverage
-0.16% (target: -0.10%) 91.67% (target: 50.00%)
Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (2c51c61) 38621 17048 44.14%
Head commit (7ec0b4e) 38544 (-77) 16954 (-94) 43.99% (-0.16%)

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 (#7167) 48 44 91.67%

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

Codacy stopped sending the deprecated coverage status on June 5th, 2024. Learn more

@remyperona
Copy link
Contributor

remyperona commented Dec 13, 2024

I fixed point 2 with the latest commit.

Point 3 happens because of the difference between & and &#038;.

The combine GF and self-host use the same exclusion filter, but the format of the URL is different between them: combine gf uses & and then transform the URL to use &#038;

So if you use &#038;, the exclusion won't work for combine GF, but will work for self-host, excluding the full combined URL.

@remyperona remyperona merged commit fd63357 into feature/host-google-fonts Dec 13, 2024
12 of 13 checks passed
@remyperona remyperona deleted the feature/7069-exclusion-part branch December 13, 2024 18:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: sub-task Indicates the issue is a sub-task linked to an epics card
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3.18 - Exclusions part
7 participants