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 #7146: 3.18: Preconnect for Google fonts isnot removed when Host Google fonts locally option is enabled #7158

Conversation

Miraeld
Copy link
Contributor

@Miraeld Miraeld commented Dec 1, 2024

Description

Fixes #7146
It'll remove the preconnect tag when google font hosting is ON and loaded from a local font.

Type of change

  • Bug fix (non-breaking change which fixes an issue).

Detailed scenario

Just follow the issue scenario.

Technical description

Documentation

This pull request involves a significant update to the pattern used for removing preconnect and prefetch links in the remove_preconnect_and_prefetch function within the Controller.php file. The main change is the adjustment of the regular expression pattern to improve its accuracy and efficiency.

Changes to the regular expression pattern:

  • inc/Engine/Media/Fonts/Frontend/Controller.php: Updated the regular expression pattern in the remove_preconnect_and_prefetch function to better match and remove preconnect and prefetch links. The new pattern is more precise in identifying the rel attribute and its values, ensuring that it correctly handles various whitespace and attribute order scenarios.

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 the type: bug Indicates an unexpected problem or unintended behavior label Dec 1, 2024
@Miraeld Miraeld requested a review from a team December 1, 2024 17:58
@Miraeld Miraeld self-assigned this Dec 1, 2024
Copy link

Coverage summary from Codacy

See diff coverage on Codacy

Coverage variation Diff coverage
Report missing for dce9cce1 100.00% (target: 50.00%)
Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (dce9cce) Report Missing Report Missing Report Missing
Head commit (4a8ed62) 38424 16867 43.90%

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 (#7158) 1 1 100.00%

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

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.

@hanna-meda
Copy link

Thank you, @Miraeld, for the PR.
Confirming that preconnect and prefetch links are now removed on PR, for Google Fonts while Host Google fonts locally option is enabled.
Screenshot 2024-12-02 at 18 47 58

Copy link
Contributor

@wordpressfan wordpressfan left a comment

Choose a reason for hiding this comment

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

@Miraeld I think this is risky to remove all link with rel equals preconnect or dns-prefetch, what do u think?
instead we may get the common pattern for the local fonts if that option is enabled, what do u think?

@jeawhanlee
Copy link
Contributor

Good Catch

@Miraeld
Copy link
Contributor Author

Miraeld commented Dec 3, 2024

@wordpressfan , we could add the google font domain to make it less general. Haven't thought of that.

@hanna-meda
Copy link

@wordpressfan, thanks for pointing this out. You’re absolutely correct—it’s clear from the screenshot that all preconnect instances have been removed, whereas the first one should have been retained. Moving this back to “In Progress” as a result.
Screenshot 2024-12-03 at 14 03 50

@Miraeld Miraeld requested a review from wordpressfan December 3, 2024 16:07
@Miraeld
Copy link
Contributor Author

Miraeld commented Dec 3, 2024

@wordpressfan & @hanna-meda regex has been changed to be far less general. :)

Copy link

codacy-production bot commented Dec 3, 2024

Coverage summary from Codacy

See diff coverage on Codacy

Coverage variation Diff coverage
Report missing for dce9cce1 (target: 50.00%)
Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (dce9cce) Report Missing Report Missing Report Missing
Head commit (a0dce79) 38425 16868 43.90%

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 (#7158) 0 0 ∅ (not applicable)

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

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.

Copy link

@hanna-meda hanna-meda left a comment

Choose a reason for hiding this comment

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

Thank you once again, @Miraeld, for this PR.
Everything looks good now: the prefetch and preconnect lines related to fonts.gstatic and googleapi are removed while unrelated link rel="preconnect" and link rel="dns-prefetch" entries remain intact.

@hanna-meda hanna-meda merged commit 0df2804 into feature/host-google-fonts Dec 4, 2024
12 checks passed
@hanna-meda hanna-meda deleted the fix/7146-remove-preconnect-when-using-local-font branch December 4, 2024 07:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Indicates an unexpected problem or unintended behavior
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3.18: Preconnect for Google fonts isnot removed when Host Google fonts locally option is enabled
5 participants