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

feat: add font-loading class #2418

Merged
merged 1 commit into from
Feb 7, 2025
Merged

Conversation

adekbadek
Copy link
Member

All Submissions:

Changes proposed in this Pull Request:

Adds a newspack--font-loading class to the body element until custom fonts are loaded. This will a enable font-loading-related performance improvement.

Let's say a site is using a thick font for headings. In order to prevent layout shift on font load, the fallback font can be styled to match the thickness (e.g. by setting letter-spacing to something wide). On font load, the body class will be removed, and the custom font displayed as expected.

How to test the changes in this Pull Request:

  1. In Customizer -> Typography, set "Font Provider Import Code or URL" to e.g. //fonts.googleapis.com/css2?family=Anton&family=Inter:wght@400;500;700&display=swap, then set "Header Font" to Anton
  2. In Customizer -> Custom CSS, add e.g. .newspack--font-loading h3 { letter-spacing: -1px; }
  3. Load the page, observe initially the body element has the newspack--font-loading class, which is then removed. The h3 elements should match the Anton font on load. Enable network throttling for better observation.

Other information:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes, as applicable?
  • Have you successfully ran tests with your changes locally?

@adekbadek adekbadek added [Status] Needs Review The issue or pull request needs to be reviewed Performance labels Nov 29, 2024
@adekbadek adekbadek requested a review from a team as a code owner November 29, 2024 09:18
Copy link
Contributor

@laurelfulford laurelfulford left a comment

Choose a reason for hiding this comment

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

Apologies for missing this one entirely! This works as described, and is a really nice addition for the more dramatic font widths 🙂 Approving & merging!

@github-actions github-actions bot added [Status] Approved The pull request has been reviewed and is ready to merge and removed [Status] Needs Review The issue or pull request needs to be reviewed labels Feb 7, 2025
@laurelfulford laurelfulford merged commit 24888a3 into trunk Feb 7, 2025
6 checks passed
Copy link

github-actions bot commented Feb 7, 2025

Hey @adekbadek, good job getting this PR merged! 🎉

Now, the needs-changelog label has been added to it.

Please check if this PR needs to be included in the "Upcoming Changes" and "Release Notes" doc. If it doesn't, simply remove the label.

If it does, please add an entry to our shared document, with screenshots and testing instructions if applicable, then remove the label.

Thank you! ❤️

@laurelfulford laurelfulford deleted the feat/font-loading-class branch February 7, 2025 16:34
matticbot pushed a commit that referenced this pull request Feb 7, 2025
# [2.5.0-alpha.1](v2.4.3...v2.5.0-alpha.1) (2025-02-07)

### Bug Fixes

* make sure featured image behind images are centred ([#2430](#2430)) ([871838d](871838d))

### Features

* add corrections archive template ([#2431](#2431)) ([09897b0](09897b0))
* add font-loading class ([#2418](#2418)) ([24888a3](24888a3))
@matticbot
Copy link
Contributor

🎉 This PR is included in version 2.5.0-alpha.1 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

matticbot pushed a commit that referenced this pull request Feb 17, 2025
# [2.5.0](v2.4.3...v2.5.0) (2025-02-17)

### Bug Fixes

* make sure featured image behind images are centred ([#2430](#2430)) ([871838d](871838d))

### Features

* add corrections archive template ([#2431](#2431)) ([09897b0](09897b0))
* add font-loading class ([#2418](#2418)) ([24888a3](24888a3))
@matticbot
Copy link
Contributor

🎉 This PR is included in version 2.5.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Performance released on @alpha released [Status] Approved The pull request has been reviewed and is ready to merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants